Page MenuHomeFreeBSD

D26758.diff
No OneTemporary

D26758.diff

Index: head/sys/netpfil/ipfw/nat64/nat64lsn.c
===================================================================
--- head/sys/netpfil/ipfw/nat64/nat64lsn.c
+++ head/sys/netpfil/ipfw/nat64/nat64lsn.c
@@ -547,6 +547,57 @@
return (NULL);
}
+/*
+ * Reassemble IPv4 fragments, make PULLUP if needed, get some ULP fields
+ * that might be unknown until reassembling is completed.
+ */
+static struct mbuf*
+nat64lsn_reassemble4(struct nat64lsn_cfg *cfg, struct mbuf *m,
+ uint16_t *port)
+{
+ struct ip *ip;
+ int len;
+
+ m = ip_reass(m);
+ if (m == NULL)
+ return (NULL);
+ /* IP header must be contigious after ip_reass() */
+ ip = mtod(m, struct ip *);
+ len = ip->ip_hl << 2;
+ switch (ip->ip_p) {
+ case IPPROTO_ICMP:
+ len += ICMP_MINLEN; /* Enough to get icmp_id */
+ break;
+ case IPPROTO_TCP:
+ len += sizeof(struct tcphdr);
+ break;
+ case IPPROTO_UDP:
+ len += sizeof(struct udphdr);
+ break;
+ default:
+ m_freem(m);
+ NAT64STAT_INC(&cfg->base.stats, noproto);
+ return (NULL);
+ }
+ if (m->m_len < len) {
+ m = m_pullup(m, len);
+ if (m == NULL) {
+ NAT64STAT_INC(&cfg->base.stats, nomem);
+ return (NULL);
+ }
+ ip = mtod(m, struct ip *);
+ }
+ switch (ip->ip_p) {
+ case IPPROTO_TCP:
+ *port = ntohs(L3HDR(ip, struct tcphdr *)->th_dport);
+ break;
+ case IPPROTO_UDP:
+ *port = ntohs(L3HDR(ip, struct udphdr *)->uh_dport);
+ break;
+ }
+ return (m);
+}
+
static int
nat64lsn_translate4(struct nat64lsn_cfg *cfg,
const struct ipfw_flow_id *f_id, struct mbuf **mp)
@@ -566,6 +617,14 @@
if (addr < cfg->prefix4 || addr > cfg->pmask4) {
NAT64STAT_INC(&cfg->base.stats, nomatch4);
return (cfg->nomatch_verdict);
+ }
+
+ /* Reassemble fragments if needed */
+ ret = ntohs(mtod(*mp, struct ip *)->ip_off);
+ if ((ret & (IP_MF | IP_OFFMASK)) != 0) {
+ *mp = nat64lsn_reassemble4(cfg, *mp, &port);
+ if (*mp == NULL)
+ return (IP_FW_DENY);
}
/* Check if protocol is supported */

File Metadata

Mime Type
text/plain
Expires
Sun, Nov 17, 11:17 PM (21 h, 41 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
14686293
Default Alt Text
D26758.diff (1 KB)

Event Timeline