Module Name: src Committed By: bouyer Date: Mon May 22 16:11:23 UTC 2017
Modified Files: src/sys/arch/arm/allwinner [bouyer-socketcan]: awin_can.c src/sys/netcan [bouyer-socketcan]: can.c can_var.h if_canloop.c Log Message: factor out if_attach() and bpf_attach() calls in can_ifattach(). Introduce can_ifdetach(). Introduce can_bpf_mtap(), which converts the can_id to network byte order (as required by tcpdump/wireshark). Thanks to Guy Harris for poiting this requirement. To generate a diff of this commit: cvs rdiff -u -r1.1.2.5 -r1.1.2.6 src/sys/arch/arm/allwinner/awin_can.c cvs rdiff -u -r1.1.2.13 -r1.1.2.14 src/sys/netcan/can.c cvs rdiff -u -r1.1.2.7 -r1.1.2.8 src/sys/netcan/can_var.h cvs rdiff -u -r1.1.2.6 -r1.1.2.7 src/sys/netcan/if_canloop.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/sys/arch/arm/allwinner/awin_can.c diff -u src/sys/arch/arm/allwinner/awin_can.c:1.1.2.5 src/sys/arch/arm/allwinner/awin_can.c:1.1.2.6 --- src/sys/arch/arm/allwinner/awin_can.c:1.1.2.5 Fri Apr 21 13:08:55 2017 +++ src/sys/arch/arm/allwinner/awin_can.c Mon May 22 16:11:23 2017 @@ -1,4 +1,4 @@ -/* $NetBSD: awin_can.c,v 1.1.2.5 2017/04/21 13:08:55 bouyer Exp $ */ +/* $NetBSD: awin_can.c,v 1.1.2.6 2017/05/22 16:11:23 bouyer Exp $ */ /*- * Copyright (c) 2017 The NetBSD Foundation, Inc. @@ -36,7 +36,7 @@ #include <sys/cdefs.h> -__KERNEL_RCSID(1, "$NetBSD: awin_can.c,v 1.1.2.5 2017/04/21 13:08:55 bouyer Exp $"); +__KERNEL_RCSID(1, "$NetBSD: awin_can.c,v 1.1.2.6 2017/05/22 16:11:23 bouyer Exp $"); #include <sys/param.h> #include <sys/bus.h> @@ -55,7 +55,6 @@ __KERNEL_RCSID(1, "$NetBSD: awin_can.c,v #include <netcan/can.h> #include <netcan/can_var.h> #endif -#include <net/bpf.h> #include <arm/allwinner/awin_reg.h> #include <arm/allwinner/awin_var.h> @@ -209,9 +208,7 @@ awin_can_attach(device_t parent, device_ /* * Attach the interface. */ - if_attach(ifp); can_ifattach(ifp); - bpf_attach(ifp, DLT_CAN_SOCKETCAN, 0); rnd_attach_source(&sc->sc_rnd_source, device_xname(self), RND_TYPE_NET, RND_FLAG_DEFAULT); #ifdef MBUFTRACE @@ -278,7 +275,7 @@ awin_can_rx_intr(struct awin_can_softc * ifp->if_ipackets++; ifp->if_ibytes += m->m_len; m_set_rcvif(m, ifp); - bpf_mtap(ifp, m); + can_bpf_mtap(ifp, m); can_input(ifp, m); } @@ -352,7 +349,7 @@ awin_can_tx_intr(struct awin_can_softc * } ifp->if_flags |= IFF_OACTIVE; ifp->if_timer = 5; - bpf_mtap(ifp, m); + can_bpf_mtap(ifp, m); } static int Index: src/sys/netcan/can.c diff -u src/sys/netcan/can.c:1.1.2.13 src/sys/netcan/can.c:1.1.2.14 --- src/sys/netcan/can.c:1.1.2.13 Sun Apr 23 21:05:09 2017 +++ src/sys/netcan/can.c Mon May 22 16:11:23 2017 @@ -1,4 +1,4 @@ -/* $NetBSD: can.c,v 1.1.2.13 2017/04/23 21:05:09 bouyer Exp $ */ +/* $NetBSD: can.c,v 1.1.2.14 2017/05/22 16:11:23 bouyer Exp $ */ /*- * Copyright (c) 2003, 2017 The NetBSD Foundation, Inc. @@ -30,7 +30,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: can.c,v 1.1.2.13 2017/04/23 21:05:09 bouyer Exp $"); +__KERNEL_RCSID(0, "$NetBSD: can.c,v 1.1.2.14 2017/05/22 16:11:23 bouyer Exp $"); #include <sys/param.h> #include <sys/systm.h> @@ -48,6 +48,7 @@ __KERNEL_RCSID(0, "$NetBSD: can.c,v 1.1. #include <net/if_types.h> #include <net/netisr.h> #include <net/route.h> +#include <net/bpf.h> #include <netcan/can.h> #include <netcan/can_pcb.h> @@ -192,7 +193,9 @@ can_purgeif(struct socket *so, struct if } void -can_ifattach(struct ifnet *ifp) { +can_ifattach(struct ifnet *ifp) +{ + if_attach(ifp); ifp->if_mtu = sizeof(struct can_frame); ifp->if_type = IFT_OTHER; ifp->if_hdrlen = 0; @@ -201,6 +204,14 @@ can_ifattach(struct ifnet *ifp) { ifp->if_output = NULL; /* unused */ IFQ_SET_READY(&ifp->if_snd); if_alloc_sadl(ifp); + bpf_attach(ifp, DLT_CAN_SOCKETCAN, 0); +} + +void +can_ifdetach(struct ifnet *ifp) +{ + bpf_detach(ifp); + if_detach(ifp); } void @@ -404,6 +415,20 @@ canintr(void) mutex_exit(softnet_lock); } +void +can_bpf_mtap(struct ifnet *ifp, struct mbuf *m) +{ + /* bpf wants the CAN id in network byte order */ + struct can_frame *cf; + canid_t oid; + + cf = mtod(m, struct can_frame *); + oid = cf->can_id; + cf->can_id = htonl(oid); + bpf_mtap(ifp, m); + cf->can_id = oid; +} + static int can_attach(struct socket *so, int proto) { Index: src/sys/netcan/can_var.h diff -u src/sys/netcan/can_var.h:1.1.2.7 src/sys/netcan/can_var.h:1.1.2.8 --- src/sys/netcan/can_var.h:1.1.2.7 Tue Apr 18 21:29:40 2017 +++ src/sys/netcan/can_var.h Mon May 22 16:11:23 2017 @@ -1,4 +1,4 @@ -/* $NetBSD: can_var.h,v 1.1.2.7 2017/04/18 21:29:40 bouyer Exp $ */ +/* $NetBSD: can_var.h,v 1.1.2.8 2017/05/22 16:11:23 bouyer Exp $ */ /*- * Copyright (c) 2003, 2017 The NetBSD Foundation, Inc. @@ -60,6 +60,7 @@ extern struct domain candomain; extern const struct pr_usrreqs can_usrreqs; void can_ifattach(struct ifnet *); +void can_ifdetach(struct ifnet *); void can_ifinit_timings(struct canif_softc *); void can_mbuf_tag_clean(struct mbuf *); void can_input(struct ifnet *, struct mbuf *); @@ -67,6 +68,7 @@ void *can_ctlinput(int, struct sockaddr int can_ctloutput(int, struct socket *, struct sockopt *); void can_init(void); void canintr(void); +void can_bpf_mtap(struct ifnet *, struct mbuf *); #endif Index: src/sys/netcan/if_canloop.c diff -u src/sys/netcan/if_canloop.c:1.1.2.6 src/sys/netcan/if_canloop.c:1.1.2.7 --- src/sys/netcan/if_canloop.c:1.1.2.6 Mon Apr 24 13:38:33 2017 +++ src/sys/netcan/if_canloop.c Mon May 22 16:11:23 2017 @@ -1,4 +1,4 @@ -/* $NetBSD: if_canloop.c,v 1.1.2.6 2017/04/24 13:38:33 bouyer Exp $ */ +/* $NetBSD: if_canloop.c,v 1.1.2.7 2017/05/22 16:11:23 bouyer Exp $ */ /*- * Copyright (c) 2017 The NetBSD Foundation, Inc. @@ -35,7 +35,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: if_canloop.c,v 1.1.2.6 2017/04/24 13:38:33 bouyer Exp $"); +__KERNEL_RCSID(0, "$NetBSD: if_canloop.c,v 1.1.2.7 2017/05/22 16:11:23 bouyer Exp $"); #ifdef _KERNEL_OPT #include "opt_can.h" @@ -62,7 +62,6 @@ __KERNEL_RCSID(0, "$NetBSD: if_canloop.c #ifdef CAN #include <netcan/can.h> #endif -#include <net/bpf.h> void canloopattach(int); void canloopinit(void); @@ -116,9 +115,7 @@ canloop_clone_create(struct if_clone *if ifp->if_extflags = IFEF_OUTPUT_MPSAFE; ifp->if_ioctl = canloop_ioctl; ifp->if_start = canloop_ifstart; - if_attach(ifp); can_ifattach(ifp); - bpf_attach(ifp, DLT_CAN_SOCKETCAN, 0); #ifdef MBUFTRACE ifp->if_mowner = malloc(sizeof(struct mowner), M_DEVBUF, M_WAITOK | M_ZERO); @@ -140,8 +137,7 @@ canloop_clone_destroy(struct ifnet *ifp) free(ifp->if_mowner, M_DEVBUF); #endif - bpf_detach(ifp); - if_detach(ifp); + can_ifdetach(ifp); if_free(ifp); canloop_count--; @@ -166,7 +162,7 @@ canloop_ifstart(struct ifnet *ifp) panic("canloop_output: no header mbuf"); m_set_rcvif(m, ifp); if (ifp->if_flags & IFF_LOOPBACK) - bpf_mtap(ifp, m); + can_bpf_mtap(ifp, m); pktlen = m->m_pkthdr.len; ifp->if_opackets++;