Deleted Added
full compact
1,2d0
< /* -*- mode: c; tab-width: 8; c-basic-indent: 4; -*- */
<
30c28
< __FBSDID("$FreeBSD: head/sys/netinet/libalias/alias_db.c 124621 2004-01-17 10:52:21Z phk $");
---
> __FBSDID("$FreeBSD: head/sys/netinet/libalias/alias_db.c 127094 2004-03-16 21:30:41Z des $");
170c168
< static LIST_HEAD(, libalias) instancehead = LIST_HEAD_INITIALIZER(instancehead);
---
> static LIST_HEAD(, libalias) instancehead = LIST_HEAD_INITIALIZER(instancehead);
193c191
< # define TCP_EXPIRE_DEAD 10
---
> #define TCP_EXPIRE_DEAD 10
199c197
< # define TCP_EXPIRE_SINGLEDEAD 90
---
> #define TCP_EXPIRE_SINGLEDEAD 90
204c202
< # define TCP_EXPIRE_INITIAL 300
---
> #define TCP_EXPIRE_INITIAL 300
209c207
< # define TCP_EXPIRE_CONNECTED 86400
---
> #define TCP_EXPIRE_CONNECTED 86400
249,254c247,252
< struct ack_data_record /* used to save changes to ACK/sequence numbers */
< {
< u_long ack_old;
< u_long ack_new;
< int delta;
< int active;
---
> struct ack_data_record { /* used to save changes to ACK/sequence
> * numbers */
> u_long ack_old;
> u_long ack_new;
> int delta;
> int active;
257,263c255,261
< struct tcp_state /* Information about TCP connection */
< {
< int in; /* State for outside -> inside */
< int out; /* State for inside -> outside */
< int index; /* Index to ACK data array */
< int ack_modified; /* Indicates whether ACK and sequence numbers */
< /* been modified */
---
> struct tcp_state { /* Information about TCP connection */
> int in; /* State for outside -> inside */
> int out; /* State for inside -> outside */
> int index; /* Index to ACK data array */
> int ack_modified; /* Indicates whether ACK and
> * sequence numbers */
> /* been modified */
266,272c264,270
< #define N_LINK_TCP_DATA 3 /* Number of distinct ACK number changes
< saved for a modified TCP stream */
< struct tcp_dat
< {
< struct tcp_state state;
< struct ack_data_record ack[N_LINK_TCP_DATA];
< int fwhole; /* Which firewall record is used for this hole? */
---
> #define N_LINK_TCP_DATA 3 /* Number of distinct ACK number changes
> * saved for a modified TCP stream */
> struct tcp_dat {
> struct tcp_state state;
> struct ack_data_record ack[N_LINK_TCP_DATA];
> int fwhole; /* Which firewall record is used for this
> * hole? */
275,279c273,276
< struct server /* LSNAT server pool (circular list) */
< {
< struct in_addr addr;
< u_short port;
< struct server *next;
---
> struct server { /* LSNAT server pool (circular list) */
> struct in_addr addr;
> u_short port;
> struct server *next;
282,293c279,289
< struct alias_link /* Main data structure */
< {
< struct libalias *la;
< struct in_addr src_addr; /* Address and port information */
< struct in_addr dst_addr;
< struct in_addr alias_addr;
< struct in_addr proxy_addr;
< u_short src_port;
< u_short dst_port;
< u_short alias_port;
< u_short proxy_port;
< struct server *server;
---
> struct alias_link { /* Main data structure */
> struct libalias *la;
> struct in_addr src_addr; /* Address and port information */
> struct in_addr dst_addr;
> struct in_addr alias_addr;
> struct in_addr proxy_addr;
> u_short src_port;
> u_short dst_port;
> u_short alias_port;
> u_short proxy_port;
> struct server *server;
295c291,292
< int link_type; /* Type of link: TCP, UDP, ICMP, proto, frag */
---
> int link_type; /* Type of link: TCP, UDP, ICMP,
> * proto, frag */
306,307c303,304
< int flags; /* indicates special characteristics */
< int pflags; /* protocol-specific flags */
---
> int flags; /* indicates special characteristics */
> int pflags; /* protocol-specific flags */
313c310
< #define LINK_PARTIALLY_SPECIFIED 0x03 /* logical-or of first two bits */
---
> #define LINK_PARTIALLY_SPECIFIED 0x03 /* logical-or of first two bits */
316,317c313,314
< int timestamp; /* Time link was last accessed */
< int expire_time; /* Expire time for link */
---
> int timestamp; /* Time link was last accessed */
> int expire_time; /* Expire time for link */
319c316
< int sockfd; /* socket descriptor */
---
> int sockfd; /* socket descriptor */
321,322c318,321
< LIST_ENTRY(alias_link) list_out; /* Linked list of pointers for */
< LIST_ENTRY(alias_link) list_in; /* input and output lookup tables */
---
> LIST_ENTRY (alias_link) list_out; /* Linked list of
> * pointers for */
> LIST_ENTRY (alias_link) list_in; /* input and output
> * lookup tables */
324,329c323,327
< union /* Auxiliary data */
< {
< char *frag_ptr;
< struct in_addr frag_addr;
< struct tcp_dat *tcp;
< } data;
---
> union { /* Auxiliary data */
> char *frag_ptr;
> struct in_addr frag_addr;
> struct tcp_dat *tcp;
> } data;
347c345
< static u_int StartPointIn(struct in_addr, u_short, int);
---
> static u_int StartPointIn(struct in_addr, u_short, int);
349,350c347,349
< static u_int StartPointOut(struct in_addr, struct in_addr,
< u_short, u_short, int);
---
> static u_int
> StartPointOut(struct in_addr, struct in_addr,
> u_short, u_short, int);
352c351
< static int SeqDiff(u_long, u_long);
---
> static int SeqDiff(u_long, u_long);
354c353
< static void ShowAliasStats(struct libalias *);
---
> static void ShowAliasStats(struct libalias *);
358,360c357,360
< static void InitPunchFW(struct libalias *la);
< static void UninitPunchFW(struct libalias *la);
< static void ClearFWHole(struct alias_link *link);
---
> static void InitPunchFW(struct libalias *la);
> static void UninitPunchFW(struct libalias *la);
> static void ClearFWHole(struct alias_link *link);
>
364,365c364,365
< static void InitPacketAliasLog(struct libalias *la);
< static void UninitPacketAliasLog(struct libalias *la);
---
> static void InitPacketAliasLog(struct libalias *la);
> static void UninitPacketAliasLog(struct libalias *la);
367c367
< static u_int
---
> static u_int
369,370c369,370
< u_short alias_port,
< int link_type)
---
> u_short alias_port,
> int link_type)
372c372
< u_int n;
---
> u_int n;
374,378c374,378
< n = alias_addr.s_addr;
< if (link_type != LINK_PPTP)
< n += alias_port;
< n += link_type;
< return(n % LINK_TABLE_IN_SIZE);
---
> n = alias_addr.s_addr;
> if (link_type != LINK_PPTP)
> n += alias_port;
> n += link_type;
> return (n % LINK_TABLE_IN_SIZE);
382c382
< static u_int
---
> static u_int
384c384
< u_short src_port, u_short dst_port, int link_type)
---
> u_short src_port, u_short dst_port, int link_type)
386c386
< u_int n;
---
> u_int n;
388,394c388,394
< n = src_addr.s_addr;
< n += dst_addr.s_addr;
< if (link_type != LINK_PPTP) {
< n += src_port;
< n += dst_port;
< }
< n += link_type;
---
> n = src_addr.s_addr;
> n += dst_addr.s_addr;
> if (link_type != LINK_PPTP) {
> n += src_port;
> n += dst_port;
> }
> n += link_type;
396c396
< return(n % LINK_TABLE_OUT_SIZE);
---
> return (n % LINK_TABLE_OUT_SIZE);
410c410
< return (ntohl(y) - ntohl(x));
---
> return (ntohl(y) - ntohl(x));
419,429c419,428
< if (la->monitorFile)
< {
< fprintf(la->monitorFile,
< "icmp=%d, udp=%d, tcp=%d, pptp=%d, proto=%d, frag_id=%d frag_ptr=%d",
< la->icmpLinkCount,
< la->udpLinkCount,
< la->tcpLinkCount,
< la->pptpLinkCount,
< la->protoLinkCount,
< la->fragmentIdLinkCount,
< la->fragmentPtrLinkCount);
---
> if (la->monitorFile) {
> fprintf(la->monitorFile,
> "icmp=%d, udp=%d, tcp=%d, pptp=%d, proto=%d, frag_id=%d frag_ptr=%d",
> la->icmpLinkCount,
> la->udpLinkCount,
> la->tcpLinkCount,
> la->pptpLinkCount,
> la->protoLinkCount,
> la->fragmentIdLinkCount,
> la->fragmentPtrLinkCount);
431,438c430,437
< fprintf(la->monitorFile, " / tot=%d (sock=%d)\n",
< la->icmpLinkCount + la->udpLinkCount
< + la->tcpLinkCount
< + la->pptpLinkCount
< + la->protoLinkCount
< + la->fragmentIdLinkCount
< + la->fragmentPtrLinkCount,
< la->sockCount);
---
> fprintf(la->monitorFile, " / tot=%d (sock=%d)\n",
> la->icmpLinkCount + la->udpLinkCount
> + la->tcpLinkCount
> + la->pptpLinkCount
> + la->protoLinkCount
> + la->fragmentIdLinkCount
> + la->fragmentPtrLinkCount,
> la->sockCount);
440,441c439,440
< fflush(la->monitorFile);
< }
---
> fflush(la->monitorFile);
> }
470c469
< static int GetNewPort(struct libalias *, struct alias_link *, int);
---
> static int GetNewPort(struct libalias *, struct alias_link *, int);
472c471
< static u_short GetSocket(struct libalias *, u_short, int *, int);
---
> static u_short GetSocket(struct libalias *, u_short, int *, int);
474c473
< static void CleanupAliasData(struct libalias *);
---
> static void CleanupAliasData(struct libalias *);
476c475
< static void IncrementalCleanup(struct libalias *);
---
> static void IncrementalCleanup(struct libalias *);
478c477
< static void DeleteLink(struct alias_link *);
---
> static void DeleteLink(struct alias_link *);
482c481
< u_short, u_short, int, int);
---
> u_short, u_short, int, int);
486,487c485,486
< struct in_addr, struct in_addr, struct in_addr,
< u_short, u_short, int, int);
---
> struct in_addr, struct in_addr, struct in_addr,
> u_short, u_short, int, int);
490c489
< FindLinkOut(struct libalias *, struct in_addr, struct in_addr, u_short, u_short, int, int);
---
> FindLinkOut (struct libalias *, struct in_addr, struct in_addr, u_short, u_short, int, int);
493c492
< FindLinkIn(struct libalias *, struct in_addr, struct in_addr, u_short, u_short, int, int);
---
> FindLinkIn (struct libalias *, struct in_addr, struct in_addr, u_short, u_short, int, int);
514,517c513,516
< int i;
< int max_trials;
< u_short port_sys;
< u_short port_net;
---
> int i;
> int max_trials;
> u_short port_sys;
> u_short port_net;
529,535c528,533
< if (alias_port_param == GET_ALIAS_PORT)
< {
< /*
< * The aliasing port is automatically selected
< * by one of two methods below:
< */
< max_trials = GET_NEW_PORT_MAX_ATTEMPTS;
---
> if (alias_port_param == GET_ALIAS_PORT) {
> /*
> * The aliasing port is automatically selected by one of
> * two methods below:
> */
> max_trials = GET_NEW_PORT_MAX_ATTEMPTS;
537,563c535,553
< if (la->packetAliasMode & PKT_ALIAS_SAME_PORTS)
< {
< /*
< * When the PKT_ALIAS_SAME_PORTS option is
< * chosen, the first try will be the
< * actual source port. If this is already
< * in use, the remainder of the trials
< * will be random.
< */
< port_net = link->src_port;
< port_sys = ntohs(port_net);
< }
< else
< {
< /* First trial and all subsequent are random. */
< port_sys = random() & ALIAS_PORT_MASK;
< port_sys += ALIAS_PORT_BASE;
< port_net = htons(port_sys);
< }
< }
< else if (alias_port_param >= 0 && alias_port_param < 0x10000)
< {
< link->alias_port = (u_short) alias_port_param;
< return(0);
< }
< else
< {
---
> if (la->packetAliasMode & PKT_ALIAS_SAME_PORTS) {
> /*
> * When the PKT_ALIAS_SAME_PORTS option is chosen,
> * the first try will be the actual source port. If
> * this is already in use, the remainder of the
> * trials will be random.
> */
> port_net = link->src_port;
> port_sys = ntohs(port_net);
> } else {
> /* First trial and all subsequent are random. */
> port_sys = random() & ALIAS_PORT_MASK;
> port_sys += ALIAS_PORT_BASE;
> port_net = htons(port_sys);
> }
> } else if (alias_port_param >= 0 && alias_port_param < 0x10000) {
> link->alias_port = (u_short) alias_port_param;
> return (0);
> } else {
565,566c555,556
< fprintf(stderr, "PacketAlias/GetNewPort(): ");
< fprintf(stderr, "input parameter error\n");
---
> fprintf(stderr, "PacketAlias/GetNewPort(): ");
> fprintf(stderr, "input parameter error\n");
568,569c558,559
< return(-1);
< }
---
> return (-1);
> }
573,576c563,565
< for (i=0; i<max_trials; i++)
< {
< int go_ahead;
< struct alias_link *search_result;
---
> for (i = 0; i < max_trials; i++) {
> int go_ahead;
> struct alias_link *search_result;
578,580c567,569
< search_result = FindLinkIn(la, link->dst_addr, link->alias_addr,
< link->dst_port, port_net,
< link->link_type, 0);
---
> search_result = FindLinkIn(la, link->dst_addr, link->alias_addr,
> link->dst_port, port_net,
> link->link_type, 0);
582,588c571,577
< if (search_result == NULL)
< go_ahead = 1;
< else if (!(link->flags & LINK_PARTIALLY_SPECIFIED)
< && (search_result->flags & LINK_PARTIALLY_SPECIFIED))
< go_ahead = 1;
< else
< go_ahead = 0;
---
> if (search_result == NULL)
> go_ahead = 1;
> else if (!(link->flags & LINK_PARTIALLY_SPECIFIED)
> && (search_result->flags & LINK_PARTIALLY_SPECIFIED))
> go_ahead = 1;
> else
> go_ahead = 0;
590,608c579,596
< if (go_ahead)
< {
< if ((la->packetAliasMode & PKT_ALIAS_USE_SOCKETS)
< && (link->flags & LINK_PARTIALLY_SPECIFIED)
< && ((link->link_type == LINK_TCP) ||
< (link->link_type == LINK_UDP)))
< {
< if (GetSocket(la, port_net, &link->sockfd, link->link_type))
< {
< link->alias_port = port_net;
< return(0);
< }
< }
< else
< {
< link->alias_port = port_net;
< return(0);
< }
< }
---
> if (go_ahead) {
> if ((la->packetAliasMode & PKT_ALIAS_USE_SOCKETS)
> && (link->flags & LINK_PARTIALLY_SPECIFIED)
> && ((link->link_type == LINK_TCP) ||
> (link->link_type == LINK_UDP))) {
> if (GetSocket(la, port_net, &link->sockfd, link->link_type)) {
> link->alias_port = port_net;
> return (0);
> }
> } else {
> link->alias_port = port_net;
> return (0);
> }
> }
> port_sys = random() & ALIAS_PORT_MASK;
> port_sys += ALIAS_PORT_BASE;
> port_net = htons(port_sys);
> }
610,614d597
< port_sys = random() & ALIAS_PORT_MASK;
< port_sys += ALIAS_PORT_BASE;
< port_net = htons(port_sys);
< }
<
616,617c599,600
< fprintf(stderr, "PacketAlias/GetnewPort(): ");
< fprintf(stderr, "could not find free port\n");
---
> fprintf(stderr, "PacketAlias/GetnewPort(): ");
> fprintf(stderr, "could not find free port\n");
620c603
< return(-1);
---
> return (-1);
624c607
< static u_short
---
> static u_short
627,629c610,612
< int err;
< int sock;
< struct sockaddr_in sock_addr;
---
> int err;
> int sock;
> struct sockaddr_in sock_addr;
631,636c614,618
< if (link_type == LINK_TCP)
< sock = socket(AF_INET, SOCK_STREAM, 0);
< else if (link_type == LINK_UDP)
< sock = socket(AF_INET, SOCK_DGRAM, 0);
< else
< {
---
> if (link_type == LINK_TCP)
> sock = socket(AF_INET, SOCK_STREAM, 0);
> else if (link_type == LINK_UDP)
> sock = socket(AF_INET, SOCK_DGRAM, 0);
> else {
638,639c620,621
< fprintf(stderr, "PacketAlias/GetSocket(): ");
< fprintf(stderr, "incorrect link type\n");
---
> fprintf(stderr, "PacketAlias/GetSocket(): ");
> fprintf(stderr, "incorrect link type\n");
641,642c623,624
< return(0);
< }
---
> return (0);
> }
644,645c626
< if (sock < 0)
< {
---
> if (sock < 0) {
647,648c628,629
< fprintf(stderr, "PacketAlias/GetSocket(): ");
< fprintf(stderr, "socket() error %d\n", *sockfd);
---
> fprintf(stderr, "PacketAlias/GetSocket(): ");
> fprintf(stderr, "socket() error %d\n", *sockfd);
650,651c631,635
< return(0);
< }
---
> return (0);
> }
> sock_addr.sin_family = AF_INET;
> sock_addr.sin_addr.s_addr = htonl(INADDR_ANY);
> sock_addr.sin_port = port_net;
653,670c637,647
< sock_addr.sin_family = AF_INET;
< sock_addr.sin_addr.s_addr = htonl(INADDR_ANY);
< sock_addr.sin_port = port_net;
<
< err = bind(sock,
< (struct sockaddr *) &sock_addr,
< sizeof(sock_addr));
< if (err == 0)
< {
< la->sockCount++;
< *sockfd = sock;
< return(1);
< }
< else
< {
< close(sock);
< return(0);
< }
---
> err = bind(sock,
> (struct sockaddr *)&sock_addr,
> sizeof(sock_addr));
> if (err == 0) {
> la->sockCount++;
> *sockfd = sock;
> return (1);
> } else {
> close(sock);
> return (0);
> }
682,688c659,665
< struct in_addr dst_addr,
< struct in_addr alias_addr,
< u_short src_port,
< u_short dst_port,
< u_short port_count,
< u_char proto,
< u_char align)
---
> struct in_addr dst_addr,
> struct in_addr alias_addr,
> u_short src_port,
> u_short dst_port,
> u_short port_count,
> u_char proto,
> u_char align)
690,693c667,670
< int i, j;
< int max_trials;
< u_short port_sys;
< int link_type;
---
> int i, j;
> int max_trials;
> u_short port_sys;
> int link_type;
695,697c672,674
< /*
< * Get link_type from protocol
< */
---
> /*
> * Get link_type from protocol
> */
699,710c676,686
< switch (proto)
< {
< case IPPROTO_UDP:
< link_type = LINK_UDP;
< break;
< case IPPROTO_TCP:
< link_type = LINK_TCP;
< break;
< default:
< return (0);
< break;
< }
---
> switch (proto) {
> case IPPROTO_UDP:
> link_type = LINK_UDP;
> break;
> case IPPROTO_TCP:
> link_type = LINK_TCP;
> break;
> default:
> return (0);
> break;
> }
712,716c688,692
< /*
< * The aliasing port is automatically selected
< * by one of two methods below:
< */
< max_trials = GET_NEW_PORT_MAX_ATTEMPTS;
---
> /*
> * The aliasing port is automatically selected by one of two
> * methods below:
> */
> max_trials = GET_NEW_PORT_MAX_ATTEMPTS;
718,726c694,700
< if (la->packetAliasMode & PKT_ALIAS_SAME_PORTS) {
< /*
< * When the ALIAS_SAME_PORTS option is
< * chosen, the first try will be the
< * actual source port. If this is already
< * in use, the remainder of the trials
< * will be random.
< */
< port_sys = ntohs(src_port);
---
> if (la->packetAliasMode & PKT_ALIAS_SAME_PORTS) {
> /*
> * When the ALIAS_SAME_PORTS option is chosen, the first
> * try will be the actual source port. If this is already
> * in use, the remainder of the trials will be random.
> */
> port_sys = ntohs(src_port);
728c702
< } else {
---
> } else {
730,734c704,708
< /* First trial and all subsequent are random. */
< if (align == FIND_EVEN_ALIAS_BASE)
< port_sys = random() & ALIAS_PORT_MASK_EVEN;
< else
< port_sys = random() & ALIAS_PORT_MASK;
---
> /* First trial and all subsequent are random. */
> if (align == FIND_EVEN_ALIAS_BASE)
> port_sys = random() & ALIAS_PORT_MASK_EVEN;
> else
> port_sys = random() & ALIAS_PORT_MASK;
736,737c710,711
< port_sys += ALIAS_PORT_BASE;
< }
---
> port_sys += ALIAS_PORT_BASE;
> }
740c714
< for (i = 0; i < max_trials; i++) {
---
> for (i = 0; i < max_trials; i++) {
742c716
< struct alias_link *search_result;
---
> struct alias_link *search_result;
744,748c718,722
< for (j = 0; j < port_count; j++)
< if (0 != (search_result = FindLinkIn(la, dst_addr, alias_addr,
< dst_port, htons(port_sys + j),
< link_type, 0)))
< break;
---
> for (j = 0; j < port_count; j++)
> if (0 != (search_result = FindLinkIn(la, dst_addr, alias_addr,
> dst_port, htons(port_sys + j),
> link_type, 0)))
> break;
750,752c724,726
< /* Found a good range, return base */
< if (j == port_count)
< return (htons(port_sys));
---
> /* Found a good range, return base */
> if (j == port_count)
> return (htons(port_sys));
754,758c728,732
< /* Find a new base to try */
< if (align == FIND_EVEN_ALIAS_BASE)
< port_sys = random() & ALIAS_PORT_MASK_EVEN;
< else
< port_sys = random() & ALIAS_PORT_MASK;
---
> /* Find a new base to try */
> if (align == FIND_EVEN_ALIAS_BASE)
> port_sys = random() & ALIAS_PORT_MASK_EVEN;
> else
> port_sys = random() & ALIAS_PORT_MASK;
760,761c734,735
< port_sys += ALIAS_PORT_BASE;
< }
---
> port_sys += ALIAS_PORT_BASE;
> }
764,765c738,739
< fprintf(stderr, "PacketAlias/FindNewPortGroup(): ");
< fprintf(stderr, "could not find free port(s)\n");
---
> fprintf(stderr, "PacketAlias/FindNewPortGroup(): ");
> fprintf(stderr, "could not find free port(s)\n");
768c742
< return(0);
---
> return (0);
774,775c748,749
< struct alias_link *link;
< int i, icount;
---
> struct alias_link *link;
> int i, icount;
777,789c751,755
< icount = 0;
< for (i=0; i<LINK_TABLE_OUT_SIZE; i++)
< {
< link = LIST_FIRST(&la->linkTableOut[i]);
< while (link != NULL)
< {
< struct alias_link *link_next;
< link_next = LIST_NEXT(link, list_out);
< icount++;
< DeleteLink(link);
< link = link_next;
< }
< }
---
> icount = 0;
> for (i = 0; i < LINK_TABLE_OUT_SIZE; i++) {
> link = LIST_FIRST(&la->linkTableOut[i]);
> while (link != NULL) {
> struct alias_link *link_next;
791c757,764
< la->cleanupIndex =0;
---
> link_next = LIST_NEXT(link, list_out);
> icount++;
> DeleteLink(link);
> link = link_next;
> }
> }
>
> la->cleanupIndex = 0;
798,799c771,772
< int icount;
< struct alias_link *link;
---
> int icount;
> struct alias_link *link;
801,806c774,778
< icount = 0;
< link = LIST_FIRST(&la->linkTableOut[la->cleanupIndex++]);
< while (link != NULL)
< {
< int idelta;
< struct alias_link *link_next;
---
> icount = 0;
> link = LIST_FIRST(&la->linkTableOut[la->cleanupIndex++]);
> while (link != NULL) {
> int idelta;
> struct alias_link *link_next;
808,815c780,785
< link_next = LIST_NEXT(link, list_out);
< idelta = la->timeStamp - link->timestamp;
< switch (link->link_type)
< {
< case LINK_TCP:
< if (idelta > link->expire_time)
< {
< struct tcp_dat *tcp_aux;
---
> link_next = LIST_NEXT(link, list_out);
> idelta = la->timeStamp - link->timestamp;
> switch (link->link_type) {
> case LINK_TCP:
> if (idelta > link->expire_time) {
> struct tcp_dat *tcp_aux;
817,835c787,803
< tcp_aux = link->data.tcp;
< if (tcp_aux->state.in != ALIAS_TCP_STATE_CONNECTED
< || tcp_aux->state.out != ALIAS_TCP_STATE_CONNECTED)
< {
< DeleteLink(link);
< icount++;
< }
< }
< break;
< default:
< if (idelta > link->expire_time)
< {
< DeleteLink(link);
< icount++;
< }
< break;
< }
< link = link_next;
< }
---
> tcp_aux = link->data.tcp;
> if (tcp_aux->state.in != ALIAS_TCP_STATE_CONNECTED
> || tcp_aux->state.out != ALIAS_TCP_STATE_CONNECTED) {
> DeleteLink(link);
> icount++;
> }
> }
> break;
> default:
> if (idelta > link->expire_time) {
> DeleteLink(link);
> icount++;
> }
> break;
> }
> link = link_next;
> }
837,838c805,806
< if (la->cleanupIndex == LINK_TABLE_OUT_SIZE)
< la->cleanupIndex = 0;
---
> if (la->cleanupIndex == LINK_TABLE_OUT_SIZE)
> la->cleanupIndex = 0;
844c812
< struct libalias *la = link->la;
---
> struct libalias *la = link->la;
847,848c815,816
< if (la->deleteAllLinks == 0 && link->flags & LINK_PERMANENT)
< return;
---
> if (la->deleteAllLinks == 0 && link->flags & LINK_PERMANENT)
> return;
852c820
< ClearFWHole(link);
---
> ClearFWHole(link);
856,857c824,825
< if (link->server != NULL) {
< struct server *head, *curr, *next;
---
> if (link->server != NULL) {
> struct server *head, *curr, *next;
859,865c827,832
< head = curr = link->server;
< do {
< next = curr->next;
< free(curr);
< } while ((curr = next) != head);
< }
<
---
> head = curr = link->server;
> do {
> next = curr->next;
> free(curr);
> } while ((curr = next) != head);
> }
867c834
< LIST_REMOVE(link, list_out);
---
> LIST_REMOVE(link, list_out);
870c837
< LIST_REMOVE(link, list_in);
---
> LIST_REMOVE(link, list_in);
873,878c840,843
< if (link->sockfd != -1)
< {
< la->sockCount--;
< close(link->sockfd);
< }
<
---
> if (link->sockfd != -1) {
> la->sockCount--;
> close(link->sockfd);
> }
880,902c845,866
< switch(link->link_type)
< {
< case LINK_ICMP:
< la->icmpLinkCount--;
< break;
< case LINK_UDP:
< la->udpLinkCount--;
< break;
< case LINK_TCP:
< la->tcpLinkCount--;
< free(link->data.tcp);
< break;
< case LINK_PPTP:
< la->pptpLinkCount--;
< break;
< case LINK_FRAGMENT_ID:
< la->fragmentIdLinkCount--;
< break;
< case LINK_FRAGMENT_PTR:
< la->fragmentPtrLinkCount--;
< if (link->data.frag_ptr != NULL)
< free(link->data.frag_ptr);
< break;
---
> switch (link->link_type) {
> case LINK_ICMP:
> la->icmpLinkCount--;
> break;
> case LINK_UDP:
> la->udpLinkCount--;
> break;
> case LINK_TCP:
> la->tcpLinkCount--;
> free(link->data.tcp);
> break;
> case LINK_PPTP:
> la->pptpLinkCount--;
> break;
> case LINK_FRAGMENT_ID:
> la->fragmentIdLinkCount--;
> break;
> case LINK_FRAGMENT_PTR:
> la->fragmentPtrLinkCount--;
> if (link->data.frag_ptr != NULL)
> free(link->data.frag_ptr);
> break;
904,908c868,872
< break;
< default:
< la->protoLinkCount--;
< break;
< }
---
> break;
> default:
> la->protoLinkCount--;
> break;
> }
911c875
< free(link);
---
> free(link);
914,917c878,880
< if (la->packetAliasMode & PKT_ALIAS_LOG)
< {
< ShowAliasStats(la);
< }
---
> if (la->packetAliasMode & PKT_ALIAS_LOG) {
> ShowAliasStats(la);
> }
922,931c885,895
< AddLink(struct libalias *la, struct in_addr src_addr,
< struct in_addr dst_addr,
< struct in_addr alias_addr,
< u_short src_port,
< u_short dst_port,
< int alias_port_param, /* if less than zero, alias */
< int link_type) /* port will be automatically */
< { /* chosen. If greater than */
< u_int start_point; /* zero, equal to alias port */
< struct alias_link *link;
---
> AddLink(struct libalias *la, struct in_addr src_addr,
> struct in_addr dst_addr,
> struct in_addr alias_addr,
> u_short src_port,
> u_short dst_port,
> int alias_port_param, /* if less than zero, alias */
> int link_type)
> { /* port will be automatically *//* chosen.
> * If greater than */
> u_int start_point; /* zero, equal to alias port */
> struct alias_link *link;
933,950c897,913
< link = malloc(sizeof(struct alias_link));
< if (link != NULL)
< {
< /* Basic initialization */
< link->la = la;
< link->src_addr = src_addr;
< link->dst_addr = dst_addr;
< link->alias_addr = alias_addr;
< link->proxy_addr.s_addr = INADDR_ANY;
< link->src_port = src_port;
< link->dst_port = dst_port;
< link->proxy_port = 0;
< link->server = NULL;
< link->link_type = link_type;
< link->sockfd = -1;
< link->flags = 0;
< link->pflags = 0;
< link->timestamp = la->timeStamp;
---
> link = malloc(sizeof(struct alias_link));
> if (link != NULL) {
> /* Basic initialization */
> link->la = la;
> link->src_addr = src_addr;
> link->dst_addr = dst_addr;
> link->alias_addr = alias_addr;
> link->proxy_addr.s_addr = INADDR_ANY;
> link->src_port = src_port;
> link->dst_port = dst_port;
> link->proxy_port = 0;
> link->server = NULL;
> link->link_type = link_type;
> link->sockfd = -1;
> link->flags = 0;
> link->pflags = 0;
> link->timestamp = la->timeStamp;
952,978c915,940
< /* Expiration time */
< switch (link_type)
< {
< case LINK_ICMP:
< link->expire_time = ICMP_EXPIRE_TIME;
< break;
< case LINK_UDP:
< link->expire_time = UDP_EXPIRE_TIME;
< break;
< case LINK_TCP:
< link->expire_time = TCP_EXPIRE_INITIAL;
< break;
< case LINK_PPTP:
< link->flags |= LINK_PERMANENT; /* no timeout. */
< break;
< case LINK_FRAGMENT_ID:
< link->expire_time = FRAGMENT_ID_EXPIRE_TIME;
< break;
< case LINK_FRAGMENT_PTR:
< link->expire_time = FRAGMENT_PTR_EXPIRE_TIME;
< break;
< case LINK_ADDR:
< break;
< default:
< link->expire_time = PROTO_EXPIRE_TIME;
< break;
< }
---
> /* Expiration time */
> switch (link_type) {
> case LINK_ICMP:
> link->expire_time = ICMP_EXPIRE_TIME;
> break;
> case LINK_UDP:
> link->expire_time = UDP_EXPIRE_TIME;
> break;
> case LINK_TCP:
> link->expire_time = TCP_EXPIRE_INITIAL;
> break;
> case LINK_PPTP:
> link->flags |= LINK_PERMANENT; /* no timeout. */
> break;
> case LINK_FRAGMENT_ID:
> link->expire_time = FRAGMENT_ID_EXPIRE_TIME;
> break;
> case LINK_FRAGMENT_PTR:
> link->expire_time = FRAGMENT_PTR_EXPIRE_TIME;
> break;
> case LINK_ADDR:
> break;
> default:
> link->expire_time = PROTO_EXPIRE_TIME;
> break;
> }
980,984c942,946
< /* Determine alias flags */
< if (dst_addr.s_addr == INADDR_ANY)
< link->flags |= LINK_UNKNOWN_DEST_ADDR;
< if (dst_port == 0)
< link->flags |= LINK_UNKNOWN_DEST_PORT;
---
> /* Determine alias flags */
> if (dst_addr.s_addr == INADDR_ANY)
> link->flags |= LINK_UNKNOWN_DEST_ADDR;
> if (dst_port == 0)
> link->flags |= LINK_UNKNOWN_DEST_PORT;
986,991c948,955
< /* Determine alias port */
< if (GetNewPort(la, link, alias_port_param) != 0)
< {
< free(link);
< return(NULL);
< }
---
> /* Determine alias port */
> if (GetNewPort(la, link, alias_port_param) != 0) {
> free(link);
> return (NULL);
> }
> /* Link-type dependent initialization */
> switch (link_type) {
> struct tcp_dat *aux_tcp;
993,996c957,966
< /* Link-type dependent initialization */
< switch(link_type)
< {
< struct tcp_dat *aux_tcp;
---
> case LINK_ICMP:
> la->icmpLinkCount++;
> break;
> case LINK_UDP:
> la->udpLinkCount++;
> break;
> case LINK_TCP:
> aux_tcp = malloc(sizeof(struct tcp_dat));
> if (aux_tcp != NULL) {
> int i;
998,1021c968,977
< case LINK_ICMP:
< la->icmpLinkCount++;
< break;
< case LINK_UDP:
< la->udpLinkCount++;
< break;
< case LINK_TCP:
< aux_tcp = malloc(sizeof(struct tcp_dat));
< if (aux_tcp != NULL)
< {
< int i;
<
< la->tcpLinkCount++;
< aux_tcp->state.in = ALIAS_TCP_STATE_NOT_CONNECTED;
< aux_tcp->state.out = ALIAS_TCP_STATE_NOT_CONNECTED;
< aux_tcp->state.index = 0;
< aux_tcp->state.ack_modified = 0;
< for (i=0; i<N_LINK_TCP_DATA; i++)
< aux_tcp->ack[i].active = 0;
< aux_tcp->fwhole = -1;
< link->data.tcp = aux_tcp;
< }
< else
< {
---
> la->tcpLinkCount++;
> aux_tcp->state.in = ALIAS_TCP_STATE_NOT_CONNECTED;
> aux_tcp->state.out = ALIAS_TCP_STATE_NOT_CONNECTED;
> aux_tcp->state.index = 0;
> aux_tcp->state.ack_modified = 0;
> for (i = 0; i < N_LINK_TCP_DATA; i++)
> aux_tcp->ack[i].active = 0;
> aux_tcp->fwhole = -1;
> link->data.tcp = aux_tcp;
> } else {
1023,1024c979,980
< fprintf(stderr, "PacketAlias/AddLink: ");
< fprintf(stderr, " cannot allocate auxiliary TCP data\n");
---
> fprintf(stderr, "PacketAlias/AddLink: ");
> fprintf(stderr, " cannot allocate auxiliary TCP data\n");
1026,1044c982,1000
< free(link);
< return (NULL);
< }
< break;
< case LINK_PPTP:
< la->pptpLinkCount++;
< break;
< case LINK_FRAGMENT_ID:
< la->fragmentIdLinkCount++;
< break;
< case LINK_FRAGMENT_PTR:
< la->fragmentPtrLinkCount++;
< break;
< case LINK_ADDR:
< break;
< default:
< la->protoLinkCount++;
< break;
< }
---
> free(link);
> return (NULL);
> }
> break;
> case LINK_PPTP:
> la->pptpLinkCount++;
> break;
> case LINK_FRAGMENT_ID:
> la->fragmentIdLinkCount++;
> break;
> case LINK_FRAGMENT_PTR:
> la->fragmentPtrLinkCount++;
> break;
> case LINK_ADDR:
> break;
> default:
> la->protoLinkCount++;
> break;
> }
1046,1049c1002,1005
< /* Set up pointers for output lookup table */
< start_point = StartPointOut(src_addr, dst_addr,
< src_port, dst_port, link_type);
< LIST_INSERT_HEAD(&la->linkTableOut[start_point], link, list_out);
---
> /* Set up pointers for output lookup table */
> start_point = StartPointOut(src_addr, dst_addr,
> src_port, dst_port, link_type);
> LIST_INSERT_HEAD(&la->linkTableOut[start_point], link, list_out);
1051,1056c1007,1010
< /* Set up pointers for input lookup table */
< start_point = StartPointIn(alias_addr, link->alias_port, link_type);
< LIST_INSERT_HEAD(&la->linkTableIn[start_point], link, list_in);
< }
< else
< {
---
> /* Set up pointers for input lookup table */
> start_point = StartPointIn(alias_addr, link->alias_port, link_type);
> LIST_INSERT_HEAD(&la->linkTableIn[start_point], link, list_in);
> } else {
1058,1059c1012,1013
< fprintf(stderr, "PacketAlias/AddLink(): ");
< fprintf(stderr, "malloc() call failed.\n");
---
> fprintf(stderr, "PacketAlias/AddLink(): ");
> fprintf(stderr, "malloc() call failed.\n");
1061c1015
< }
---
> }
1063,1068c1017,1020
< if (la->packetAliasMode & PKT_ALIAS_LOG)
< {
< ShowAliasStats(la);
< }
<
< return(link);
---
> if (la->packetAliasMode & PKT_ALIAS_LOG) {
> ShowAliasStats(la);
> }
> return (link);
1073,1082c1025,1035
< struct in_addr src_addr,
< struct in_addr dst_addr,
< struct in_addr alias_addr,
< u_short src_port,
< u_short dst_port,
< int alias_port_param, /* if less than zero, alias */
< int link_type) /* port will be automatically */
< { /* chosen. If greater than */
< struct alias_link *new_link; /* zero, equal to alias port */
< struct libalias *la = old_link->la;
---
> struct in_addr src_addr,
> struct in_addr dst_addr,
> struct in_addr alias_addr,
> u_short src_port,
> u_short dst_port,
> int alias_port_param, /* if less than zero, alias */
> int link_type)
> { /* port will be automatically *//* chosen.
> * If greater than */
> struct alias_link *new_link; /* zero, equal to alias port */
> struct libalias *la = old_link->la;
1084,1086c1037,1039
< new_link = AddLink(la, src_addr, dst_addr, alias_addr,
< src_port, dst_port, alias_port_param,
< link_type);
---
> new_link = AddLink(la, src_addr, dst_addr, alias_addr,
> src_port, dst_port, alias_port_param,
> link_type);
1088,1092c1041,1045
< if (new_link != NULL &&
< old_link->link_type == LINK_TCP &&
< old_link->data.tcp->fwhole > 0) {
< PunchFWHole(new_link);
< }
---
> if (new_link != NULL &&
> old_link->link_type == LINK_TCP &&
> old_link->data.tcp->fwhole > 0) {
> PunchFWHole(new_link);
> }
1094,1095c1047,1048
< DeleteLink(old_link);
< return new_link;
---
> DeleteLink(old_link);
> return new_link;
1100,1104c1053,1057
< struct in_addr dst_addr,
< u_short src_port,
< u_short dst_port,
< int link_type,
< int replace_partial_links)
---
> struct in_addr dst_addr,
> u_short src_port,
> u_short dst_port,
> int link_type,
> int replace_partial_links)
1106,1107c1059,1060
< u_int i;
< struct alias_link *link;
---
> u_int i;
> struct alias_link *link;
1109,1122c1062,1073
< i = StartPointOut(src_addr, dst_addr, src_port, dst_port, link_type);
< LIST_FOREACH(link, &la->linkTableOut[i], list_out)
< {
< if (link->src_addr.s_addr == src_addr.s_addr
< && link->server == NULL
< && link->dst_addr.s_addr == dst_addr.s_addr
< && link->dst_port == dst_port
< && link->src_port == src_port
< && link->link_type == link_type)
< {
< link->timestamp = la->timeStamp;
< break;
< }
< }
---
> i = StartPointOut(src_addr, dst_addr, src_port, dst_port, link_type);
> LIST_FOREACH(link, &la->linkTableOut[i], list_out) {
> if (link->src_addr.s_addr == src_addr.s_addr
> && link->server == NULL
> && link->dst_addr.s_addr == dst_addr.s_addr
> && link->dst_port == dst_port
> && link->src_port == src_port
> && link->link_type == link_type) {
> link->timestamp = la->timeStamp;
> break;
> }
> }
1125,1150c1076,1096
< if (link == NULL && replace_partial_links)
< {
< if (dst_port != 0 && dst_addr.s_addr != INADDR_ANY)
< {
< link = _FindLinkOut(la, src_addr, dst_addr, src_port, 0,
< link_type, 0);
< if (link == NULL)
< link = _FindLinkOut(la, src_addr, la->nullAddress, src_port,
< dst_port, link_type, 0);
< }
< if (link == NULL &&
< (dst_port != 0 || dst_addr.s_addr != INADDR_ANY))
< {
< link = _FindLinkOut(la, src_addr, la->nullAddress, src_port, 0,
< link_type, 0);
< }
< if (link != NULL)
< {
< link = ReLink(link,
< src_addr, dst_addr, link->alias_addr,
< src_port, dst_port, link->alias_port,
< link_type);
< }
< }
<
< return(link);
---
> if (link == NULL && replace_partial_links) {
> if (dst_port != 0 && dst_addr.s_addr != INADDR_ANY) {
> link = _FindLinkOut(la, src_addr, dst_addr, src_port, 0,
> link_type, 0);
> if (link == NULL)
> link = _FindLinkOut(la, src_addr, la->nullAddress, src_port,
> dst_port, link_type, 0);
> }
> if (link == NULL &&
> (dst_port != 0 || dst_addr.s_addr != INADDR_ANY)) {
> link = _FindLinkOut(la, src_addr, la->nullAddress, src_port, 0,
> link_type, 0);
> }
> if (link != NULL) {
> link = ReLink(link,
> src_addr, dst_addr, link->alias_addr,
> src_port, dst_port, link->alias_port,
> link_type);
> }
> }
> return (link);
1155,1159c1101,1105
< struct in_addr dst_addr,
< u_short src_port,
< u_short dst_port,
< int link_type,
< int replace_partial_links)
---
> struct in_addr dst_addr,
> u_short src_port,
> u_short dst_port,
> int link_type,
> int replace_partial_links)
1161c1107
< struct alias_link *link;
---
> struct alias_link *link;
1163,1164c1109,1110
< link = _FindLinkOut(la, src_addr, dst_addr, src_port, dst_port,
< link_type, replace_partial_links);
---
> link = _FindLinkOut(la, src_addr, dst_addr, src_port, dst_port,
> link_type, replace_partial_links);
1166,1180c1112,1125
< if (link == NULL)
< {
< /* The following allows permanent links to be
< specified as using the default source address
< (i.e. device interface address) without knowing
< in advance what that address is. */
< if (la->aliasAddress.s_addr != INADDR_ANY &&
< src_addr.s_addr == la->aliasAddress.s_addr)
< {
< link = _FindLinkOut(la, la->nullAddress, dst_addr, src_port, dst_port,
< link_type, replace_partial_links);
< }
< }
<
< return(link);
---
> if (link == NULL) {
> /*
> * The following allows permanent links to be specified as
> * using the default source address (i.e. device interface
> * address) without knowing in advance what that address
> * is.
> */
> if (la->aliasAddress.s_addr != INADDR_ANY &&
> src_addr.s_addr == la->aliasAddress.s_addr) {
> link = _FindLinkOut(la, la->nullAddress, dst_addr, src_port, dst_port,
> link_type, replace_partial_links);
> }
> }
> return (link);
1186,1190c1131,1135
< struct in_addr alias_addr,
< u_short dst_port,
< u_short alias_port,
< int link_type,
< int replace_partial_links)
---
> struct in_addr alias_addr,
> u_short dst_port,
> u_short alias_port,
> int link_type,
> int replace_partial_links)
1192,1198c1137,1143
< int flags_in;
< u_int start_point;
< struct alias_link *link;
< struct alias_link *link_fully_specified;
< struct alias_link *link_unknown_all;
< struct alias_link *link_unknown_dst_addr;
< struct alias_link *link_unknown_dst_port;
---
> int flags_in;
> u_int start_point;
> struct alias_link *link;
> struct alias_link *link_fully_specified;
> struct alias_link *link_unknown_all;
> struct alias_link *link_unknown_dst_addr;
> struct alias_link *link_unknown_dst_port;
1201,1204c1146,1149
< link_fully_specified = NULL;
< link_unknown_all = NULL;
< link_unknown_dst_addr = NULL;
< link_unknown_dst_port = NULL;
---
> link_fully_specified = NULL;
> link_unknown_all = NULL;
> link_unknown_dst_addr = NULL;
> link_unknown_dst_port = NULL;
1209,1213c1154,1158
< flags_in = 0;
< if (dst_addr.s_addr == INADDR_ANY)
< flags_in |= LINK_UNKNOWN_DEST_ADDR;
< if (dst_port == 0)
< flags_in |= LINK_UNKNOWN_DEST_PORT;
---
> flags_in = 0;
> if (dst_addr.s_addr == INADDR_ANY)
> flags_in |= LINK_UNKNOWN_DEST_ADDR;
> if (dst_port == 0)
> flags_in |= LINK_UNKNOWN_DEST_PORT;
1216,1219c1161,1163
< start_point = StartPointIn(alias_addr, alias_port, link_type);
< LIST_FOREACH(link, &la->linkTableIn[start_point], list_in)
< {
< int flags;
---
> start_point = StartPointIn(alias_addr, alias_port, link_type);
> LIST_FOREACH(link, &la->linkTableIn[start_point], list_in) {
> int flags;
1221,1267c1165,1200
< flags = flags_in | link->flags;
< if (!(flags & LINK_PARTIALLY_SPECIFIED))
< {
< if (link->alias_addr.s_addr == alias_addr.s_addr
< && link->alias_port == alias_port
< && link->dst_addr.s_addr == dst_addr.s_addr
< && link->dst_port == dst_port
< && link->link_type == link_type)
< {
< link_fully_specified = link;
< break;
< }
< }
< else if ((flags & LINK_UNKNOWN_DEST_ADDR)
< && (flags & LINK_UNKNOWN_DEST_PORT))
< {
< if (link->alias_addr.s_addr == alias_addr.s_addr
< && link->alias_port == alias_port
< && link->link_type == link_type)
< {
< if (link_unknown_all == NULL)
< link_unknown_all = link;
< }
< }
< else if (flags & LINK_UNKNOWN_DEST_ADDR)
< {
< if (link->alias_addr.s_addr == alias_addr.s_addr
< && link->alias_port == alias_port
< && link->link_type == link_type
< && link->dst_port == dst_port)
< {
< if (link_unknown_dst_addr == NULL)
< link_unknown_dst_addr = link;
< }
< }
< else if (flags & LINK_UNKNOWN_DEST_PORT)
< {
< if (link->alias_addr.s_addr == alias_addr.s_addr
< && link->alias_port == alias_port
< && link->link_type == link_type
< && link->dst_addr.s_addr == dst_addr.s_addr)
< {
< if (link_unknown_dst_port == NULL)
< link_unknown_dst_port = link;
< }
< }
< }
---
> flags = flags_in | link->flags;
> if (!(flags & LINK_PARTIALLY_SPECIFIED)) {
> if (link->alias_addr.s_addr == alias_addr.s_addr
> && link->alias_port == alias_port
> && link->dst_addr.s_addr == dst_addr.s_addr
> && link->dst_port == dst_port
> && link->link_type == link_type) {
> link_fully_specified = link;
> break;
> }
> } else if ((flags & LINK_UNKNOWN_DEST_ADDR)
> && (flags & LINK_UNKNOWN_DEST_PORT)) {
> if (link->alias_addr.s_addr == alias_addr.s_addr
> && link->alias_port == alias_port
> && link->link_type == link_type) {
> if (link_unknown_all == NULL)
> link_unknown_all = link;
> }
> } else if (flags & LINK_UNKNOWN_DEST_ADDR) {
> if (link->alias_addr.s_addr == alias_addr.s_addr
> && link->alias_port == alias_port
> && link->link_type == link_type
> && link->dst_port == dst_port) {
> if (link_unknown_dst_addr == NULL)
> link_unknown_dst_addr = link;
> }
> } else if (flags & LINK_UNKNOWN_DEST_PORT) {
> if (link->alias_addr.s_addr == alias_addr.s_addr
> && link->alias_port == alias_port
> && link->link_type == link_type
> && link->dst_addr.s_addr == dst_addr.s_addr) {
> if (link_unknown_dst_port == NULL)
> link_unknown_dst_port = link;
> }
> }
> }
1271,1283c1204,1214
< if (link_fully_specified != NULL)
< {
< link_fully_specified->timestamp = la->timeStamp;
< link = link_fully_specified;
< }
< else if (link_unknown_dst_port != NULL)
< link = link_unknown_dst_port;
< else if (link_unknown_dst_addr != NULL)
< link = link_unknown_dst_addr;
< else if (link_unknown_all != NULL)
< link = link_unknown_all;
< else
< return (NULL);
---
> if (link_fully_specified != NULL) {
> link_fully_specified->timestamp = la->timeStamp;
> link = link_fully_specified;
> } else if (link_unknown_dst_port != NULL)
> link = link_unknown_dst_port;
> else if (link_unknown_dst_addr != NULL)
> link = link_unknown_dst_addr;
> else if (link_unknown_all != NULL)
> link = link_unknown_all;
> else
> return (NULL);
1285,1289c1216,1219
< if (replace_partial_links &&
< (link->flags & LINK_PARTIALLY_SPECIFIED || link->server != NULL))
< {
< struct in_addr src_addr;
< u_short src_port;
---
> if (replace_partial_links &&
> (link->flags & LINK_PARTIALLY_SPECIFIED || link->server != NULL)) {
> struct in_addr src_addr;
> u_short src_port;
1291,1298c1221,1228
< if (link->server != NULL) { /* LSNAT link */
< src_addr = link->server->addr;
< src_port = link->server->port;
< link->server = link->server->next;
< } else {
< src_addr = link->src_addr;
< src_port = link->src_port;
< }
---
> if (link->server != NULL) { /* LSNAT link */
> src_addr = link->server->addr;
> src_port = link->server->port;
> link->server = link->server->next;
> } else {
> src_addr = link->src_addr;
> src_port = link->src_port;
> }
1300,1306c1230,1235
< link = ReLink(link,
< src_addr, dst_addr, alias_addr,
< src_port, dst_port, alias_port,
< link_type);
< }
<
< return (link);
---
> link = ReLink(link,
> src_addr, dst_addr, alias_addr,
> src_port, dst_port, alias_port,
> link_type);
> }
> return (link);
1311,1315c1240,1244
< struct in_addr alias_addr,
< u_short dst_port,
< u_short alias_port,
< int link_type,
< int replace_partial_links)
---
> struct in_addr alias_addr,
> u_short dst_port,
> u_short alias_port,
> int link_type,
> int replace_partial_links)
1317c1246
< struct alias_link *link;
---
> struct alias_link *link;
1319,1320c1248,1249
< link = _FindLinkIn(la, dst_addr, alias_addr, dst_port, alias_port,
< link_type, replace_partial_links);
---
> link = _FindLinkIn(la, dst_addr, alias_addr, dst_port, alias_port,
> link_type, replace_partial_links);
1322,1336c1251,1264
< if (link == NULL)
< {
< /* The following allows permanent links to be
< specified as using the default aliasing address
< (i.e. device interface address) without knowing
< in advance what that address is. */
< if (la->aliasAddress.s_addr != INADDR_ANY &&
< alias_addr.s_addr == la->aliasAddress.s_addr)
< {
< link = _FindLinkIn(la, dst_addr, la->nullAddress, dst_port, alias_port,
< link_type, replace_partial_links);
< }
< }
<
< return(link);
---
> if (link == NULL) {
> /*
> * The following allows permanent links to be specified as
> * using the default aliasing address (i.e. device
> * interface address) without knowing in advance what that
> * address is.
> */
> if (la->aliasAddress.s_addr != INADDR_ANY &&
> alias_addr.s_addr == la->aliasAddress.s_addr) {
> link = _FindLinkIn(la, dst_addr, la->nullAddress, dst_port, alias_port,
> link_type, replace_partial_links);
> }
> }
> return (link);
1361,1363c1289,1291
< struct in_addr alias_addr,
< u_short id_alias,
< int create)
---
> struct in_addr alias_addr,
> u_short id_alias,
> int create)
1365c1293
< struct alias_link *link;
---
> struct alias_link *link;
1367,1372c1295,1299
< link = FindLinkIn(la, dst_addr, alias_addr,
< NO_DEST_PORT, id_alias,
< LINK_ICMP, 0);
< if (link == NULL && create && !(la->packetAliasMode & PKT_ALIAS_DENY_INCOMING))
< {
< struct in_addr target_addr;
---
> link = FindLinkIn(la, dst_addr, alias_addr,
> NO_DEST_PORT, id_alias,
> LINK_ICMP, 0);
> if (link == NULL && create && !(la->packetAliasMode & PKT_ALIAS_DENY_INCOMING)) {
> struct in_addr target_addr;
1374,1380c1301,1306
< target_addr = FindOriginalAddress(la, alias_addr);
< link = AddLink(la, target_addr, dst_addr, alias_addr,
< id_alias, NO_DEST_PORT, id_alias,
< LINK_ICMP);
< }
<
< return (link);
---
> target_addr = FindOriginalAddress(la, alias_addr);
> link = AddLink(la, target_addr, dst_addr, alias_addr,
> id_alias, NO_DEST_PORT, id_alias,
> LINK_ICMP);
> }
> return (link);
1386,1388c1312,1314
< struct in_addr dst_addr,
< u_short id,
< int create)
---
> struct in_addr dst_addr,
> u_short id,
> int create)
1390c1316
< struct alias_link * link;
---
> struct alias_link *link;
1392,1397c1318,1322
< link = FindLinkOut(la, src_addr, dst_addr,
< id, NO_DEST_PORT,
< LINK_ICMP, 0);
< if (link == NULL && create)
< {
< struct in_addr alias_addr;
---
> link = FindLinkOut(la, src_addr, dst_addr,
> id, NO_DEST_PORT,
> LINK_ICMP, 0);
> if (link == NULL && create) {
> struct in_addr alias_addr;
1399,1405c1324,1329
< alias_addr = FindAliasAddress(la, src_addr);
< link = AddLink(la, src_addr, dst_addr, alias_addr,
< id, NO_DEST_PORT, GET_ALIAS_ID,
< LINK_ICMP);
< }
<
< return(link);
---
> alias_addr = FindAliasAddress(la, src_addr);
> link = AddLink(la, src_addr, dst_addr, alias_addr,
> id, NO_DEST_PORT, GET_ALIAS_ID,
> LINK_ICMP);
> }
> return (link);
1411,1412c1335,1336
< struct in_addr alias_addr,
< u_short ip_id)
---
> struct in_addr alias_addr,
> u_short ip_id)
1414c1338
< struct alias_link *link;
---
> struct alias_link *link;
1416,1418c1340,1342
< link = FindLinkIn(la, dst_addr, alias_addr,
< NO_DEST_PORT, ip_id,
< LINK_FRAGMENT_ID, 0);
---
> link = FindLinkIn(la, dst_addr, alias_addr,
> NO_DEST_PORT, ip_id,
> LINK_FRAGMENT_ID, 0);
1420,1427c1344,1349
< if (link == NULL)
< {
< link = AddLink(la, la->nullAddress, dst_addr, alias_addr,
< NO_SRC_PORT, NO_DEST_PORT, ip_id,
< LINK_FRAGMENT_ID);
< }
<
< return(link);
---
> if (link == NULL) {
> link = AddLink(la, la->nullAddress, dst_addr, alias_addr,
> NO_SRC_PORT, NO_DEST_PORT, ip_id,
> LINK_FRAGMENT_ID);
> }
> return (link);
1432,1434c1354,1357
< FindFragmentIn2(struct libalias *la, struct in_addr dst_addr, /* Doesn't add a link if one */
< struct in_addr alias_addr, /* is not found. */
< u_short ip_id)
---
> FindFragmentIn2(struct libalias *la, struct in_addr dst_addr, /* Doesn't add a link if
> * one */
> struct in_addr alias_addr, /* is not found. */
> u_short ip_id)
1436,1438c1359,1361
< return FindLinkIn(la, dst_addr, alias_addr,
< NO_DEST_PORT, ip_id,
< LINK_FRAGMENT_ID, 0);
---
> return FindLinkIn(la, dst_addr, alias_addr,
> NO_DEST_PORT, ip_id,
> LINK_FRAGMENT_ID, 0);
1444c1367
< u_short ip_id)
---
> u_short ip_id)
1446,1448c1369,1371
< return AddLink(la, la->nullAddress, dst_addr, la->nullAddress,
< NO_SRC_PORT, NO_DEST_PORT, ip_id,
< LINK_FRAGMENT_PTR);
---
> return AddLink(la, la->nullAddress, dst_addr, la->nullAddress,
> NO_SRC_PORT, NO_DEST_PORT, ip_id,
> LINK_FRAGMENT_PTR);
1454c1377
< u_short ip_id)
---
> u_short ip_id)
1456,1458c1379,1381
< return FindLinkIn(la, dst_addr, la->nullAddress,
< NO_DEST_PORT, ip_id,
< LINK_FRAGMENT_PTR, 0);
---
> return FindLinkIn(la, dst_addr, la->nullAddress,
> NO_DEST_PORT, ip_id,
> LINK_FRAGMENT_PTR, 0);
1464,1465c1387,1388
< struct in_addr alias_addr,
< u_char proto)
---
> struct in_addr alias_addr,
> u_char proto)
1467c1390
< struct alias_link *link;
---
> struct alias_link *link;
1469,1471c1392,1394
< link = FindLinkIn(la, dst_addr, alias_addr,
< NO_DEST_PORT, 0,
< proto, 1);
---
> link = FindLinkIn(la, dst_addr, alias_addr,
> NO_DEST_PORT, 0,
> proto, 1);
1473,1475c1396,1397
< if (link == NULL && !(la->packetAliasMode & PKT_ALIAS_DENY_INCOMING))
< {
< struct in_addr target_addr;
---
> if (link == NULL && !(la->packetAliasMode & PKT_ALIAS_DENY_INCOMING)) {
> struct in_addr target_addr;
1477,1483c1399,1404
< target_addr = FindOriginalAddress(la, alias_addr);
< link = AddLink(la, target_addr, dst_addr, alias_addr,
< NO_SRC_PORT, NO_DEST_PORT, 0,
< proto);
< }
<
< return (link);
---
> target_addr = FindOriginalAddress(la, alias_addr);
> link = AddLink(la, target_addr, dst_addr, alias_addr,
> NO_SRC_PORT, NO_DEST_PORT, 0,
> proto);
> }
> return (link);
1489,1490c1410,1411
< struct in_addr dst_addr,
< u_char proto)
---
> struct in_addr dst_addr,
> u_char proto)
1492c1413
< struct alias_link *link;
---
> struct alias_link *link;
1494,1496c1415,1417
< link = FindLinkOut(la, src_addr, dst_addr,
< NO_SRC_PORT, NO_DEST_PORT,
< proto, 1);
---
> link = FindLinkOut(la, src_addr, dst_addr,
> NO_SRC_PORT, NO_DEST_PORT,
> proto, 1);
1498,1500c1419,1420
< if (link == NULL)
< {
< struct in_addr alias_addr;
---
> if (link == NULL) {
> struct in_addr alias_addr;
1502,1508c1422,1427
< alias_addr = FindAliasAddress(la, src_addr);
< link = AddLink(la, src_addr, dst_addr, alias_addr,
< NO_SRC_PORT, NO_DEST_PORT, 0,
< proto);
< }
<
< return (link);
---
> alias_addr = FindAliasAddress(la, src_addr);
> link = AddLink(la, src_addr, dst_addr, alias_addr,
> NO_SRC_PORT, NO_DEST_PORT, 0,
> proto);
> }
> return (link);
1514,1518c1433,1437
< struct in_addr alias_addr,
< u_short dst_port,
< u_short alias_port,
< u_char proto,
< int create)
---
> struct in_addr alias_addr,
> u_short dst_port,
> u_short alias_port,
> u_char proto,
> int create)
1520,1521c1439,1440
< int link_type;
< struct alias_link *link;
---
> int link_type;
> struct alias_link *link;
1523,1534c1442,1452
< switch (proto)
< {
< case IPPROTO_UDP:
< link_type = LINK_UDP;
< break;
< case IPPROTO_TCP:
< link_type = LINK_TCP;
< break;
< default:
< return NULL;
< break;
< }
---
> switch (proto) {
> case IPPROTO_UDP:
> link_type = LINK_UDP;
> break;
> case IPPROTO_TCP:
> link_type = LINK_TCP;
> break;
> default:
> return NULL;
> break;
> }
1536,1538c1454,1456
< link = FindLinkIn(la, dst_addr, alias_addr,
< dst_port, alias_port,
< link_type, create);
---
> link = FindLinkIn(la, dst_addr, alias_addr,
> dst_port, alias_port,
> link_type, create);
1540,1542c1458,1459
< if (link == NULL && create && !(la->packetAliasMode & PKT_ALIAS_DENY_INCOMING))
< {
< struct in_addr target_addr;
---
> if (link == NULL && create && !(la->packetAliasMode & PKT_ALIAS_DENY_INCOMING)) {
> struct in_addr target_addr;
1544,1550c1461,1466
< target_addr = FindOriginalAddress(la, alias_addr);
< link = AddLink(la, target_addr, dst_addr, alias_addr,
< alias_port, dst_port, alias_port,
< link_type);
< }
<
< return(link);
---
> target_addr = FindOriginalAddress(la, alias_addr);
> link = AddLink(la, target_addr, dst_addr, alias_addr,
> alias_port, dst_port, alias_port,
> link_type);
> }
> return (link);
1555,1560c1471,1476
< FindUdpTcpOut(struct libalias *la, struct in_addr src_addr,
< struct in_addr dst_addr,
< u_short src_port,
< u_short dst_port,
< u_char proto,
< int create)
---
> FindUdpTcpOut(struct libalias *la, struct in_addr src_addr,
> struct in_addr dst_addr,
> u_short src_port,
> u_short dst_port,
> u_char proto,
> int create)
1562,1563c1478,1479
< int link_type;
< struct alias_link *link;
---
> int link_type;
> struct alias_link *link;
1565,1576c1481,1491
< switch (proto)
< {
< case IPPROTO_UDP:
< link_type = LINK_UDP;
< break;
< case IPPROTO_TCP:
< link_type = LINK_TCP;
< break;
< default:
< return NULL;
< break;
< }
---
> switch (proto) {
> case IPPROTO_UDP:
> link_type = LINK_UDP;
> break;
> case IPPROTO_TCP:
> link_type = LINK_TCP;
> break;
> default:
> return NULL;
> break;
> }
1578c1493
< link = FindLinkOut(la, src_addr, dst_addr, src_port, dst_port, link_type, create);
---
> link = FindLinkOut(la, src_addr, dst_addr, src_port, dst_port, link_type, create);
1580,1582c1495,1496
< if (link == NULL && create)
< {
< struct in_addr alias_addr;
---
> if (link == NULL && create) {
> struct in_addr alias_addr;
1584,1590c1498,1503
< alias_addr = FindAliasAddress(la, src_addr);
< link = AddLink(la, src_addr, dst_addr, alias_addr,
< src_port, dst_port, GET_ALIAS_PORT,
< link_type);
< }
<
< return(link);
---
> alias_addr = FindAliasAddress(la, src_addr);
> link = AddLink(la, src_addr, dst_addr, alias_addr,
> src_port, dst_port, GET_ALIAS_PORT,
> link_type);
> }
> return (link);
1595,1598c1508,1511
< AddPptp(struct libalias *la, struct in_addr src_addr,
< struct in_addr dst_addr,
< struct in_addr alias_addr,
< u_int16_t src_call_id)
---
> AddPptp(struct libalias *la, struct in_addr src_addr,
> struct in_addr dst_addr,
> struct in_addr alias_addr,
> u_int16_t src_call_id)
1600c1513
< struct alias_link *link;
---
> struct alias_link *link;
1602,1604c1515,1517
< link = AddLink(la, src_addr, dst_addr, alias_addr,
< src_call_id, 0, GET_ALIAS_PORT,
< LINK_PPTP);
---
> link = AddLink(la, src_addr, dst_addr, alias_addr,
> src_call_id, 0, GET_ALIAS_PORT,
> LINK_PPTP);
1606c1519
< return (link);
---
> return (link);
1612,1613c1525,1526
< struct in_addr dst_addr,
< u_int16_t src_call_id)
---
> struct in_addr dst_addr,
> u_int16_t src_call_id)
1615,1616c1528,1529
< u_int i;
< struct alias_link *link;
---
> u_int i;
> struct alias_link *link;
1618,1620c1531,1533
< i = StartPointOut(src_addr, dst_addr, 0, 0, LINK_PPTP);
< LIST_FOREACH(link, &la->linkTableOut[i], list_out)
< if (link->link_type == LINK_PPTP &&
---
> i = StartPointOut(src_addr, dst_addr, 0, 0, LINK_PPTP);
> LIST_FOREACH(link, &la->linkTableOut[i], list_out)
> if (link->link_type == LINK_PPTP &&
1626c1539
< return (link);
---
> return (link);
1632,1633c1545,1546
< struct in_addr dst_addr,
< u_int16_t dst_call_id)
---
> struct in_addr dst_addr,
> u_int16_t dst_call_id)
1635,1636c1548,1549
< u_int i;
< struct alias_link *link;
---
> u_int i;
> struct alias_link *link;
1638,1640c1551,1553
< i = StartPointOut(src_addr, dst_addr, 0, 0, LINK_PPTP);
< LIST_FOREACH(link, &la->linkTableOut[i], list_out)
< if (link->link_type == LINK_PPTP &&
---
> i = StartPointOut(src_addr, dst_addr, 0, 0, LINK_PPTP);
> LIST_FOREACH(link, &la->linkTableOut[i], list_out)
> if (link->link_type == LINK_PPTP &&
1646c1559
< return (link);
---
> return (link);
1652,1653c1565,1566
< struct in_addr alias_addr,
< u_int16_t dst_call_id)
---
> struct in_addr alias_addr,
> u_int16_t dst_call_id)
1655,1656c1568,1569
< u_int i;
< struct alias_link *link;
---
> u_int i;
> struct alias_link *link;
1658,1660c1571,1573
< i = StartPointIn(alias_addr, 0, LINK_PPTP);
< LIST_FOREACH(link, &la->linkTableIn[i], list_in)
< if (link->link_type == LINK_PPTP &&
---
> i = StartPointIn(alias_addr, 0, LINK_PPTP);
> LIST_FOREACH(link, &la->linkTableIn[i], list_in)
> if (link->link_type == LINK_PPTP &&
1666c1579
< return (link);
---
> return (link);
1672,1673c1585,1586
< struct in_addr alias_addr,
< u_int16_t alias_call_id)
---
> struct in_addr alias_addr,
> u_int16_t alias_call_id)
1675c1588
< struct alias_link *link;
---
> struct alias_link *link;
1677,1679c1590,1592
< link = FindLinkIn(la, dst_addr, alias_addr,
< 0/* any */, alias_call_id,
< LINK_PPTP, 0);
---
> link = FindLinkIn(la, dst_addr, alias_addr,
> 0 /* any */ , alias_call_id,
> LINK_PPTP, 0);
1682c1595
< return (link);
---
> return (link);
1687,1691c1600,1604
< FindRtspOut(struct libalias *la, struct in_addr src_addr,
< struct in_addr dst_addr,
< u_short src_port,
< u_short alias_port,
< u_char proto)
---
> FindRtspOut(struct libalias *la, struct in_addr src_addr,
> struct in_addr dst_addr,
> u_short src_port,
> u_short alias_port,
> u_char proto)
1693,1694c1606,1607
< int link_type;
< struct alias_link *link;
---
> int link_type;
> struct alias_link *link;
1696,1707c1609,1619
< switch (proto)
< {
< case IPPROTO_UDP:
< link_type = LINK_UDP;
< break;
< case IPPROTO_TCP:
< link_type = LINK_TCP;
< break;
< default:
< return NULL;
< break;
< }
---
> switch (proto) {
> case IPPROTO_UDP:
> link_type = LINK_UDP;
> break;
> case IPPROTO_TCP:
> link_type = LINK_TCP;
> break;
> default:
> return NULL;
> break;
> }
1709c1621
< link = FindLinkOut(la, src_addr, dst_addr, src_port, 0, link_type, 1);
---
> link = FindLinkOut(la, src_addr, dst_addr, src_port, 0, link_type, 1);
1711,1713c1623,1624
< if (link == NULL)
< {
< struct in_addr alias_addr;
---
> if (link == NULL) {
> struct in_addr alias_addr;
1715,1721c1626,1631
< alias_addr = FindAliasAddress(la, src_addr);
< link = AddLink(la, src_addr, dst_addr, alias_addr,
< src_port, 0, alias_port,
< link_type);
< }
<
< return(link);
---
> alias_addr = FindAliasAddress(la, src_addr);
> link = AddLink(la, src_addr, dst_addr, alias_addr,
> src_port, 0, alias_port,
> link_type);
> }
> return (link);
1728c1638
< struct alias_link *link;
---
> struct alias_link *link;
1730,1746c1640,1653
< link = FindLinkIn(la, la->nullAddress, alias_addr,
< 0, 0, LINK_ADDR, 0);
< if (link == NULL)
< {
< la->newDefaultLink = 1;
< if (la->targetAddress.s_addr == INADDR_ANY)
< return alias_addr;
< else if (la->targetAddress.s_addr == INADDR_NONE)
< return (la->aliasAddress.s_addr != INADDR_ANY) ?
< la->aliasAddress : alias_addr;
< else
< return la->targetAddress;
< }
< else
< {
< if (link->server != NULL) { /* LSNAT link */
< struct in_addr src_addr;
---
> link = FindLinkIn(la, la->nullAddress, alias_addr,
> 0, 0, LINK_ADDR, 0);
> if (link == NULL) {
> la->newDefaultLink = 1;
> if (la->targetAddress.s_addr == INADDR_ANY)
> return alias_addr;
> else if (la->targetAddress.s_addr == INADDR_NONE)
> return (la->aliasAddress.s_addr != INADDR_ANY) ?
> la->aliasAddress : alias_addr;
> else
> return la->targetAddress;
> } else {
> if (link->server != NULL) { /* LSNAT link */
> struct in_addr src_addr;
1748,1756c1655,1663
< src_addr = link->server->addr;
< link->server = link->server->next;
< return (src_addr);
< } else if (link->src_addr.s_addr == INADDR_ANY)
< return (la->aliasAddress.s_addr != INADDR_ANY) ?
< la->aliasAddress : alias_addr;
< else
< return link->src_addr;
< }
---
> src_addr = link->server->addr;
> link->server = link->server->next;
> return (src_addr);
> } else if (link->src_addr.s_addr == INADDR_ANY)
> return (la->aliasAddress.s_addr != INADDR_ANY) ?
> la->aliasAddress : alias_addr;
> else
> return link->src_addr;
> }
1763c1670
< struct alias_link *link;
---
> struct alias_link *link;
1765,1779c1672,1683
< link = FindLinkOut(la, original_addr, la->nullAddress,
< 0, 0, LINK_ADDR, 0);
< if (link == NULL)
< {
< return (la->aliasAddress.s_addr != INADDR_ANY) ?
< la->aliasAddress : original_addr;
< }
< else
< {
< if (link->alias_addr.s_addr == INADDR_ANY)
< return (la->aliasAddress.s_addr != INADDR_ANY) ?
< la->aliasAddress : original_addr;
< else
< return link->alias_addr;
< }
---
> link = FindLinkOut(la, original_addr, la->nullAddress,
> 0, 0, LINK_ADDR, 0);
> if (link == NULL) {
> return (la->aliasAddress.s_addr != INADDR_ANY) ?
> la->aliasAddress : original_addr;
> } else {
> if (link->alias_addr.s_addr == INADDR_ANY)
> return (la->aliasAddress.s_addr != INADDR_ANY) ?
> la->aliasAddress : original_addr;
> else
> return link->alias_addr;
> }
1801c1705
< link->data.frag_addr = src_addr;
---
> link->data.frag_addr = src_addr;
1808c1712
< *src_addr = link->data.frag_addr;
---
> *src_addr = link->data.frag_addr;
1815c1719
< link->data.frag_ptr = fptr;
---
> link->data.frag_ptr = fptr;
1822c1726
< *fptr = link->data.frag_ptr;
---
> *fptr = link->data.frag_ptr;
1829,1844c1733,1748
< /* TCP input state */
< switch (state) {
< case ALIAS_TCP_STATE_DISCONNECTED:
< if (link->data.tcp->state.out != ALIAS_TCP_STATE_CONNECTED)
< link->expire_time = TCP_EXPIRE_DEAD;
< else
< link->expire_time = TCP_EXPIRE_SINGLEDEAD;
< break;
< case ALIAS_TCP_STATE_CONNECTED:
< if (link->data.tcp->state.out == ALIAS_TCP_STATE_CONNECTED)
< link->expire_time = TCP_EXPIRE_CONNECTED;
< break;
< default:
< abort();
< }
< link->data.tcp->state.in = state;
---
> /* TCP input state */
> switch (state) {
> case ALIAS_TCP_STATE_DISCONNECTED:
> if (link->data.tcp->state.out != ALIAS_TCP_STATE_CONNECTED)
> link->expire_time = TCP_EXPIRE_DEAD;
> else
> link->expire_time = TCP_EXPIRE_SINGLEDEAD;
> break;
> case ALIAS_TCP_STATE_CONNECTED:
> if (link->data.tcp->state.out == ALIAS_TCP_STATE_CONNECTED)
> link->expire_time = TCP_EXPIRE_CONNECTED;
> break;
> default:
> abort();
> }
> link->data.tcp->state.in = state;
1851,1866c1755,1770
< /* TCP output state */
< switch (state) {
< case ALIAS_TCP_STATE_DISCONNECTED:
< if (link->data.tcp->state.in != ALIAS_TCP_STATE_CONNECTED)
< link->expire_time = TCP_EXPIRE_DEAD;
< else
< link->expire_time = TCP_EXPIRE_SINGLEDEAD;
< break;
< case ALIAS_TCP_STATE_CONNECTED:
< if (link->data.tcp->state.in == ALIAS_TCP_STATE_CONNECTED)
< link->expire_time = TCP_EXPIRE_CONNECTED;
< break;
< default:
< abort();
< }
< link->data.tcp->state.out = state;
---
> /* TCP output state */
> switch (state) {
> case ALIAS_TCP_STATE_DISCONNECTED:
> if (link->data.tcp->state.in != ALIAS_TCP_STATE_CONNECTED)
> link->expire_time = TCP_EXPIRE_DEAD;
> else
> link->expire_time = TCP_EXPIRE_SINGLEDEAD;
> break;
> case ALIAS_TCP_STATE_CONNECTED:
> if (link->data.tcp->state.in == ALIAS_TCP_STATE_CONNECTED)
> link->expire_time = TCP_EXPIRE_CONNECTED;
> break;
> default:
> abort();
> }
> link->data.tcp->state.out = state;
1873,1874c1777,1778
< /* TCP input state */
< return link->data.tcp->state.in;
---
> /* TCP input state */
> return link->data.tcp->state.in;
1881,1882c1785,1786
< /* TCP output state */
< return link->data.tcp->state.out;
---
> /* TCP output state */
> return link->data.tcp->state.out;
1889,1892c1793,1796
< if (link->src_addr.s_addr == INADDR_ANY)
< return link->la->aliasAddress;
< else
< return(link->src_addr);
---
> if (link->src_addr.s_addr == INADDR_ANY)
> return link->la->aliasAddress;
> else
> return (link->src_addr);
1899c1803
< return(link->dst_addr);
---
> return (link->dst_addr);
1906,1909c1810,1813
< if (link->alias_addr.s_addr == INADDR_ANY)
< return link->la->aliasAddress;
< else
< return link->alias_addr;
---
> if (link->alias_addr.s_addr == INADDR_ANY)
> return link->la->aliasAddress;
> else
> return link->alias_addr;
1916c1820
< return la->aliasAddress;
---
> return la->aliasAddress;
1923c1827
< la->aliasAddress = alias_addr;
---
> la->aliasAddress = alias_addr;
1930c1834
< return(link->src_port);
---
> return (link->src_port);
1937c1841
< return(link->alias_port);
---
> return (link->alias_port);
1941c1845
< static u_short
---
> static u_short
1944c1848
< return(link->dst_port);
---
> return (link->dst_port);
1945a1850
>
1952c1857
< link->data.tcp->state.ack_modified = 1;
---
> link->data.tcp->state.ack_modified = 1;
1959c1864
< return link->proxy_addr;
---
> return link->proxy_addr;
1966c1871
< link->proxy_addr = addr;
---
> link->proxy_addr = addr;
1973c1878
< return link->proxy_port;
---
> return link->proxy_port;
1980c1885
< link->proxy_port = port;
---
> link->proxy_port = port;
1988c1893
< return link->data.tcp->state.ack_modified;
---
> return link->data.tcp->state.ack_modified;
2001,2004c1906,1909
< int i;
< struct tcphdr *tc;
< int delta, ack_diff_min;
< u_long ack;
---
> int i;
> struct tcphdr *tc;
> int delta, ack_diff_min;
> u_long ack;
2006,2007c1911,1912
< tc = (struct tcphdr *) ((char *) pip + (pip->ip_hl << 2));
< ack = tc->th_ack;
---
> tc = (struct tcphdr *)((char *)pip + (pip->ip_hl << 2));
> ack = tc->th_ack;
2009,2013c1914,1917
< delta = 0;
< ack_diff_min = -1;
< for (i=0; i<N_LINK_TCP_DATA; i++)
< {
< struct ack_data_record x;
---
> delta = 0;
> ack_diff_min = -1;
> for (i = 0; i < N_LINK_TCP_DATA; i++) {
> struct ack_data_record x;
2015,2018c1919,1921
< x = link->data.tcp->ack[i];
< if (x.active == 1)
< {
< int ack_diff;
---
> x = link->data.tcp->ack[i];
> if (x.active == 1) {
> int ack_diff;
2020,2039c1923,1937
< ack_diff = SeqDiff(x.ack_new, ack);
< if (ack_diff >= 0)
< {
< if (ack_diff_min >= 0)
< {
< if (ack_diff < ack_diff_min)
< {
< delta = x.delta;
< ack_diff_min = ack_diff;
< }
< }
< else
< {
< delta = x.delta;
< ack_diff_min = ack_diff;
< }
< }
< }
< }
< return (delta);
---
> ack_diff = SeqDiff(x.ack_new, ack);
> if (ack_diff >= 0) {
> if (ack_diff_min >= 0) {
> if (ack_diff < ack_diff_min) {
> delta = x.delta;
> ack_diff_min = ack_diff;
> }
> } else {
> delta = x.delta;
> ack_diff_min = ack_diff;
> }
> }
> }
> }
> return (delta);
2052,2055c1950,1953
< int i;
< struct tcphdr *tc;
< int delta, seq_diff_min;
< u_long seq;
---
> int i;
> struct tcphdr *tc;
> int delta, seq_diff_min;
> u_long seq;
2057,2058c1955,1956
< tc = (struct tcphdr *) ((char *) pip + (pip->ip_hl << 2));
< seq = tc->th_seq;
---
> tc = (struct tcphdr *)((char *)pip + (pip->ip_hl << 2));
> seq = tc->th_seq;
2060,2064c1958,1961
< delta = 0;
< seq_diff_min = -1;
< for (i=0; i<N_LINK_TCP_DATA; i++)
< {
< struct ack_data_record x;
---
> delta = 0;
> seq_diff_min = -1;
> for (i = 0; i < N_LINK_TCP_DATA; i++) {
> struct ack_data_record x;
2066,2069c1963,1965
< x = link->data.tcp->ack[i];
< if (x.active == 1)
< {
< int seq_diff;
---
> x = link->data.tcp->ack[i];
> if (x.active == 1) {
> int seq_diff;
2071,2090c1967,1981
< seq_diff = SeqDiff(x.ack_old, seq);
< if (seq_diff >= 0)
< {
< if (seq_diff_min >= 0)
< {
< if (seq_diff < seq_diff_min)
< {
< delta = x.delta;
< seq_diff_min = seq_diff;
< }
< }
< else
< {
< delta = x.delta;
< seq_diff_min = seq_diff;
< }
< }
< }
< }
< return (delta);
---
> seq_diff = SeqDiff(x.ack_old, seq);
> if (seq_diff >= 0) {
> if (seq_diff_min >= 0) {
> if (seq_diff < seq_diff_min) {
> delta = x.delta;
> seq_diff_min = seq_diff;
> }
> } else {
> delta = x.delta;
> seq_diff_min = seq_diff;
> }
> }
> }
> }
> return (delta);
2103,2106c1994,1997
< struct tcphdr *tc;
< struct ack_data_record x;
< int hlen, tlen, dlen;
< int i;
---
> struct tcphdr *tc;
> struct ack_data_record x;
> int hlen, tlen, dlen;
> int i;
2108c1999
< tc = (struct tcphdr *) ((char *) pip + (pip->ip_hl << 2));
---
> tc = (struct tcphdr *)((char *)pip + (pip->ip_hl << 2));
2110,2112c2001,2003
< hlen = (pip->ip_hl + tc->th_off) << 2;
< tlen = ntohs(pip->ip_len);
< dlen = tlen - hlen;
---
> hlen = (pip->ip_hl + tc->th_off) << 2;
> tlen = ntohs(pip->ip_len);
> dlen = tlen - hlen;
2114,2117c2005,2008
< x.ack_old = htonl(ntohl(tc->th_seq) + dlen);
< x.ack_new = htonl(ntohl(tc->th_seq) + dlen + delta);
< x.delta = delta;
< x.active = 1;
---
> x.ack_old = htonl(ntohl(tc->th_seq) + dlen);
> x.ack_new = htonl(ntohl(tc->th_seq) + dlen + delta);
> x.delta = delta;
> x.active = 1;
2119,2120c2010,2011
< i = link->data.tcp->state.index;
< link->data.tcp->ack[i] = x;
---
> i = link->data.tcp->state.index;
> link->data.tcp->ack[i] = x;
2122,2126c2013,2017
< i++;
< if (i == N_LINK_TCP_DATA)
< link->data.tcp->state.index = 0;
< else
< link->data.tcp->state.index = i;
---
> i++;
> if (i == N_LINK_TCP_DATA)
> link->data.tcp->state.index = 0;
> else
> link->data.tcp->state.index = i;
2132,2146c2023,2030
< if (expire == 0)
< {
< link->flags &= ~LINK_PERMANENT;
< DeleteLink(link);
< }
< else if (expire == -1)
< {
< link->flags |= LINK_PERMANENT;
< }
< else if (expire > 0)
< {
< link->expire_time = expire;
< }
< else
< {
---
> if (expire == 0) {
> link->flags &= ~LINK_PERMANENT;
> DeleteLink(link);
> } else if (expire == -1) {
> link->flags |= LINK_PERMANENT;
> } else if (expire > 0) {
> link->expire_time = expire;
> } else {
2148,2149c2032,2033
< fprintf(stderr, "PacketAlias/SetExpire(): ");
< fprintf(stderr, "error in expire parameter\n");
---
> fprintf(stderr, "PacketAlias/SetExpire(): ");
> fprintf(stderr, "error in expire parameter\n");
2151c2035
< }
---
> }
2157c2041
< la->newDefaultLink = 0;
---
> la->newDefaultLink = 0;
2164c2048
< link->pflags = pflags;;
---
> link->pflags = pflags;;
2171c2055
< return (link->pflags);
---
> return (link->pflags);
2177c2061
< struct libalias *la = link->la;
---
> struct libalias *la = link->la;
2179,2182c2063,2066
< la->deleteAllLinks = 1;
< link = ReLink(link, link->src_addr, link->dst_addr, link->alias_addr,
< link->src_port, cid, link->alias_port, link->link_type);
< la->deleteAllLinks = 0;
---
> la->deleteAllLinks = 1;
> link = ReLink(link, link->src_addr, link->dst_addr, link->alias_addr,
> link->src_port, cid, link->alias_port, link->link_type);
> la->deleteAllLinks = 0;
2205,2207c2089,2091
< int i, n, n100;
< struct timeval tv;
< struct timezone tz;
---
> int i, n, n100;
> struct timeval tv;
> struct timezone tz;
2209,2215c2093,2099
< /*
< * Save system time (seconds) in global variable timeStamp for
< * use by other functions. This is done so as not to unnecessarily
< * waste timeline by making system calls.
< */
< gettimeofday(&tv, &tz);
< la->timeStamp = tv.tv_sec;
---
> /*
> * Save system time (seconds) in global variable timeStamp for use
> * by other functions. This is done so as not to unnecessarily
> * waste timeline by making system calls.
> */
> gettimeofday(&tv, &tz);
> la->timeStamp = tv.tv_sec;
2217,2220c2101,2104
< /* Compute number of spokes (output table link chains) to cover */
< n100 = LINK_TABLE_OUT_SIZE * 100 + la->houseKeepingResidual;
< n100 *= la->timeStamp - la->lastCleanupTime;
< n100 /= ALIAS_CLEANUP_INTERVAL_SECS;
---
> /* Compute number of spokes (output table link chains) to cover */
> n100 = LINK_TABLE_OUT_SIZE * 100 + la->houseKeepingResidual;
> n100 *= la->timeStamp - la->lastCleanupTime;
> n100 /= ALIAS_CLEANUP_INTERVAL_SECS;
2222c2106
< n = n100/100;
---
> n = n100 / 100;
2224,2229c2108,2112
< /* Handle different cases */
< if (n > ALIAS_CLEANUP_MAX_SPOKES)
< {
< n = ALIAS_CLEANUP_MAX_SPOKES;
< la->lastCleanupTime = la->timeStamp;
< la->houseKeepingResidual = 0;
---
> /* Handle different cases */
> if (n > ALIAS_CLEANUP_MAX_SPOKES) {
> n = ALIAS_CLEANUP_MAX_SPOKES;
> la->lastCleanupTime = la->timeStamp;
> la->houseKeepingResidual = 0;
2231,2237c2114,2118
< for (i=0; i<n; i++)
< IncrementalCleanup(la);
< }
< else if (n > 0)
< {
< la->lastCleanupTime = la->timeStamp;
< la->houseKeepingResidual = n100 - 100*n;
---
> for (i = 0; i < n; i++)
> IncrementalCleanup(la);
> } else if (n > 0) {
> la->lastCleanupTime = la->timeStamp;
> la->houseKeepingResidual = n100 - 100 * n;
2239,2243c2120,2122
< for (i=0; i<n; i++)
< IncrementalCleanup(la);
< }
< else if (n < 0)
< {
---
> for (i = 0; i < n; i++)
> IncrementalCleanup(la);
> } else if (n < 0) {
2245,2246c2124,2125
< fprintf(stderr, "PacketAlias/HouseKeeping(): ");
< fprintf(stderr, "something unexpected in time values\n");
---
> fprintf(stderr, "PacketAlias/HouseKeeping(): ");
> fprintf(stderr, "something unexpected in time values\n");
2248,2250c2127,2129
< la->lastCleanupTime = la->timeStamp;
< la->houseKeepingResidual = 0;
< }
---
> la->lastCleanupTime = la->timeStamp;
> la->houseKeepingResidual = 0;
> }
2258,2264c2137,2142
< if ((~la->packetAliasMode & PKT_ALIAS_LOG)
< && (la->monitorFile = fopen("/var/log/alias.log", "w")))
< {
< la->packetAliasMode |= PKT_ALIAS_LOG;
< fprintf(la->monitorFile,
< "PacketAlias/InitPacketAliasLog: Packet alias logging enabled.\n");
< }
---
> if ((~la->packetAliasMode & PKT_ALIAS_LOG)
> && (la->monitorFile = fopen("/var/log/alias.log", "w"))) {
> la->packetAliasMode |= PKT_ALIAS_LOG;
> fprintf(la->monitorFile,
> "PacketAlias/InitPacketAliasLog: Packet alias logging enabled.\n");
> }
2272,2276c2150,2154
< if (la->monitorFile) {
< fclose(la->monitorFile);
< la->monitorFile = NULL;
< }
< la->packetAliasMode &= ~PKT_ALIAS_LOG;
---
> if (la->monitorFile) {
> fclose(la->monitorFile);
> la->monitorFile = NULL;
> }
> la->packetAliasMode &= ~PKT_ALIAS_LOG;
2305,2308c2183,2186
< LibAliasRedirectPort(struct libalias *la, struct in_addr src_addr, u_short src_port,
< struct in_addr dst_addr, u_short dst_port,
< struct in_addr alias_addr, u_short alias_port,
< u_char proto)
---
> LibAliasRedirectPort(struct libalias *la, struct in_addr src_addr, u_short src_port,
> struct in_addr dst_addr, u_short dst_port,
> struct in_addr alias_addr, u_short alias_port,
> u_char proto)
2310,2311c2188,2189
< int link_type;
< struct alias_link *link;
---
> int link_type;
> struct alias_link *link;
2313,2321c2191,2198
< switch(proto)
< {
< case IPPROTO_UDP:
< link_type = LINK_UDP;
< break;
< case IPPROTO_TCP:
< link_type = LINK_TCP;
< break;
< default:
---
> switch (proto) {
> case IPPROTO_UDP:
> link_type = LINK_UDP;
> break;
> case IPPROTO_TCP:
> link_type = LINK_TCP;
> break;
> default:
2323,2324c2200,2201
< fprintf(stderr, "PacketAliasRedirectPort(): ");
< fprintf(stderr, "only TCP and UDP protocols allowed\n");
---
> fprintf(stderr, "PacketAliasRedirectPort(): ");
> fprintf(stderr, "only TCP and UDP protocols allowed\n");
2326,2327c2203,2204
< return NULL;
< }
---
> return NULL;
> }
2329,2331c2206,2208
< link = AddLink(la, src_addr, dst_addr, alias_addr,
< src_port, dst_port, alias_port,
< link_type);
---
> link = AddLink(la, src_addr, dst_addr, alias_addr,
> src_port, dst_port, alias_port,
> link_type);
2333,2336c2210,2212
< if (link != NULL)
< {
< link->flags |= LINK_PERMANENT;
< }
---
> if (link != NULL) {
> link->flags |= LINK_PERMANENT;
> }
2338,2342c2214,2217
< else
< {
< fprintf(stderr, "PacketAliasRedirectPort(): "
< "call to AddLink() failed\n");
< }
---
> else {
> fprintf(stderr, "PacketAliasRedirectPort(): "
> "call to AddLink() failed\n");
> }
2345c2220
< return link;
---
> return link;
2352c2227
< struct server *server;
---
> struct server *server;
2354c2229
< server = malloc(sizeof(struct server));
---
> server = malloc(sizeof(struct server));
2356,2357c2231,2232
< if (server != NULL) {
< struct server *head;
---
> if (server != NULL) {
> struct server *head;
2359,2360c2234,2235
< server->addr = addr;
< server->port = port;
---
> server->addr = addr;
> server->port = port;
2362,2366c2237,2241
< head = link->server;
< if (head == NULL)
< server->next = server;
< else {
< struct server *s;
---
> head = link->server;
> if (head == NULL)
> server->next = server;
> else {
> struct server *s;
2368,2375c2243,2250
< for (s = head; s->next != head; s = s->next);
< s->next = server;
< server->next = head;
< }
< link->server = server;
< return (0);
< } else
< return (-1);
---
> for (s = head; s->next != head; s = s->next);
> s->next = server;
> server->next = head;
> }
> link->server = server;
> return (0);
> } else
> return (-1);
2382,2384c2257,2259
< struct in_addr dst_addr,
< struct in_addr alias_addr,
< u_char proto)
---
> struct in_addr dst_addr,
> struct in_addr alias_addr,
> u_char proto)
2386c2261
< struct alias_link *link;
---
> struct alias_link *link;
2388,2390c2263,2265
< link = AddLink(la, src_addr, dst_addr, alias_addr,
< NO_SRC_PORT, NO_DEST_PORT, 0,
< proto);
---
> link = AddLink(la, src_addr, dst_addr, alias_addr,
> NO_SRC_PORT, NO_DEST_PORT, 0,
> proto);
2392,2395c2267,2269
< if (link != NULL)
< {
< link->flags |= LINK_PERMANENT;
< }
---
> if (link != NULL) {
> link->flags |= LINK_PERMANENT;
> }
2397,2401c2271,2274
< else
< {
< fprintf(stderr, "PacketAliasRedirectProto(): "
< "call to AddLink() failed\n");
< }
---
> else {
> fprintf(stderr, "PacketAliasRedirectProto(): "
> "call to AddLink() failed\n");
> }
2404c2277
< return link;
---
> return link;
2410c2283
< struct in_addr alias_addr)
---
> struct in_addr alias_addr)
2412c2285
< struct alias_link *link;
---
> struct alias_link *link;
2414,2416c2287,2289
< link = AddLink(la, src_addr, la->nullAddress, alias_addr,
< 0, 0, 0,
< LINK_ADDR);
---
> link = AddLink(la, src_addr, la->nullAddress, alias_addr,
> 0, 0, 0,
> LINK_ADDR);
2418,2421c2291,2293
< if (link != NULL)
< {
< link->flags |= LINK_PERMANENT;
< }
---
> if (link != NULL) {
> link->flags |= LINK_PERMANENT;
> }
2423,2427c2295,2298
< else
< {
< fprintf(stderr, "PacketAliasRedirectAddr(): "
< "call to AddLink() failed\n");
< }
---
> else {
> fprintf(stderr, "PacketAliasRedirectAddr(): "
> "call to AddLink() failed\n");
> }
2430c2301
< return link;
---
> return link;
2439,2444c2310,2315
< if (link->flags & LINK_PARTIALLY_SPECIFIED)
< return (-1);
< else {
< link->flags &= ~LINK_PERMANENT;
< return (0);
< }
---
> if (link->flags & LINK_PARTIALLY_SPECIFIED)
> return (-1);
> else {
> link->flags &= ~LINK_PERMANENT;
> return (0);
> }
2454,2456c2325,2327
< la->deleteAllLinks = 1;
< DeleteLink(link);
< la->deleteAllLinks = 0;
---
> la->deleteAllLinks = 1;
> DeleteLink(link);
> la->deleteAllLinks = 0;
2463,2465c2334,2336
< if (la->packetAliasMode & PKT_ALIAS_RESET_ON_ADDR_CHANGE
< && la->aliasAddress.s_addr != addr.s_addr)
< CleanupAliasData(la);
---
> if (la->packetAliasMode & PKT_ALIAS_RESET_ON_ADDR_CHANGE
> && la->aliasAddress.s_addr != addr.s_addr)
> CleanupAliasData(la);
2467c2338
< la->aliasAddress = addr;
---
> la->aliasAddress = addr;
2474c2345
< la->targetAddress = target_addr;
---
> la->targetAddress = target_addr;
2481c2352
< while(!LIST_EMPTY(&instancehead))
---
> while (!LIST_EMPTY(&instancehead))
2488,2490c2359,2361
< int i;
< struct timeval tv;
< struct timezone tz;
---
> int i;
> struct timeval tv;
> struct timezone tz;
2492,2504c2363,2369
< if (la == NULL)
< {
< la = calloc(sizeof *la, 1);
< if (la == NULL)
< return (la);
< if (LIST_EMPTY(&instancehead))
< atexit(finishoff);
< LIST_INSERT_HEAD(&instancehead, la, instancelist);
<
< gettimeofday(&tv, &tz);
< la->timeStamp = tv.tv_sec;
< la->lastCleanupTime = tv.tv_sec;
< la->houseKeepingResidual = 0;
---
> if (la == NULL) {
> la = calloc(sizeof *la, 1);
> if (la == NULL)
> return (la);
> if (LIST_EMPTY(&instancehead))
> atexit(finishoff);
> LIST_INSERT_HEAD(&instancehead, la, instancelist);
2506,2509c2371,2374
< for (i=0; i<LINK_TABLE_OUT_SIZE; i++)
< LIST_INIT(&la->linkTableOut[i]);
< for (i=0; i<LINK_TABLE_IN_SIZE; i++)
< LIST_INIT(&la->linkTableIn[i]);
---
> gettimeofday(&tv, &tz);
> la->timeStamp = tv.tv_sec;
> la->lastCleanupTime = tv.tv_sec;
> la->houseKeepingResidual = 0;
2511,2517c2376,2379
< }
< else
< {
< la->deleteAllLinks = 1;
< CleanupAliasData(la);
< la->deleteAllLinks = 0;
< }
---
> for (i = 0; i < LINK_TABLE_OUT_SIZE; i++)
> LIST_INIT(&la->linkTableOut[i]);
> for (i = 0; i < LINK_TABLE_IN_SIZE; i++)
> LIST_INIT(&la->linkTableIn[i]);
2519,2520c2381,2385
< la->aliasAddress.s_addr = INADDR_ANY;
< la->targetAddress.s_addr = INADDR_ANY;
---
> } else {
> la->deleteAllLinks = 1;
> CleanupAliasData(la);
> la->deleteAllLinks = 0;
> }
2522,2529c2387,2388
< la->icmpLinkCount = 0;
< la->udpLinkCount = 0;
< la->tcpLinkCount = 0;
< la->pptpLinkCount = 0;
< la->protoLinkCount = 0;
< la->fragmentIdLinkCount = 0;
< la->fragmentPtrLinkCount = 0;
< la->sockCount = 0;
---
> la->aliasAddress.s_addr = INADDR_ANY;
> la->targetAddress.s_addr = INADDR_ANY;
2531c2390,2397
< la->cleanupIndex =0;
---
> la->icmpLinkCount = 0;
> la->udpLinkCount = 0;
> la->tcpLinkCount = 0;
> la->pptpLinkCount = 0;
> la->protoLinkCount = 0;
> la->fragmentIdLinkCount = 0;
> la->fragmentPtrLinkCount = 0;
> la->sockCount = 0;
2533,2535c2399,2403
< la->packetAliasMode = PKT_ALIAS_SAME_PORTS
< | PKT_ALIAS_USE_SOCKETS
< | PKT_ALIAS_RESET_ON_ADDR_CHANGE;
---
> la->cleanupIndex = 0;
>
> la->packetAliasMode = PKT_ALIAS_SAME_PORTS
> | PKT_ALIAS_USE_SOCKETS
> | PKT_ALIAS_RESET_ON_ADDR_CHANGE;
2537c2405
< la->fireWallFD = -1;
---
> la->fireWallFD = -1;
2539c2407
< return (la);
---
> return (la);
2543,2547c2411,2416
< LibAliasUninit(struct libalias *la) {
< la->deleteAllLinks = 1;
< CleanupAliasData(la);
< la->deleteAllLinks = 0;
< UninitPacketAliasLog(la);
---
> LibAliasUninit(struct libalias *la)
> {
> la->deleteAllLinks = 1;
> CleanupAliasData(la);
> la->deleteAllLinks = 0;
> UninitPacketAliasLog(la);
2549c2418
< UninitPunchFW(la);
---
> UninitPunchFW(la);
2551,2552c2420,2421
< LIST_REMOVE(la, instancelist);
< free(la);
---
> LIST_REMOVE(la, instancelist);
> free(la);
2559,2561c2428,2430
< unsigned int flags, /* Which state to bring flags to */
< unsigned int mask /* Mask of which flags to affect (use 0 to do a
< probe for flag values) */
---
> unsigned int flags, /* Which state to bring flags to */
> unsigned int mask /* Mask of which flags to affect (use 0 to
> * do a probe for flag values) */
2565,2568c2434,2436
< if (flags & mask & PKT_ALIAS_LOG)
< {
< InitPacketAliasLog(la); /* Do the enable */
< } else
---
> if (flags & mask & PKT_ALIAS_LOG) {
> InitPacketAliasLog(la); /* Do the enable */
> } else
2570,2573c2438,2440
< if (~flags & mask & PKT_ALIAS_LOG) {
< UninitPacketAliasLog(la);
< }
<
---
> if (~flags & mask & PKT_ALIAS_LOG) {
> UninitPacketAliasLog(la);
> }
2576,2578c2443,2445
< if (flags & mask & PKT_ALIAS_PUNCH_FW) {
< InitPunchFW(la);
< } else
---
> if (flags & mask & PKT_ALIAS_PUNCH_FW) {
> InitPunchFW(la);
> } else
2580,2582c2447,2449
< if (~flags & mask & PKT_ALIAS_PUNCH_FW) {
< UninitPunchFW(la);
< }
---
> if (~flags & mask & PKT_ALIAS_PUNCH_FW) {
> UninitPunchFW(la);
> }
2586,2587c2453,2454
< la->packetAliasMode = (flags & mask) | (la->packetAliasMode & ~mask);
< return la->packetAliasMode;
---
> la->packetAliasMode = (flags & mask) | (la->packetAliasMode & ~mask);
> return la->packetAliasMode;
2594c2461
< return la->newDefaultLink;
---
> return la->newDefaultLink;
2606c2473
< #define IPFW2 1 /* use new ipfw code */
---
> #define IPFW2 1 /* use new ipfw code */
2615c2482
< #if IPFW2 /* support for new firewall code */
---
> #if IPFW2 /* support for new firewall code */
2622c2489
< next_cmd(ipfw_insn *cmd)
---
> next_cmd(ipfw_insn * cmd)
2624,2626c2491,2493
< cmd += F_LEN(cmd);
< bzero(cmd, sizeof(*cmd));
< return cmd;
---
> cmd += F_LEN(cmd);
> bzero(cmd, sizeof(*cmd));
> return cmd;
2634,2635c2501,2502
< fill_cmd(ipfw_insn *cmd, enum ipfw_opcodes opcode, int size,
< int flags, u_int16_t arg)
---
> fill_cmd(ipfw_insn * cmd, enum ipfw_opcodes opcode, int size,
> int flags, u_int16_t arg)
2637,2640c2504,2507
< cmd->opcode = opcode;
< cmd->len = ((cmd->len | flags) & (F_NOT | F_OR)) | (size & F_LEN_MASK);
< cmd->arg1 = arg;
< return next_cmd(cmd);
---
> cmd->opcode = opcode;
> cmd->len = ((cmd->len | flags) & (F_NOT | F_OR)) | (size & F_LEN_MASK);
> cmd->arg1 = arg;
> return next_cmd(cmd);
2644c2511
< fill_ip(ipfw_insn *cmd1, enum ipfw_opcodes opcode, u_int32_t addr)
---
> fill_ip(ipfw_insn * cmd1, enum ipfw_opcodes opcode, u_int32_t addr)
2646c2513
< ipfw_insn_ip *cmd = (ipfw_insn_ip *)cmd1;
---
> ipfw_insn_ip *cmd = (ipfw_insn_ip *) cmd1;
2648,2649c2515,2516
< cmd->addr.s_addr = addr;
< return fill_cmd(cmd1, opcode, F_INSN_SIZE(ipfw_insn_u32), 0, 0);
---
> cmd->addr.s_addr = addr;
> return fill_cmd(cmd1, opcode, F_INSN_SIZE(ipfw_insn_u32), 0, 0);
2653c2520
< fill_one_port(ipfw_insn *cmd1, enum ipfw_opcodes opcode, u_int16_t port)
---
> fill_one_port(ipfw_insn * cmd1, enum ipfw_opcodes opcode, u_int16_t port)
2655c2522
< ipfw_insn_u16 *cmd = (ipfw_insn_u16 *)cmd1;
---
> ipfw_insn_u16 *cmd = (ipfw_insn_u16 *) cmd1;
2657,2658c2524,2525
< cmd->ports[0] = cmd->ports[1] = port;
< return fill_cmd(cmd1, opcode, F_INSN_SIZE(ipfw_insn_u16), 0, 0);
---
> cmd->ports[0] = cmd->ports[1] = port;
> return fill_cmd(cmd1, opcode, F_INSN_SIZE(ipfw_insn_u16), 0, 0);
2663,2664c2530,2531
< enum ipfw_opcodes action, int proto,
< struct in_addr sa, u_int16_t sp, struct in_addr da, u_int16_t dp)
---
> enum ipfw_opcodes action, int proto,
> struct in_addr sa, u_int16_t sp, struct in_addr da, u_int16_t dp)
2666,2667c2533,2534
< struct ip_fw *rule = (struct ip_fw *)buf;
< ipfw_insn *cmd = (ipfw_insn *)rule->cmd;
---
> struct ip_fw *rule = (struct ip_fw *)buf;
> ipfw_insn *cmd = (ipfw_insn *) rule->cmd;
2669,2670c2536,2537
< bzero(buf, bufsize);
< rule->rulenum = rulenum;
---
> bzero(buf, bufsize);
> rule->rulenum = rulenum;
2672,2676c2539,2543
< cmd = fill_cmd(cmd, O_PROTO, F_INSN_SIZE(ipfw_insn), 0, proto);
< cmd = fill_ip(cmd, O_IP_SRC, sa.s_addr);
< cmd = fill_one_port(cmd, O_IP_SRCPORT, sp);
< cmd = fill_ip(cmd, O_IP_DST, da.s_addr);
< cmd = fill_one_port(cmd, O_IP_DSTPORT, dp);
---
> cmd = fill_cmd(cmd, O_PROTO, F_INSN_SIZE(ipfw_insn), 0, proto);
> cmd = fill_ip(cmd, O_IP_SRC, sa.s_addr);
> cmd = fill_one_port(cmd, O_IP_SRCPORT, sp);
> cmd = fill_ip(cmd, O_IP_DST, da.s_addr);
> cmd = fill_one_port(cmd, O_IP_DSTPORT, dp);
2678,2679c2545,2546
< rule->act_ofs = (u_int32_t *)cmd - (u_int32_t *)rule->cmd;
< cmd = fill_cmd(cmd, action, F_INSN_SIZE(ipfw_insn), 0, 0);
---
> rule->act_ofs = (u_int32_t *) cmd - (u_int32_t *) rule->cmd;
> cmd = fill_cmd(cmd, action, F_INSN_SIZE(ipfw_insn), 0, 0);
2681c2548
< rule->cmd_len = (u_int32_t *)cmd - (u_int32_t *)rule->cmd;
---
> rule->cmd_len = (u_int32_t *) cmd - (u_int32_t *) rule->cmd;
2683c2550
< return ((char *)cmd - (char *)buf);
---
> return ((char *)cmd - (char *)buf);
2685d2551
< #endif /* IPFW2 */
2687c2553
< static void ClearAllFWHoles(struct libalias *la);
---
> #endif /* IPFW2 */
2688a2555
> static void ClearAllFWHoles(struct libalias *la);
2689a2557
>
2693c2561
< } /*lint -save -e717 */ while(0) /*lint -restore */
---
> } /*lint -save -e717 */ while(0)/* lint -restore */
2698c2566
< } /*lint -save -e717 */ while(0) /*lint -restore */
---
> } /*lint -save -e717 */ while(0)/* lint -restore */
2706,2714c2574,2582
< la->fireWallField = malloc(la->fireWallNumNums);
< if (la->fireWallField) {
< memset(la->fireWallField, 0, la->fireWallNumNums);
< if (la->fireWallFD < 0) {
< la->fireWallFD = socket(AF_INET, SOCK_RAW, IPPROTO_RAW);
< }
< ClearAllFWHoles(la);
< la->fireWallActiveNum = la->fireWallBaseNum;
< }
---
> la->fireWallField = malloc(la->fireWallNumNums);
> if (la->fireWallField) {
> memset(la->fireWallField, 0, la->fireWallNumNums);
> if (la->fireWallFD < 0) {
> la->fireWallFD = socket(AF_INET, SOCK_RAW, IPPROTO_RAW);
> }
> ClearAllFWHoles(la);
> la->fireWallActiveNum = la->fireWallBaseNum;
> }
2720,2727c2588,2595
< ClearAllFWHoles(la);
< if (la->fireWallFD >= 0)
< close(la->fireWallFD);
< la->fireWallFD = -1;
< if (la->fireWallField)
< free(la->fireWallField);
< la->fireWallField = NULL;
< la->packetAliasMode &= ~PKT_ALIAS_PUNCH_FW;
---
> ClearAllFWHoles(la);
> if (la->fireWallFD >= 0)
> close(la->fireWallFD);
> la->fireWallFD = -1;
> if (la->fireWallField)
> free(la->fireWallField);
> la->fireWallField = NULL;
> la->packetAliasMode &= ~PKT_ALIAS_PUNCH_FW;
2734,2737c2602,2605
< struct libalias *la;
< int r; /* Result code */
< struct ip_fw rule; /* On-the-fly built rule */
< int fwhole; /* Where to punch hole */
---
> struct libalias *la;
> int r; /* Result code */
> struct ip_fw rule; /* On-the-fly built rule */
> int fwhole; /* Where to punch hole */
2739c2607
< la = link->la;
---
> la = link->la;
2742,2745c2610,2613
< if ( !(la->packetAliasMode & PKT_ALIAS_PUNCH_FW) ||
< la->fireWallFD < 0 ||
< link->link_type != LINK_TCP)
< return;
---
> if (!(la->packetAliasMode & PKT_ALIAS_PUNCH_FW) ||
> la->fireWallFD < 0 ||
> link->link_type != LINK_TCP)
> return;
2747c2615
< memset(&rule, 0, sizeof rule);
---
> memset(&rule, 0, sizeof rule);
2751,2765c2619,2631
< /* Find empty slot */
< for (fwhole = la->fireWallActiveNum;
< fwhole < la->fireWallBaseNum + la->fireWallNumNums &&
< fw_tstfield(la, la->fireWallField, fwhole);
< fwhole++)
< ;
< if (fwhole == la->fireWallBaseNum + la->fireWallNumNums) {
< for (fwhole = la->fireWallBaseNum;
< fwhole < la->fireWallActiveNum &&
< fw_tstfield(la, la->fireWallField, fwhole);
< fwhole++)
< ;
< if (fwhole == la->fireWallActiveNum) {
< /* No rule point empty - we can't punch more holes. */
< la->fireWallActiveNum = la->fireWallBaseNum;
---
> /* Find empty slot */
> for (fwhole = la->fireWallActiveNum;
> fwhole < la->fireWallBaseNum + la->fireWallNumNums &&
> fw_tstfield(la, la->fireWallField, fwhole);
> fwhole++);
> if (fwhole == la->fireWallBaseNum + la->fireWallNumNums) {
> for (fwhole = la->fireWallBaseNum;
> fwhole < la->fireWallActiveNum &&
> fw_tstfield(la, la->fireWallField, fwhole);
> fwhole++);
> if (fwhole == la->fireWallActiveNum) {
> /* No rule point empty - we can't punch more holes. */
> la->fireWallActiveNum = la->fireWallBaseNum;
2767c2633
< fprintf(stderr, "libalias: Unable to create firewall hole!\n");
---
> fprintf(stderr, "libalias: Unable to create firewall hole!\n");
2769,2773c2635,2639
< return;
< }
< }
< /* Start next search at next position */
< la->fireWallActiveNum = fwhole+1;
---
> return;
> }
> }
> /* Start next search at next position */
> la->fireWallActiveNum = fwhole + 1;
2775,2780c2641,2646
< /*
< * generate two rules of the form
< *
< * add fwhole accept tcp from OAddr OPort to DAddr DPort
< * add fwhole accept tcp from DAddr DPort to OAddr OPort
< */
---
> /*
> * generate two rules of the form
> *
> * add fwhole accept tcp from OAddr OPort to DAddr DPort add fwhole
> * accept tcp from DAddr DPort to OAddr OPort
> */
2782,2784c2648,2650
< if (GetOriginalPort(link) != 0 && GetDestPort(link) != 0) {
< u_int32_t rulebuf[255];
< int i;
---
> if (GetOriginalPort(link) != 0 && GetDestPort(link) != 0) {
> u_int32_t rulebuf[255];
> int i;
2786,2792c2652,2658
< i = fill_rule(rulebuf, sizeof(rulebuf), fwhole,
< O_ACCEPT, IPPROTO_TCP,
< GetOriginalAddress(link), ntohs(GetOriginalPort(link)),
< GetDestAddress(link), ntohs(GetDestPort(link)) );
< r = setsockopt(la->fireWallFD, IPPROTO_IP, IP_FW_ADD, rulebuf, i);
< if (r)
< err(1, "alias punch inbound(1) setsockopt(IP_FW_ADD)");
---
> i = fill_rule(rulebuf, sizeof(rulebuf), fwhole,
> O_ACCEPT, IPPROTO_TCP,
> GetOriginalAddress(link), ntohs(GetOriginalPort(link)),
> GetDestAddress(link), ntohs(GetDestPort(link)));
> r = setsockopt(la->fireWallFD, IPPROTO_IP, IP_FW_ADD, rulebuf, i);
> if (r)
> err(1, "alias punch inbound(1) setsockopt(IP_FW_ADD)");
2794,2802c2660,2668
< i = fill_rule(rulebuf, sizeof(rulebuf), fwhole,
< O_ACCEPT, IPPROTO_TCP,
< GetDestAddress(link), ntohs(GetDestPort(link)),
< GetOriginalAddress(link), ntohs(GetOriginalPort(link)) );
< r = setsockopt(la->fireWallFD, IPPROTO_IP, IP_FW_ADD, rulebuf, i);
< if (r)
< err(1, "alias punch inbound(2) setsockopt(IP_FW_ADD)");
< }
< #else /* !IPFW2, old code to generate ipfw rule */
---
> i = fill_rule(rulebuf, sizeof(rulebuf), fwhole,
> O_ACCEPT, IPPROTO_TCP,
> GetDestAddress(link), ntohs(GetDestPort(link)),
> GetOriginalAddress(link), ntohs(GetOriginalPort(link)));
> r = setsockopt(la->fireWallFD, IPPROTO_IP, IP_FW_ADD, rulebuf, i);
> if (r)
> err(1, "alias punch inbound(2) setsockopt(IP_FW_ADD)");
> }
> #else /* !IPFW2, old code to generate ipfw rule */
2804,2811c2670,2677
< /* Build generic part of the two rules */
< rule.fw_number = fwhole;
< IP_FW_SETNSRCP(&rule, 1); /* Number of source ports. */
< IP_FW_SETNDSTP(&rule, 1); /* Number of destination ports. */
< rule.fw_flg = IP_FW_F_ACCEPT | IP_FW_F_IN | IP_FW_F_OUT;
< rule.fw_prot = IPPROTO_TCP;
< rule.fw_smsk.s_addr = INADDR_BROADCAST;
< rule.fw_dmsk.s_addr = INADDR_BROADCAST;
---
> /* Build generic part of the two rules */
> rule.fw_number = fwhole;
> IP_FW_SETNSRCP(&rule, 1); /* Number of source ports. */
> IP_FW_SETNDSTP(&rule, 1); /* Number of destination ports. */
> rule.fw_flg = IP_FW_F_ACCEPT | IP_FW_F_IN | IP_FW_F_OUT;
> rule.fw_prot = IPPROTO_TCP;
> rule.fw_smsk.s_addr = INADDR_BROADCAST;
> rule.fw_dmsk.s_addr = INADDR_BROADCAST;
2813,2817c2679,2683
< /* Build and apply specific part of the rules */
< rule.fw_src = GetOriginalAddress(link);
< rule.fw_dst = GetDestAddress(link);
< rule.fw_uar.fw_pts[0] = ntohs(GetOriginalPort(link));
< rule.fw_uar.fw_pts[1] = ntohs(GetDestPort(link));
---
> /* Build and apply specific part of the rules */
> rule.fw_src = GetOriginalAddress(link);
> rule.fw_dst = GetDestAddress(link);
> rule.fw_uar.fw_pts[0] = ntohs(GetOriginalPort(link));
> rule.fw_uar.fw_pts[1] = ntohs(GetDestPort(link));
2819,2824c2685,2692
< /* Skip non-bound links - XXX should not be strictly necessary,
< but seems to leave hole if not done. Leak of non-bound links?
< (Code should be left even if the problem is fixed - it is a
< clear optimization) */
< if (rule.fw_uar.fw_pts[0] != 0 && rule.fw_uar.fw_pts[1] != 0) {
< r = setsockopt(fireWallFD, IPPROTO_IP, IP_FW_ADD, &rule, sizeof rule);
---
> /*
> * Skip non-bound links - XXX should not be strictly necessary, but
> * seems to leave hole if not done. Leak of non-bound links? (Code
> * should be left even if the problem is fixed - it is a clear
> * optimization)
> */
> if (rule.fw_uar.fw_pts[0] != 0 && rule.fw_uar.fw_pts[1] != 0) {
> r = setsockopt(fireWallFD, IPPROTO_IP, IP_FW_ADD, &rule, sizeof rule);
2826,2827c2694,2695
< if (r)
< err(1, "alias punch inbound(1) setsockopt(IP_FW_ADD)");
---
> if (r)
> err(1, "alias punch inbound(1) setsockopt(IP_FW_ADD)");
2829,2833c2697,2701
< rule.fw_src = GetDestAddress(link);
< rule.fw_dst = GetOriginalAddress(link);
< rule.fw_uar.fw_pts[0] = ntohs(GetDestPort(link));
< rule.fw_uar.fw_pts[1] = ntohs(GetOriginalPort(link));
< r = setsockopt(fireWallFD, IPPROTO_IP, IP_FW_ADD, &rule, sizeof rule);
---
> rule.fw_src = GetDestAddress(link);
> rule.fw_dst = GetOriginalAddress(link);
> rule.fw_uar.fw_pts[0] = ntohs(GetDestPort(link));
> rule.fw_uar.fw_pts[1] = ntohs(GetOriginalPort(link));
> r = setsockopt(fireWallFD, IPPROTO_IP, IP_FW_ADD, &rule, sizeof rule);
2835,2836c2703,2704
< if (r)
< err(1, "alias punch inbound(2) setsockopt(IP_FW_ADD)");
---
> if (r)
> err(1, "alias punch inbound(2) setsockopt(IP_FW_ADD)");
2838,2839c2706,2707
< }
< #endif /* !IPFW2 */
---
> }
> #endif /* !IPFW2 */
2841,2842c2709,2710
< link->data.tcp->fwhole = fwhole;
< fw_setfield(la, la->fireWallField, fwhole);
---
> link->data.tcp->fwhole = fwhole;
> fw_setfield(la, la->fireWallField, fwhole);
2851c2719
< struct libalias *la;
---
> struct libalias *la;
2853,2856c2721,2725
< la = link->la;
< if (link->link_type == LINK_TCP) {
< int fwhole = link->data.tcp->fwhole; /* Where is the firewall hole? */
< struct ip_fw rule;
---
> la = link->la;
> if (link->link_type == LINK_TCP) {
> int fwhole = link->data.tcp->fwhole; /* Where is the firewall
> * hole? */
> struct ip_fw rule;
2858,2859c2727,2728
< if (fwhole < 0)
< return;
---
> if (fwhole < 0)
> return;
2861c2730
< memset(&rule, 0, sizeof rule); /* useless for ipfw2 */
---
> memset(&rule, 0, sizeof rule); /* useless for ipfw2 */
2863,2874c2732,2741
< while (!setsockopt(la->fireWallFD, IPPROTO_IP, IP_FW_DEL,
< &fwhole, sizeof fwhole))
< ;
< #else /* !IPFW2 */
< rule.fw_number = fwhole;
< while (!setsockopt(fireWallFD, IPPROTO_IP, IP_FW_DEL,
< &rule, sizeof rule))
< ;
< #endif /* !IPFW2 */
< fw_clrfield(la, la->fireWallField, fwhole);
< link->data.tcp->fwhole = -1;
< }
---
> while (!setsockopt(la->fireWallFD, IPPROTO_IP, IP_FW_DEL,
> &fwhole, sizeof fwhole));
> #else /* !IPFW2 */
> rule.fw_number = fwhole;
> while (!setsockopt(fireWallFD, IPPROTO_IP, IP_FW_DEL,
> &rule, sizeof rule));
> #endif /* !IPFW2 */
> fw_clrfield(la, la->fireWallField, fwhole);
> link->data.tcp->fwhole = -1;
> }
2879,2881c2746,2749
< ClearAllFWHoles(struct libalias *la) {
< struct ip_fw rule; /* On-the-fly built rule */
< int i;
---
> ClearAllFWHoles(struct libalias *la)
> {
> struct ip_fw rule; /* On-the-fly built rule */
> int i;
2883,2884c2751,2752
< if (la->fireWallFD < 0)
< return;
---
> if (la->fireWallFD < 0)
> return;
2886,2887c2754,2755
< memset(&rule, 0, sizeof rule);
< for (i = la->fireWallBaseNum; i < la->fireWallBaseNum + la->fireWallNumNums; i++) {
---
> memset(&rule, 0, sizeof rule);
> for (i = la->fireWallBaseNum; i < la->fireWallBaseNum + la->fireWallNumNums; i++) {
2889,2899c2757,2766
< int r = i;
< while (!setsockopt(la->fireWallFD, IPPROTO_IP, IP_FW_DEL, &r, sizeof r))
< ;
< #else /* !IPFW2 */
< rule.fw_number = i;
< while (!setsockopt(fireWallFD, IPPROTO_IP, IP_FW_DEL, &rule, sizeof rule))
< ;
< #endif /* !IPFW2 */
< }
< /* XXX: third arg correct here ? /phk */
< memset(la->fireWallField, 0, la->fireWallNumNums);
---
> int r = i;
>
> while (!setsockopt(la->fireWallFD, IPPROTO_IP, IP_FW_DEL, &r, sizeof r));
> #else /* !IPFW2 */
> rule.fw_number = i;
> while (!setsockopt(fireWallFD, IPPROTO_IP, IP_FW_DEL, &rule, sizeof rule));
> #endif /* !IPFW2 */
> }
> /* XXX: third arg correct here ? /phk */
> memset(la->fireWallField, 0, la->fireWallNumNums);
2900a2768
>
2904c2772,2773
< LibAliasSetFWBase(struct libalias *la, unsigned int base, unsigned int num) {
---
> LibAliasSetFWBase(struct libalias *la, unsigned int base, unsigned int num)
> {
2906,2907c2775,2776
< la->fireWallBaseNum = base;
< la->fireWallNumNums = num;
---
> la->fireWallBaseNum = base;
> la->fireWallNumNums = num;
2912,2913c2781,2783
< LibAliasSetSkinnyPort(struct libalias *la, unsigned int port) {
< la->skinnyPort = port;
---
> LibAliasSetSkinnyPort(struct libalias *la, unsigned int port)
> {
> la->skinnyPort = port;