alias.c (127757) | alias.c (131566) |
---|---|
1/*- 2 * Copyright (c) 2001 Charles Mott <cm@linktel.net> 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 11 unchanged lines hidden (view full) --- 20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 * SUCH DAMAGE. 25 */ 26 27#include <sys/cdefs.h> | 1/*- 2 * Copyright (c) 2001 Charles Mott <cm@linktel.net> 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 11 unchanged lines hidden (view full) --- 20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 * SUCH DAMAGE. 25 */ 26 27#include <sys/cdefs.h> |
28__FBSDID("$FreeBSD: head/sys/netinet/libalias/alias.c 127757 2004-04-02 17:57:57Z deischen $"); | 28__FBSDID("$FreeBSD: head/sys/netinet/libalias/alias.c 131566 2004-07-04 12:53:07Z phk $"); |
29 30/* 31 Alias.c provides supervisory control for the functions of the 32 packet aliasing software. It consists of routines to monitor 33 TCP connection state, protocol-specific aliasing routines, 34 fragment handling and the following outside world functional 35 interfaces: SaveFragmentPtr, GetFragmentPtr, FragmentAliasIn, 36 PacketAliasIn and PacketAliasOut. --- 212 unchanged lines hidden (view full) --- 249 250/* Local prototypes */ 251static int IcmpAliasIn1(struct libalias *, struct ip *); 252static int IcmpAliasIn2(struct libalias *, struct ip *); 253static int IcmpAliasIn(struct libalias *, struct ip *); 254 255static int IcmpAliasOut1(struct libalias *, struct ip *); 256static int IcmpAliasOut2(struct libalias *, struct ip *); | 29 30/* 31 Alias.c provides supervisory control for the functions of the 32 packet aliasing software. It consists of routines to monitor 33 TCP connection state, protocol-specific aliasing routines, 34 fragment handling and the following outside world functional 35 interfaces: SaveFragmentPtr, GetFragmentPtr, FragmentAliasIn, 36 PacketAliasIn and PacketAliasOut. --- 212 unchanged lines hidden (view full) --- 249 250/* Local prototypes */ 251static int IcmpAliasIn1(struct libalias *, struct ip *); 252static int IcmpAliasIn2(struct libalias *, struct ip *); 253static int IcmpAliasIn(struct libalias *, struct ip *); 254 255static int IcmpAliasOut1(struct libalias *, struct ip *); 256static int IcmpAliasOut2(struct libalias *, struct ip *); |
257static int IcmpAliasOut(struct libalias *, struct ip *); | 257static int IcmpAliasOut(struct libalias *, struct ip *, int create); |
258 259static int ProtoAliasIn(struct libalias *, struct ip *); | 258 259static int ProtoAliasIn(struct libalias *, struct ip *); |
260static int ProtoAliasOut(struct libalias *, struct ip *); | 260static int ProtoAliasOut(struct libalias *, struct ip *, int create); |
261 | 261 |
262static int UdpAliasOut(struct libalias *, struct ip *); | |
263static int UdpAliasIn(struct libalias *, struct ip *); | 262static int UdpAliasIn(struct libalias *, struct ip *); |
263static int UdpAliasOut(struct libalias *, struct ip *, int create); |
|
264 | 264 |
265static int TcpAliasOut(struct libalias *, struct ip *, int); | |
266static int TcpAliasIn(struct libalias *, struct ip *); | 265static int TcpAliasIn(struct libalias *, struct ip *); |
266static int TcpAliasOut(struct libalias *, struct ip *, int, int create); |
|
267 268 269static int 270IcmpAliasIn1(struct libalias *la, struct ip *pip) 271{ 272/* 273 De-alias incoming echo and timestamp replies. 274 Alias incoming echo and timestamp requests. --- 309 unchanged lines hidden (view full) --- 584 } 585 return (PKT_ALIAS_OK); 586 } 587 return (PKT_ALIAS_IGNORED); 588} 589 590 591static int | 267 268 269static int 270IcmpAliasIn1(struct libalias *la, struct ip *pip) 271{ 272/* 273 De-alias incoming echo and timestamp replies. 274 Alias incoming echo and timestamp requests. --- 309 unchanged lines hidden (view full) --- 584 } 585 return (PKT_ALIAS_OK); 586 } 587 return (PKT_ALIAS_IGNORED); 588} 589 590 591static int |
592IcmpAliasOut(struct libalias *la, struct ip *pip) | 592IcmpAliasOut(struct libalias *la, struct ip *pip, int create) |
593{ 594 int iresult; 595 struct icmp *ic; 596 597/* Return if proxy-only mode is enabled */ 598 if (la->packetAliasMode & PKT_ALIAS_PROXY_ONLY) 599 return PKT_ALIAS_OK; 600 --- 50 unchanged lines hidden (view full) --- 651 652 return (PKT_ALIAS_OK); 653 } 654 return (PKT_ALIAS_IGNORED); 655} 656 657 658static int | 593{ 594 int iresult; 595 struct icmp *ic; 596 597/* Return if proxy-only mode is enabled */ 598 if (la->packetAliasMode & PKT_ALIAS_PROXY_ONLY) 599 return PKT_ALIAS_OK; 600 --- 50 unchanged lines hidden (view full) --- 651 652 return (PKT_ALIAS_OK); 653 } 654 return (PKT_ALIAS_IGNORED); 655} 656 657 658static int |
659ProtoAliasOut(struct libalias *la, struct ip *pip) | 659ProtoAliasOut(struct libalias *la, struct ip *pip, int create) |
660{ 661/* 662 Handle outgoing IP packets. The 663 only thing which is done in this case is to alias 664 the source IP address of the packet. 665*/ 666 struct alias_link *link; 667 --- 78 unchanged lines hidden (view full) --- 746 return (PKT_ALIAS_IGNORED); 747 else 748 return (PKT_ALIAS_OK); 749 } 750 return (PKT_ALIAS_IGNORED); 751} 752 753static int | 660{ 661/* 662 Handle outgoing IP packets. The 663 only thing which is done in this case is to alias 664 the source IP address of the packet. 665*/ 666 struct alias_link *link; 667 --- 78 unchanged lines hidden (view full) --- 746 return (PKT_ALIAS_IGNORED); 747 else 748 return (PKT_ALIAS_OK); 749 } 750 return (PKT_ALIAS_IGNORED); 751} 752 753static int |
754UdpAliasOut(struct libalias *la, struct ip *pip) | 754UdpAliasOut(struct libalias *la, struct ip *pip, int create) |
755{ 756 struct udphdr *ud; 757 struct alias_link *link; 758 759/* Return if proxy-only mode is enabled */ 760 if (la->packetAliasMode & PKT_ALIAS_PROXY_ONLY) 761 return PKT_ALIAS_OK; 762 763 ud = (struct udphdr *)((char *)pip + (pip->ip_hl << 2)); 764 765 link = FindUdpTcpOut(la, pip->ip_src, pip->ip_dst, 766 ud->uh_sport, ud->uh_dport, | 755{ 756 struct udphdr *ud; 757 struct alias_link *link; 758 759/* Return if proxy-only mode is enabled */ 760 if (la->packetAliasMode & PKT_ALIAS_PROXY_ONLY) 761 return PKT_ALIAS_OK; 762 763 ud = (struct udphdr *)((char *)pip + (pip->ip_hl << 2)); 764 765 link = FindUdpTcpOut(la, pip->ip_src, pip->ip_dst, 766 ud->uh_sport, ud->uh_dport, |
767 IPPROTO_UDP, 1); | 767 IPPROTO_UDP, create); |
768 if (link != NULL) { 769 u_short alias_port; 770 struct in_addr alias_address; 771 772 alias_address = GetAliasAddress(link); 773 alias_port = GetAliasPort(link); 774 775/* Special processing for IP encoding protocols */ --- 124 unchanged lines hidden (view full) --- 900 TcpMonitorIn(pip, link); 901 902 return (PKT_ALIAS_OK); 903 } 904 return (PKT_ALIAS_IGNORED); 905} 906 907static int | 768 if (link != NULL) { 769 u_short alias_port; 770 struct in_addr alias_address; 771 772 alias_address = GetAliasAddress(link); 773 alias_port = GetAliasPort(link); 774 775/* Special processing for IP encoding protocols */ --- 124 unchanged lines hidden (view full) --- 900 TcpMonitorIn(pip, link); 901 902 return (PKT_ALIAS_OK); 903 } 904 return (PKT_ALIAS_IGNORED); 905} 906 907static int |
908TcpAliasOut(struct libalias *la, struct ip *pip, int maxpacketsize) | 908TcpAliasOut(struct libalias *la, struct ip *pip, int maxpacketsize, int create) |
909{ 910 int proxy_type; 911 u_short dest_port; 912 u_short proxy_server_port; 913 struct in_addr dest_address; 914 struct in_addr proxy_server_address; 915 struct tcphdr *tc; 916 struct alias_link *link; --- 21 unchanged lines hidden (view full) --- 938 939 accumulate = twowords(&pip->ip_dst); 940 pip->ip_dst = proxy_server_address; 941 accumulate -= twowords(&pip->ip_dst); 942 ADJUST_CHECKSUM(accumulate, pip->ip_sum); 943 } 944 link = FindUdpTcpOut(la, pip->ip_src, pip->ip_dst, 945 tc->th_sport, tc->th_dport, | 909{ 910 int proxy_type; 911 u_short dest_port; 912 u_short proxy_server_port; 913 struct in_addr dest_address; 914 struct in_addr proxy_server_address; 915 struct tcphdr *tc; 916 struct alias_link *link; --- 21 unchanged lines hidden (view full) --- 938 939 accumulate = twowords(&pip->ip_dst); 940 pip->ip_dst = proxy_server_address; 941 accumulate -= twowords(&pip->ip_dst); 942 ADJUST_CHECKSUM(accumulate, pip->ip_sum); 943 } 944 link = FindUdpTcpOut(la, pip->ip_src, pip->ip_dst, 945 tc->th_sport, tc->th_dport, |
946 IPPROTO_TCP, 1); | 946 IPPROTO_TCP, create); 947 if (link == NULL) 948 return (PKT_ALIAS_IGNORED); |
947 if (link != NULL) { 948 u_short alias_port; 949 struct in_addr alias_address; 950 int accumulate; 951 952/* Save original destination address, if this is a proxy packet. 953 Also modify packet to include destination encoding. This may 954 change the size of IP header. */ --- 274 unchanged lines hidden (view full) --- 1229#define UNREG_ADDR_C_UPPER 0xc0a8ffff 1230 1231int 1232LibAliasOut(struct libalias *la, char *ptr, /* valid IP packet */ 1233 int maxpacketsize /* How much the packet data may grow (FTP 1234 * and IRC inline changes) */ 1235) 1236{ | 949 if (link != NULL) { 950 u_short alias_port; 951 struct in_addr alias_address; 952 int accumulate; 953 954/* Save original destination address, if this is a proxy packet. 955 Also modify packet to include destination encoding. This may 956 change the size of IP header. */ --- 274 unchanged lines hidden (view full) --- 1231#define UNREG_ADDR_C_UPPER 0xc0a8ffff 1232 1233int 1234LibAliasOut(struct libalias *la, char *ptr, /* valid IP packet */ 1235 int maxpacketsize /* How much the packet data may grow (FTP 1236 * and IRC inline changes) */ 1237) 1238{ |
1239 return (LibAliasOutTry(la, ptr, maxpacketsize, 1)); 1240} 1241 1242int 1243LibAliasOutTry(struct libalias *la, char *ptr, /* valid IP packet */ 1244 int maxpacketsize, /* How much the packet data may grow (FTP 1245 * and IRC inline changes) */ 1246 int create /* Create new entries ? */ 1247) 1248{ |
|
1237 int iresult; 1238 struct in_addr addr_save; 1239 struct ip *pip; 1240 1241 if (la->packetAliasMode & PKT_ALIAS_REVERSE) { 1242 la->packetAliasMode &= ~PKT_ALIAS_REVERSE; 1243 iresult = PacketAliasIn(ptr, maxpacketsize); 1244 la->packetAliasMode |= PKT_ALIAS_REVERSE; --- 27 unchanged lines hidden (view full) --- 1272 } 1273 } else if (la->packetAliasMode & PKT_ALIAS_PROXY_ONLY) { 1274 SetDefaultAliasAddress(la, pip->ip_src); 1275 } 1276 iresult = PKT_ALIAS_IGNORED; 1277 if ((ntohs(pip->ip_off) & IP_OFFMASK) == 0) { 1278 switch (pip->ip_p) { 1279 case IPPROTO_ICMP: | 1249 int iresult; 1250 struct in_addr addr_save; 1251 struct ip *pip; 1252 1253 if (la->packetAliasMode & PKT_ALIAS_REVERSE) { 1254 la->packetAliasMode &= ~PKT_ALIAS_REVERSE; 1255 iresult = PacketAliasIn(ptr, maxpacketsize); 1256 la->packetAliasMode |= PKT_ALIAS_REVERSE; --- 27 unchanged lines hidden (view full) --- 1284 } 1285 } else if (la->packetAliasMode & PKT_ALIAS_PROXY_ONLY) { 1286 SetDefaultAliasAddress(la, pip->ip_src); 1287 } 1288 iresult = PKT_ALIAS_IGNORED; 1289 if ((ntohs(pip->ip_off) & IP_OFFMASK) == 0) { 1290 switch (pip->ip_p) { 1291 case IPPROTO_ICMP: |
1280 iresult = IcmpAliasOut(la, pip); | 1292 iresult = IcmpAliasOut(la, pip, create); |
1281 break; 1282 case IPPROTO_UDP: | 1293 break; 1294 case IPPROTO_UDP: |
1283 iresult = UdpAliasOut(la, pip); | 1295 iresult = UdpAliasOut(la, pip, create); |
1284 break; | 1296 break; |
1285 case IPPROTO_TCP: 1286 iresult = TcpAliasOut(la, pip, maxpacketsize); | 1297 case IPPROTO_TCP: 1298 iresult = TcpAliasOut(la, pip, maxpacketsize, create); |
1287 break; 1288 case IPPROTO_GRE: 1289 if (AliasHandlePptpGreOut(la, pip) == 0) 1290 iresult = PKT_ALIAS_OK; 1291 else | 1299 break; 1300 case IPPROTO_GRE: 1301 if (AliasHandlePptpGreOut(la, pip) == 0) 1302 iresult = PKT_ALIAS_OK; 1303 else |
1292 iresult = ProtoAliasOut(la, pip); | 1304 iresult = ProtoAliasOut(la, pip, create); |
1293 break; 1294 default: | 1305 break; 1306 default: |
1295 iresult = ProtoAliasOut(la, pip); | 1307 iresult = ProtoAliasOut(la, pip, create); |
1296 break; 1297 } 1298 } else { 1299 iresult = FragmentOut(la, pip); 1300 } 1301 1302 SetDefaultAliasAddress(la, addr_save); 1303 return (iresult); --- 106 unchanged lines hidden --- | 1308 break; 1309 } 1310 } else { 1311 iresult = FragmentOut(la, pip); 1312 } 1313 1314 SetDefaultAliasAddress(la, addr_save); 1315 return (iresult); --- 106 unchanged lines hidden --- |