svn commit: r200957 - user/luigi/ipfw3-head/sys/netinet/ipfw
Luigi Rizzo
luigi at FreeBSD.org
Thu Dec 24 18:50:59 UTC 2009
Author: luigi
Date: Thu Dec 24 18:50:58 2009
New Revision: 200957
URL: http://svn.freebsd.org/changeset/base/200957
Log:
Make the code a bit more portable doing the ip_len/ip_off controlled
by a HAVE_NET_IPLEN macro (which is not defined on FreeBSD so we use
ip_len and ip_off in host order on layer3).
Modified:
user/luigi/ipfw3-head/sys/netinet/ipfw/ip_dummynet.c
user/luigi/ipfw3-head/sys/netinet/ipfw/ip_fw2.c
user/luigi/ipfw3-head/sys/netinet/ipfw/ip_fw_dynamic.c
user/luigi/ipfw3-head/sys/netinet/ipfw/ip_fw_log.c
user/luigi/ipfw3-head/sys/netinet/ipfw/ip_fw_nat.c
user/luigi/ipfw3-head/sys/netinet/ipfw/ip_fw_pfil.c
Modified: user/luigi/ipfw3-head/sys/netinet/ipfw/ip_dummynet.c
==============================================================================
--- user/luigi/ipfw3-head/sys/netinet/ipfw/ip_dummynet.c Thu Dec 24 18:41:14 2009 (r200956)
+++ user/luigi/ipfw3-head/sys/netinet/ipfw/ip_dummynet.c Thu Dec 24 18:50:58 2009 (r200957)
@@ -991,8 +991,10 @@ dummynet_send(struct mbuf *m)
break ;
case DN_TO_IP_IN :
ip = mtod(m, struct ip *);
+#ifndef HAVE_NET_IPLEN
ip->ip_len = htons(ip->ip_len);
ip->ip_off = htons(ip->ip_off);
+#endif
netisr_dispatch(NETISR_IP, m);
break;
#ifdef INET6
Modified: user/luigi/ipfw3-head/sys/netinet/ipfw/ip_fw2.c
==============================================================================
--- user/luigi/ipfw3-head/sys/netinet/ipfw/ip_fw2.c Thu Dec 24 18:41:14 2009 (r200956)
+++ user/luigi/ipfw3-head/sys/netinet/ipfw/ip_fw2.c Thu Dec 24 18:50:58 2009 (r200957)
@@ -607,8 +607,10 @@ send_reject(struct ip_fw_args *args, int
if (code != ICMP_REJECT_RST) { /* Send an ICMP unreach */
/* We need the IP header in host order for icmp_error(). */
if (args->eh != NULL) {
+#ifndef HAVE_NET_IPLEN
ip->ip_len = ntohs(ip->ip_len);
ip->ip_off = ntohs(ip->ip_off);
+#endif /* !HAVE_NET_IPLEN */
}
icmp_error(args->m, ICMP_UNREACH, code, 0L, 0);
} else if (args->f_id.proto == IPPROTO_TCP) {
@@ -1094,10 +1096,13 @@ do { \
proto = ip->ip_p;
src_ip = ip->ip_src;
dst_ip = ip->ip_dst;
+#ifndef HAVE_NET_IPLEN
if (args->eh != NULL) { /* layer 2 packets are as on the wire */
offset = ntohs(ip->ip_off) & IP_OFFMASK;
ip_len = ntohs(ip->ip_len);
- } else {
+ } else
+#endif /* !HAVE_NET_IPLEN */
+ {
offset = ip->ip_off & IP_OFFMASK;
ip_len = ip->ip_len;
}
@@ -2124,8 +2129,13 @@ do { \
f->bcnt += pktlen;
l = 0; /* in any case exit inner loop */
- ip_off = (args->eh != NULL) ?
- ntohs(ip->ip_off) : ip->ip_off;
+#ifndef HAVE_NET_IPLEN
+ if (args->eh == NULL)
+ ip_off = ip->ip_off;
+ else
+#endif /* !HAVE_NET_IPLEN */
+ ip_off = ntohs(ip->ip_off);
+
/* if not fragmented, go to next rule */
if ((ip_off & (IP_MF | IP_OFFMASK)) == 0)
break;
@@ -2134,10 +2144,12 @@ do { \
* byte order: fix them in case we come
* from layer2.
*/
+#ifndef HAVE_NET_IPLEN
if (args->eh != NULL) {
ip->ip_len = ntohs(ip->ip_len);
ip->ip_off = ntohs(ip->ip_off);
}
+#endif /* !HAVE_NET_IPLEN */
args->m = m = ip_reass(m);
@@ -2153,9 +2165,11 @@ do { \
ip = mtod(m, struct ip *);
hlen = ip->ip_hl << 2;
+#ifndef HAVE_NET_IPLEN
/* revert len & off for layer2 pkts */
if (args->eh != NULL)
ip->ip_len = htons(ip->ip_len);
+#endif /* !HAVE_NET_IPLEN */
ip->ip_sum = 0;
if (hlen == sizeof(struct ip))
ip->ip_sum = in_cksum_hdr(ip);
Modified: user/luigi/ipfw3-head/sys/netinet/ipfw/ip_fw_dynamic.c
==============================================================================
--- user/luigi/ipfw3-head/sys/netinet/ipfw/ip_fw_dynamic.c Thu Dec 24 18:41:14 2009 (r200956)
+++ user/luigi/ipfw3-head/sys/netinet/ipfw/ip_fw_dynamic.c Thu Dec 24 18:50:58 2009 (r200957)
@@ -1002,7 +1002,11 @@ ipfw_send_pkt(struct mbuf *replyto, stru
h->ip_hl = sizeof(*h) >> 2;
h->ip_tos = IPTOS_LOWDELAY;
h->ip_off = 0;
+#ifdef HAVE_NET_IPLEN
+ h->ip_len = htons(len);
+#else
h->ip_len = len;
+#endif
h->ip_ttl = V_ip_defttl;
h->ip_sum = 0;
break;
Modified: user/luigi/ipfw3-head/sys/netinet/ipfw/ip_fw_log.c
==============================================================================
--- user/luigi/ipfw3-head/sys/netinet/ipfw/ip_fw_log.c Thu Dec 24 18:41:14 2009 (r200956)
+++ user/luigi/ipfw3-head/sys/netinet/ipfw/ip_fw_log.c Thu Dec 24 18:50:58 2009 (r200957)
@@ -158,18 +158,22 @@ ipfw_log(struct ip_fw *f, u_int hlen, st
* more info in the header
*/
mh.mh_data = "DDDDDDSSSSSS\x08\x00";
+#ifndef HAVE_NET_IPLEN
if (args->f_id.addr_type == 4) {
/* restore wire format */
ip->ip_off = ntohs(ip->ip_off);
ip->ip_len = ntohs(ip->ip_len);
}
+#endif /* !HAVE_NET_IPLEN */
}
BPF_MTAP(log_if, (struct mbuf *)&mh);
+#ifndef HAVE_NET_IPLEN
if (args->eh == NULL && args->f_id.addr_type == 4) {
/* restore host format */
ip->ip_off = htons(ip->ip_off);
ip->ip_len = htons(ip->ip_len);
}
+#endif /* !HAVE_NET_IPLEN */
return;
}
/* the old 'log' function */
@@ -404,10 +408,13 @@ ipfw_log(struct ip_fw *f, u_int hlen, st
#endif
{
int ip_off, ip_len;
+#ifndef HAVE_NET_IPLEN
if (eh != NULL) { /* layer 2 packets are as on the wire */
ip_off = ntohs(ip->ip_off);
ip_len = ntohs(ip->ip_len);
- } else {
+ } else
+#endif /* !HAVE_NET_IPLEN */
+ {
ip_off = ip->ip_off;
ip_len = ip->ip_len;
}
Modified: user/luigi/ipfw3-head/sys/netinet/ipfw/ip_fw_nat.c
==============================================================================
--- user/luigi/ipfw3-head/sys/netinet/ipfw/ip_fw_nat.c Thu Dec 24 18:41:14 2009 (r200956)
+++ user/luigi/ipfw3-head/sys/netinet/ipfw/ip_fw_nat.c Thu Dec 24 18:50:58 2009 (r200957)
@@ -222,10 +222,12 @@ ipfw_nat(struct ip_fw_args *args, struct
return (IP_FW_DENY);
}
ip = mtod(mcl, struct ip *);
+#ifndef HAVE_NET_IPLEN
if (args->eh == NULL) {
ip->ip_len = htons(ip->ip_len);
ip->ip_off = htons(ip->ip_off);
}
+#endif /* !HAVE_NET_IPLEN */
/*
* XXX - Libalias checksum offload 'duct tape':
@@ -335,12 +337,12 @@ ipfw_nat(struct ip_fw_args *args, struct
}
ip->ip_len = htons(ip->ip_len);
}
-
+#ifndef HAVE_NET_IPLEN
if (args->eh == NULL) {
ip->ip_len = ntohs(ip->ip_len);
ip->ip_off = ntohs(ip->ip_off);
}
-
+#endif /* !HAVE_NET_IPLEN */
args->m = mcl;
return (IP_FW_NAT);
}
Modified: user/luigi/ipfw3-head/sys/netinet/ipfw/ip_fw_pfil.c
==============================================================================
--- user/luigi/ipfw3-head/sys/netinet/ipfw/ip_fw_pfil.c Thu Dec 24 18:41:14 2009 (r200956)
+++ user/luigi/ipfw3-head/sys/netinet/ipfw/ip_fw_pfil.c Thu Dec 24 18:50:58 2009 (r200957)
@@ -425,8 +425,10 @@ ipfw_divert(struct mbuf **m, int incomin
if (reass != NULL) {
ip = mtod(reass, struct ip *);
hlen = ip->ip_hl << 2;
+#ifndef HAVE_NET_IPLEN
ip->ip_len = htons(ip->ip_len);
ip->ip_off = htons(ip->ip_off);
+#endif /* !HAVE_NET_IPLEN */
ip->ip_sum = 0;
if (hlen == sizeof(struct ip))
ip->ip_sum = in_cksum_hdr(ip);
@@ -436,9 +438,11 @@ ipfw_divert(struct mbuf **m, int incomin
} else
clone = NULL;
} else {
+#ifndef HAVE_NET_IPLEN
/* Convert header to network byte order. */
ip->ip_len = htons(ip->ip_len);
ip->ip_off = htons(ip->ip_off);
+#endif /* !HAVE_NET_IPLEN */
}
/* Do the dirty job... */
More information about the svn-src-user
mailing list