From 8434f10fbf81a15231b23373543e3c9234321166 Mon Sep 17 00:00:00 2001 From: dlg Date: Sat, 20 Feb 2021 04:55:52 +0000 Subject: [PATCH] add p2p_input, like ether_input but for l3 tunnel interfaces. the l3 protocol input to push the packet is based on a value in m->m_pkthdr.ph_family, which tunnel drivers should set before calling if_vinput. add p2p_bpf_mtap to call bpf_mtap_af also using m->m_pkthdr.ph_family. --- sys/net/if.c | 42 +++++++++++++++++++++++++++++++++++++++++- sys/net/if_var.h | 4 +++- 2 files changed, 44 insertions(+), 2 deletions(-) diff --git a/sys/net/if.c b/sys/net/if.c index 9377bda5b44..3e0ce1643a6 100644 --- a/sys/net/if.c +++ b/sys/net/if.c @@ -1,4 +1,4 @@ -/* $OpenBSD: if.c,v 1.631 2021/02/20 04:37:26 dlg Exp $ */ +/* $OpenBSD: if.c,v 1.632 2021/02/20 04:55:52 dlg Exp $ */ /* $NetBSD: if.c,v 1.35 1996/05/07 05:26:04 thorpej Exp $ */ /* @@ -853,6 +853,10 @@ if_vinput(struct ifnet *ifp, struct mbuf *m) counters_pkt(ifp->if_counters, ifc_ipackets, ifc_ibytes, m->m_pkthdr.len); +#if NPF > 0 + pf_pkt_addr_changed(m); +#endif + #if NBPFILTER > 0 if_bpf = ifp->if_bpf; if (if_bpf) { @@ -1501,6 +1505,42 @@ p2p_rtrequest(struct ifnet *ifp, int req, struct rtentry *rt) } } +int +p2p_bpf_mtap(caddr_t if_bpf, const struct mbuf *m, u_int dir) +{ +#if NBPFILTER > 0 + return (bpf_mtap_af(if_bpf, m->m_pkthdr.ph_family, m, dir)); +#else + return (0); +#endif +} + +void +p2p_input(struct ifnet *ifp, struct mbuf *m) +{ + void (*input)(struct ifnet *, struct mbuf *); + + switch (m->m_pkthdr.ph_family) { + case AF_INET: + input = ipv4_input; + break; +#ifdef INET6 + case AF_INET6: + input = ipv6_input; + break; +#endif +#ifdef MPLS + case AF_MPLS: + input = mpls_input; + break; +#endif + default: + m_freem(m); + return; + } + + (*input)(ifp, m); +} /* * Bring down all interfaces diff --git a/sys/net/if_var.h b/sys/net/if_var.h index 26c08284f0d..400afd319b0 100644 --- a/sys/net/if_var.h +++ b/sys/net/if_var.h @@ -1,4 +1,4 @@ -/* $OpenBSD: if_var.h,v 1.113 2021/02/20 04:35:41 dlg Exp $ */ +/* $OpenBSD: if_var.h,v 1.114 2021/02/20 04:55:52 dlg Exp $ */ /* $NetBSD: if.h,v 1.23 1996/05/07 02:40:27 thorpej Exp $ */ /* @@ -327,6 +327,8 @@ int if_input_local(struct ifnet *, struct mbuf *, sa_family_t); int if_output_local(struct ifnet *, struct mbuf *, sa_family_t); void if_rtrequest_dummy(struct ifnet *, int, struct rtentry *); void p2p_rtrequest(struct ifnet *, int, struct rtentry *); +void p2p_input(struct ifnet *, struct mbuf *); +int p2p_bpf_mtap(caddr_t, const struct mbuf *, u_int); struct ifaddr *ifa_ifwithaddr(struct sockaddr *, u_int); struct ifaddr *ifa_ifwithdstaddr(struct sockaddr *, u_int); -- 2.20.1