Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F178361479
D62392.1796579820.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Authored By
Unknown
Size
4 KB
Referenced Files
None
Subscribers
None
D62392.1796579820.diff
View Options
diff --git a/sys/netpfil/ipfw/pmod/tcpmod.c b/sys/netpfil/ipfw/pmod/tcpmod.c
--- a/sys/netpfil/ipfw/pmod/tcpmod.c
+++ b/sys/netpfil/ipfw/pmod/tcpmod.c
@@ -57,28 +57,22 @@
#define V_tcpmod_setmss_eid VNET(tcpmod_setmss_eid)
static int
-tcpmod_setmss(struct mbuf **mp, struct tcphdr *tcp, int tlen, uint16_t mss,
- int *done)
+tcpmod_setmss(struct mbuf **mp, int tcpoff, int tlen, uint16_t mss)
{
struct mbuf *m;
- u_char *cp;
- int optlen, ret;
- uint16_t oldmss, csum;
+ u_char buf[MAX_TCPOPTLEN], *cp;
+ int optlen, optoff, ret;
+ uint16_t oldmss, newmss, csum;
m = *mp;
ret = IP_FW_DENY;
- /*
- * We shouldn't have any data, IP packet contains only
- * TCP header with options.
- */
- *mp = m = m_pullup(m, m->m_pkthdr.len);
- if (m == NULL) {
- *done = 1;
+ optoff = tcpoff + sizeof(struct tcphdr);
+ tlen -= sizeof(struct tcphdr);
+ if (tlen <= 0 || tlen > (int)sizeof(buf))
return (ret);
- }
+ m_copydata(m, optoff, tlen, buf);
/* Parse TCP options. */
- for (tlen -= sizeof(struct tcphdr), cp = (u_char *)(tcp + 1);
- tlen > 0; tlen -= optlen, cp += optlen) {
+ for (cp = buf; tlen > 0; tlen -= optlen, cp += optlen) {
if (cp[0] == TCPOPT_EOL)
break;
if (cp[0] == TCPOPT_NOP) {
@@ -98,13 +92,19 @@
/* Do not update lower MSS value */
if (ntohs(oldmss) <= ntohs(mss))
break;
- bcopy(&mss, cp + 2, sizeof(mss));
+ newmss = mss;
+ m_copyback(m, optoff + (cp - buf) + 2,
+ sizeof(newmss), (caddr_t)&newmss);
/* Update checksum if it is not delayed. */
if ((m->m_pkthdr.csum_flags &
(CSUM_TCP | CSUM_TCP_IPV6)) == 0) {
- bcopy(&tcp->th_sum, &csum, sizeof(csum));
+ m_copydata(m, tcpoff +
+ offsetof(struct tcphdr, th_sum),
+ sizeof(csum), (caddr_t)&csum);
csum = cksum_adjust(csum, oldmss, mss);
- bcopy(&csum, &tcp->th_sum, sizeof(csum));
+ m_copyback(m, tcpoff +
+ offsetof(struct tcphdr, th_sum),
+ sizeof(csum), (caddr_t)&csum);
}
break;
}
@@ -115,12 +115,12 @@
#ifdef INET6
static int
-tcpmod_ipv6_setmss(struct mbuf **mp, uint16_t mss, int *done)
+tcpmod_ipv6_setmss(struct mbuf **mp, uint16_t mss)
{
struct ip6_hdr *ip6;
struct ip6_hbh *hbh;
struct tcphdr *tcp;
- int hlen, plen, proto;
+ int hlen, plen, tlen, proto;
ip6 = mtod(*mp, struct ip6_hdr *);
hlen = sizeof(*ip6);
@@ -139,31 +139,31 @@
}
tcp = mtodo(*mp, hlen);
plen = (*mp)->m_pkthdr.len - hlen;
- hlen = tcp->th_off << 2;
+ tlen = tcp->th_off << 2;
/* We must have TCP options and enough data in a packet. */
- if (hlen <= sizeof(struct tcphdr) || hlen > plen)
+ if (tlen <= (int)sizeof(struct tcphdr) || tlen > plen)
return (IP_FW_DENY);
- return (tcpmod_setmss(mp, tcp, hlen, mss, done));
+ return (tcpmod_setmss(mp, hlen, tlen, mss));
}
#endif /* INET6 */
#ifdef INET
static int
-tcpmod_ipv4_setmss(struct mbuf **mp, uint16_t mss, int *done)
+tcpmod_ipv4_setmss(struct mbuf **mp, uint16_t mss)
{
struct tcphdr *tcp;
struct ip *ip;
- int hlen, plen;
+ int hlen, plen, tlen;
ip = mtod(*mp, struct ip *);
hlen = ip->ip_hl << 2;
tcp = mtodo(*mp, hlen);
plen = (*mp)->m_pkthdr.len - hlen;
- hlen = tcp->th_off << 2;
+ tlen = tcp->th_off << 2;
/* We must have TCP options and enough data in a packet. */
- if (hlen <= sizeof(struct tcphdr) || hlen > plen)
+ if (tlen <= (int)sizeof(struct tcphdr) || tlen > plen)
return (IP_FW_DENY);
- return (tcpmod_setmss(mp, tcp, hlen, mss, done));
+ return (tcpmod_setmss(mp, hlen, tlen, mss));
}
#endif /* INET */
@@ -207,23 +207,21 @@
switch (args->f_id.addr_type) {
#ifdef INET
case 4:
- ret = tcpmod_ipv4_setmss(&args->m, htons(icmd->arg1),
- done);
+ ret = tcpmod_ipv4_setmss(&args->m,
+ htons(icmd->arg1));
break;
#endif
#ifdef INET6
case 6:
- ret = tcpmod_ipv6_setmss(&args->m, htons(icmd->arg1),
- done);
+ ret = tcpmod_ipv6_setmss(&args->m,
+ htons(icmd->arg1));
break;
#endif
}
/*
* We return zero in both @ret and @done on success, and ipfw_chk()
* will update rule counters. Otherwise a packet will not be matched
- * by rule. We passed @done around above in case we hit a fatal error
- * somewhere, we'll return non-zero but signal that rule processing
- * cannot succeed.
+ * by rule.
*/
return (ret);
}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sun, Dec 6, 5:57 PM (3 h, 16 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
42260953
Default Alt Text
D62392.1796579820.diff (4 KB)
Attached To
Mode
D62392: ipfw: avoid m_pullup in tcpmod_setmss
Attached
Detach File
Event Timeline