PERFORCE change 138688 for review
Paolo Pisati
piso at FreeBSD.org
Thu Mar 27 00:06:25 UTC 2008
http://perforce.freebsd.org/chv.cgi?CH=138688
Change 138688 by piso at piso_newluxor on 2008/03/27 00:06:17
Adapt ng_nat to the new libalias API.
Affected files ...
.. //depot/projects/soc2005/libalias/sys/netgraph/ng_nat.c#15 edit
Differences ...
==== //depot/projects/soc2005/libalias/sys/netgraph/ng_nat.c#15 (text+ko) ====
@@ -675,7 +675,6 @@
struct mbuf *m;
struct ip *ip;
int rval, error = 0;
- char *c;
/* We have no required hooks. */
if (!(priv->flags & NGNAT_CONNECTED)) {
@@ -689,7 +688,7 @@
m = NGI_M(item);
- if ((m = m_megapullup(m, m->m_pkthdr.len)) == NULL) {
+ if ((m = m_pullup(m, sizeof(struct ip))) == NULL) {
NGI_M(item) = NULL; /* avoid double free */
NG_FREE_ITEM(item);
return (ENOBUFS);
@@ -697,21 +696,20 @@
NGI_M(item) = m;
- c = mtod(m, char *);
ip = mtod(m, struct ip *);
KASSERT(m->m_pkthdr.len == ntohs(ip->ip_len),
("ng_nat: ip_len != m_pkthdr.len"));
if (hook == priv->in) {
- rval = LibAliasIn(priv->lib, c, MCLBYTES);
+ rval = LibAliasIn(priv->lib, &m, MCLBYTES);
if (rval != PKT_ALIAS_OK &&
rval != PKT_ALIAS_FOUND_HEADER_FRAGMENT) {
NG_FREE_ITEM(item);
return (EINVAL);
}
} else if (hook == priv->out) {
- rval = LibAliasOut(priv->lib, c, MCLBYTES);
+ rval = LibAliasOut(priv->lib, &m, MCLBYTES);
if (rval != PKT_ALIAS_OK) {
NG_FREE_ITEM(item);
return (EINVAL);
@@ -719,11 +717,30 @@
} else
panic("ng_nat: unknown hook!\n");
- m->m_pkthdr.len = m->m_len = ntohs(ip->ip_len);
+
+ if ((m = m_pullup(m, sizeof(struct ip))) == NULL) {
+ NGI_M(item) = NULL; /* avoid double free */
+ NG_FREE_ITEM(item);
+ return (ENOBUFS);
+ }
+
+ NGI_M(item) = m;
+
+ ip = mtod(m, struct ip *);
+ m->m_pkthdr.len = ntohs(ip->ip_len);
if ((ip->ip_off & htons(IP_OFFMASK)) == 0 &&
ip->ip_p == IPPROTO_TCP) {
- struct tcphdr *th = (struct tcphdr *)((caddr_t)ip +
+ struct tcphdr *th;
+ if ((m = m_pullup(m, (ip->ip_hl << 2)
+ + sizeof(struct tcphdr))) == NULL) {
+ NGI_M(item) = NULL; /* avoid double free */
+ NG_FREE_ITEM(item);
+ return (ENOBUFS);
+ }
+ NGI_M(item) = m;
+ ip = mtod(m, struct ip *);
+ th = (struct tcphdr *)((caddr_t)ip +
(ip->ip_hl << 2));
/*
More information about the p4-projects
mailing list