diff options
author | phk <phk@FreeBSD.org> | 2004-07-04 12:53:07 +0000 |
---|---|---|
committer | phk <phk@FreeBSD.org> | 2004-07-04 12:53:07 +0000 |
commit | 112a83894d56dd8ce8c57886166b40ad0ba87ba4 (patch) | |
tree | 79818eb1c6115b396f162664bce0c5e4ab9cb24b /lib/libalias | |
parent | b52c81e5db821f2344b775a5b98a58a7797433e4 (diff) | |
download | FreeBSD-src-112a83894d56dd8ce8c57886166b40ad0ba87ba4.zip FreeBSD-src-112a83894d56dd8ce8c57886166b40ad0ba87ba4.tar.gz |
Add LibAliasOutTry() which checks a packet for a hit in the tables, but
does not create a new entry if none is found.
Diffstat (limited to 'lib/libalias')
-rw-r--r-- | lib/libalias/alias.c | 44 | ||||
-rw-r--r-- | lib/libalias/alias.h | 1 |
2 files changed, 29 insertions, 16 deletions
diff --git a/lib/libalias/alias.c b/lib/libalias/alias.c index 42ce618..326b8c0 100644 --- a/lib/libalias/alias.c +++ b/lib/libalias/alias.c @@ -254,16 +254,16 @@ static int IcmpAliasIn(struct libalias *, struct ip *); static int IcmpAliasOut1(struct libalias *, struct ip *); static int IcmpAliasOut2(struct libalias *, struct ip *); -static int IcmpAliasOut(struct libalias *, struct ip *); +static int IcmpAliasOut(struct libalias *, struct ip *, int create); static int ProtoAliasIn(struct libalias *, struct ip *); -static int ProtoAliasOut(struct libalias *, struct ip *); +static int ProtoAliasOut(struct libalias *, struct ip *, int create); -static int UdpAliasOut(struct libalias *, struct ip *); static int UdpAliasIn(struct libalias *, struct ip *); +static int UdpAliasOut(struct libalias *, struct ip *, int create); -static int TcpAliasOut(struct libalias *, struct ip *, int); static int TcpAliasIn(struct libalias *, struct ip *); +static int TcpAliasOut(struct libalias *, struct ip *, int, int create); static int @@ -589,7 +589,7 @@ fragment contained in ICMP data section */ static int -IcmpAliasOut(struct libalias *la, struct ip *pip) +IcmpAliasOut(struct libalias *la, struct ip *pip, int create) { int iresult; struct icmp *ic; @@ -656,7 +656,7 @@ ProtoAliasIn(struct libalias *la, struct ip *pip) static int -ProtoAliasOut(struct libalias *la, struct ip *pip) +ProtoAliasOut(struct libalias *la, struct ip *pip, int create) { /* Handle outgoing IP packets. The @@ -751,7 +751,7 @@ UdpAliasIn(struct libalias *la, struct ip *pip) } static int -UdpAliasOut(struct libalias *la, struct ip *pip) +UdpAliasOut(struct libalias *la, struct ip *pip, int create) { struct udphdr *ud; struct alias_link *link; @@ -764,7 +764,7 @@ UdpAliasOut(struct libalias *la, struct ip *pip) link = FindUdpTcpOut(la, pip->ip_src, pip->ip_dst, ud->uh_sport, ud->uh_dport, - IPPROTO_UDP, 1); + IPPROTO_UDP, create); if (link != NULL) { u_short alias_port; struct in_addr alias_address; @@ -905,7 +905,7 @@ TcpAliasIn(struct libalias *la, struct ip *pip) } static int -TcpAliasOut(struct libalias *la, struct ip *pip, int maxpacketsize) +TcpAliasOut(struct libalias *la, struct ip *pip, int maxpacketsize, int create) { int proxy_type; u_short dest_port; @@ -943,7 +943,9 @@ TcpAliasOut(struct libalias *la, struct ip *pip, int maxpacketsize) } link = FindUdpTcpOut(la, pip->ip_src, pip->ip_dst, tc->th_sport, tc->th_dport, - IPPROTO_TCP, 1); + IPPROTO_TCP, create); + if (link == NULL) + return (PKT_ALIAS_IGNORED); if (link != NULL) { u_short alias_port; struct in_addr alias_address; @@ -1234,6 +1236,16 @@ LibAliasOut(struct libalias *la, char *ptr, /* valid IP packet */ * and IRC inline changes) */ ) { + return (LibAliasOutTry(la, ptr, maxpacketsize, 1)); +} + +int +LibAliasOutTry(struct libalias *la, char *ptr, /* valid IP packet */ + int maxpacketsize, /* How much the packet data may grow (FTP + * and IRC inline changes) */ + int create /* Create new entries ? */ +) +{ int iresult; struct in_addr addr_save; struct ip *pip; @@ -1277,22 +1289,22 @@ LibAliasOut(struct libalias *la, char *ptr, /* valid IP packet */ if ((ntohs(pip->ip_off) & IP_OFFMASK) == 0) { switch (pip->ip_p) { case IPPROTO_ICMP: - iresult = IcmpAliasOut(la, pip); + iresult = IcmpAliasOut(la, pip, create); break; case IPPROTO_UDP: - iresult = UdpAliasOut(la, pip); + iresult = UdpAliasOut(la, pip, create); break; - case IPPROTO_TCP: - iresult = TcpAliasOut(la, pip, maxpacketsize); + case IPPROTO_TCP: + iresult = TcpAliasOut(la, pip, maxpacketsize, create); break; case IPPROTO_GRE: if (AliasHandlePptpGreOut(la, pip) == 0) iresult = PKT_ALIAS_OK; else - iresult = ProtoAliasOut(la, pip); + iresult = ProtoAliasOut(la, pip, create); break; default: - iresult = ProtoAliasOut(la, pip); + iresult = ProtoAliasOut(la, pip, create); break; } } else { diff --git a/lib/libalias/alias.h b/lib/libalias/alias.h index 0f5ba70..cf681a4 100644 --- a/lib/libalias/alias.h +++ b/lib/libalias/alias.h @@ -134,6 +134,7 @@ void LibAliasUninit(struct libalias *); /* Packet Handling functions. */ int LibAliasIn (struct libalias *, char *_ptr, int _maxpacketsize); int LibAliasOut(struct libalias *, char *_ptr, int _maxpacketsize); +int LibAliasOutTry(struct libalias *, char *_ptr, int _maxpacketsize, int _create); int LibAliasUnaliasOut(struct libalias *, char *_ptr, int _maxpacketsize); /* Port and address redirection functions. */ |