static int protohandler(struct libalias *la, struct ip *pip, struct alias_data *ah) { if (ntohs(*ah->dport) == TFTP_PORT_NUMBER) FindRtspOut(la, pip->ip_src, pip->ip_dst, *ah->sport, *ah->aport, IPPROTO_UDP); else AliasHandleRtspOut(la, pip, ah->lnk, ah->maxpktsize); return (0); }
static int TcpAliasOut(struct ip *pip, int maxpacketsize) { int proxy_type; u_short dest_port; u_short proxy_server_port; struct in_addr dest_address; struct in_addr proxy_server_address; struct tcphdr *tc; struct alias_link *link; tc = (struct tcphdr *) ((char *) pip + (pip->ip_hl << 2)); proxy_type = ProxyCheck(pip, &proxy_server_address, &proxy_server_port); if (proxy_type == 0 && (packetAliasMode & PKT_ALIAS_PROXY_ONLY)) return PKT_ALIAS_OK; /* If this is a transparent proxy, save original destination, then alter the destination and adjust checksums */ dest_port = tc->th_dport; dest_address = pip->ip_dst; if (proxy_type != 0) { int accumulate; u_short *sptr; accumulate = tc->th_dport; tc->th_dport = proxy_server_port; accumulate -= tc->th_dport; sptr = (u_short *) &(pip->ip_dst); accumulate += *sptr++; accumulate += *sptr; sptr = (u_short *) &proxy_server_address; accumulate -= *sptr++; accumulate -= *sptr; ADJUST_CHECKSUM(accumulate, tc->th_sum); sptr = (u_short *) &(pip->ip_dst); accumulate = *sptr++; accumulate += *sptr; pip->ip_dst = proxy_server_address; sptr = (u_short *) &(pip->ip_dst); accumulate -= *sptr++; accumulate -= *sptr; ADJUST_CHECKSUM(accumulate, pip->ip_sum); } link = FindUdpTcpOut(pip->ip_src, pip->ip_dst, tc->th_sport, tc->th_dport, IPPROTO_TCP, 1); if (link !=NULL) { u_short alias_port; struct in_addr alias_address; int accumulate; u_short *sptr; /* Save original destination address, if this is a proxy packet. Also modify packet to include destination encoding. This may change the size of IP header. */ if (proxy_type != 0) { SetProxyPort(link, dest_port); SetProxyAddress(link, dest_address); ProxyModify(link, pip, maxpacketsize, proxy_type); tc = (struct tcphdr *) ((char *) pip + (pip->ip_hl << 2)); } /* Get alias address and port */ alias_port = GetAliasPort(link); alias_address = GetAliasAddress(link); /* Monitor TCP connection state */ TcpMonitorOut(pip, link); /* Special processing for IP encoding protocols */ if (ntohs(tc->th_dport) == FTP_CONTROL_PORT_NUMBER || ntohs(tc->th_sport) == FTP_CONTROL_PORT_NUMBER) AliasHandleFtpOut(pip, link, maxpacketsize); else if (ntohs(tc->th_dport) == IRC_CONTROL_PORT_NUMBER_1 || ntohs(tc->th_dport) == IRC_CONTROL_PORT_NUMBER_2) AliasHandleIrcOut(pip, link, maxpacketsize); else if (ntohs(tc->th_dport) == RTSP_CONTROL_PORT_NUMBER_1 || ntohs(tc->th_sport) == RTSP_CONTROL_PORT_NUMBER_1 || ntohs(tc->th_dport) == RTSP_CONTROL_PORT_NUMBER_2 || ntohs(tc->th_sport) == RTSP_CONTROL_PORT_NUMBER_2) AliasHandleRtspOut(pip, link, maxpacketsize); else if (ntohs(tc->th_dport) == PPTP_CONTROL_PORT_NUMBER || ntohs(tc->th_sport) == PPTP_CONTROL_PORT_NUMBER) AliasHandlePptpOut(pip, link); /* Adjust TCP checksum since source port is being aliased */ /* and source address is being altered */ accumulate = tc->th_sport; tc->th_sport = alias_port; accumulate -= tc->th_sport; sptr = (u_short *) &(pip->ip_src); accumulate += *sptr++; accumulate += *sptr; sptr = (u_short *) &alias_address; accumulate -= *sptr++; accumulate -= *sptr; /* Modify sequence number if necessary */ if (GetAckModified(link) == 1) { int delta; delta = GetDeltaSeqOut(pip, link); if (delta != 0) { sptr = (u_short *) &tc->th_seq; accumulate += *sptr++; accumulate += *sptr; tc->th_seq = htonl(ntohl(tc->th_seq) + delta); sptr = (u_short *) &tc->th_seq; accumulate -= *sptr++; accumulate -= *sptr; } } ADJUST_CHECKSUM(accumulate, tc->th_sum); /* Change source address */ sptr = (u_short *) &(pip->ip_src); accumulate = *sptr++; accumulate += *sptr; pip->ip_src = alias_address; sptr = (u_short *) &(pip->ip_src); accumulate -= *sptr++; accumulate -= *sptr; ADJUST_CHECKSUM(accumulate, pip->ip_sum); return(PKT_ALIAS_OK); } return(PKT_ALIAS_IGNORED); }