-/* $OpenBSD: ip_ipip.c,v 1.93 2021/07/08 21:07:19 bluhm Exp $ */
+/* $OpenBSD: ip_ipip.c,v 1.94 2021/10/05 11:45:26 bluhm Exp $ */
/*
* The authors of this code are John Ioannidis (ji@tla.org),
* Angelos D. Keromytis (kermit@csd.uch.gr) and
#ifdef ENCDEBUG
char buf[INET6_ADDRSTRLEN];
#endif
+ int error;
/* XXX Deal with empty TDB source/destination addresses. */
ntohl(tdb->tdb_spi));
ipipstat_inc(ipips_unspec);
- m_freem(m);
- *mp = NULL;
- return EINVAL;
+ error = EINVAL;
+ goto drop;
}
M_PREPEND(m, sizeof(struct ip), M_DONTWAIT);
if (m == NULL) {
DPRINTF("M_PREPEND failed");
ipipstat_inc(ipips_hdrops);
- *mp = NULL;
- return ENOBUFS;
+ error = ENOBUFS;
+ goto drop;
}
ipo = mtod(m, struct ip *);
}
#endif /* INET6 */
else {
- m_freem(m);
- *mp = NULL;
ipipstat_inc(ipips_family);
- return EAFNOSUPPORT;
+ error = EAFNOSUPPORT;
+ goto drop;
}
otos = 0;
ip_ecn_ingress(ECN_ALLOWED, &otos, &itos);
ipo->ip_tos = otos;
+
+ obytes = m->m_pkthdr.len - sizeof(struct ip);
+ if (tdb->tdb_xform->xf_type == XF_IP4)
+ tdb->tdb_cur_bytes += obytes;
break;
#ifdef INET6
ntohl(tdb->tdb_spi));
ipipstat_inc(ipips_unspec);
- m_freem(m);
- *mp = NULL;
- return ENOBUFS;
+ error = EINVAL;
+ goto drop;
}
/* If the inner protocol is IPv6, clear link local scope */
if (m == NULL) {
DPRINTF("M_PREPEND failed");
ipipstat_inc(ipips_hdrops);
- *mp = NULL;
- return ENOBUFS;
+ error = ENOBUFS;
+ goto drop;
}
/* Initialize IPv6 header */
ip6o->ip6_nxt = IPPROTO_IPV6;
} else {
- m_freem(m);
- *mp = NULL;
ipipstat_inc(ipips_family);
- return EAFNOSUPPORT;
+ error = EAFNOSUPPORT;
+ goto drop;
}
otos = 0;
ip_ecn_ingress(ECN_ALLOWED, &otos, &itos);
ip6o->ip6_flow |= htonl((u_int32_t) otos << 20);
+
+ obytes = m->m_pkthdr.len - sizeof(struct ip6_hdr);
+ if (tdb->tdb_xform->xf_type == XF_IP4)
+ tdb->tdb_cur_bytes += obytes;
break;
#endif /* INET6 */
default:
DPRINTF("unsupported protocol family %d",
tdb->tdb_dst.sa.sa_family);
- m_freem(m);
- *mp = NULL;
ipipstat_inc(ipips_family);
- return EAFNOSUPPORT;
+ error = EAFNOSUPPORT;
+ goto drop;
}
- ipipstat_inc(ipips_opackets);
*mp = m;
-
- if (tdb->tdb_dst.sa.sa_family == AF_INET) {
- obytes = m->m_pkthdr.len - sizeof(struct ip);
- if (tdb->tdb_xform->xf_type == XF_IP4)
- tdb->tdb_cur_bytes += obytes;
-
- ipipstat_add(ipips_obytes, obytes);
- }
-
-#ifdef INET6
- if (tdb->tdb_dst.sa.sa_family == AF_INET6) {
- obytes = m->m_pkthdr.len - sizeof(struct ip6_hdr);
- if (tdb->tdb_xform->xf_type == XF_IP4)
- tdb->tdb_cur_bytes += obytes;
-
- ipipstat_add(ipips_obytes, obytes);
- }
-#endif /* INET6 */
-
+ ipipstat_pkt(ipips_opackets, ipips_obytes, obytes);
return 0;
+
+ drop:
+ m_freem(m);
+ *mp = NULL;
+ return error;
}
#ifdef IPSEC
-/* $OpenBSD: ip_ipip.h,v 1.11 2019/10/04 05:00:49 dlg Exp $ */
+/* $OpenBSD: ip_ipip.h,v 1.12 2021/10/05 11:45:26 bluhm Exp $ */
/*
* The authors of this code are John Ioannidis (ji@tla.org),
* Angelos D. Keromytis (kermit@csd.uch.gr) and
counters_add(ipipcounters, c, v);
}
+static inline void
+ipipstat_pkt(enum ipipstat_counters p, enum ipipstat_counters b, uint64_t v)
+{
+ counters_pkt(ipipcounters, p, b, v);
+}
+
struct tdb;
void ipip_init(void);
-/* $OpenBSD: ip_ipsp.h,v 1.208 2021/10/05 11:34:34 bluhm Exp $ */
+/* $OpenBSD: ip_ipsp.h,v 1.209 2021/10/05 11:45:26 bluhm Exp $ */
/*
* The authors of this code are John Ioannidis (ji@tla.org),
* Angelos D. Keromytis (kermit@csd.uch.gr),
counters_add(ipseccounters, c, v);
}
+static inline void
+ipsecstat_pkt(enum ipsec_counters p, enum ipsec_counters b, uint64_t v)
+{
+ counters_pkt(ipseccounters, p, b, v);
+}
+
struct m_tag;
#define sen_data Sen.Data
-/* $OpenBSD: ipsec_input.c,v 1.181 2021/10/05 11:34:35 bluhm Exp $ */
+/* $OpenBSD: ipsec_input.c,v 1.182 2021/10/05 11:45:26 bluhm Exp $ */
/*
* The authors of this code are John Ioannidis (ji@tla.org),
* Angelos D. Keromytis (kermit@csd.uch.gr) and
NET_ASSERT_LOCKED();
- ipsecstat_inc(ipsec_ipackets);
- ipsecstat_add(ipsec_ibytes, m->m_pkthdr.len);
+ ipsecstat_pkt(ipsec_ipackets, ipsec_ibytes, m->m_pkthdr.len);
IPSEC_ISTAT(esps_input, ahs_input, ipcomps_input);
if (m == NULL) {
-/* $OpenBSD: ipsec_output.c,v 1.86 2021/07/27 17:13:03 mvs Exp $ */
+/* $OpenBSD: ipsec_output.c,v 1.87 2021/10/05 11:45:26 bluhm Exp $ */
/*
* The author of this code is Angelos D. Keromytis (angelos@cis.upenn.edu)
*
m_tag_prepend(m, mtag);
- ipsecstat_inc(ipsec_opackets);
- ipsecstat_add(ipsec_obytes, m->m_pkthdr.len);
+ ipsecstat_pkt(ipsec_opackets, ipsec_obytes, m->m_pkthdr.len);
tdb->tdb_opackets++;
tdb->tdb_obytes += m->m_pkthdr.len;