diff options
author | Joel Sherrill <joel.sherrill@OARcorp.com> | 1998-12-10 19:42:29 +0000 |
---|---|---|
committer | Joel Sherrill <joel.sherrill@OARcorp.com> | 1998-12-10 19:42:29 +0000 |
commit | a3d0b8a79a432820dee80b1583f1acf86d256e97 (patch) | |
tree | 7d399d0a3c740fc3fae41c7b06e5f05aaf44447e | |
parent | Patch from Ian Lance Taylor <ian@airs.com>: (diff) | |
download | rtems-a3d0b8a79a432820dee80b1583f1acf86d256e97.tar.bz2 |
Patch from Ian Lance Taylor <ian@airs.com>:
From: Eric Norum <eric@skatter.usask.ca>
Date: Sat, 5 Dec 98 13:20:51 -0600
What do you think of this patch? It implements your `tap'
suggestion in a way that adds support for all ethernet devices with
no driver modifications. I also added a return value from the tap
function. If the return value is zero, the packet will be passed up
the chain as usual. If the return value is non-zero the mbuf holding
the packet will be freed and the packet will be dropped.
If you like it, please submit it to Joel.
I guess there needs to be an addition to the network documentation
describing the additional ioctl's -- and a big warning that the tap
function is called from a context that holds the network semaphore.
Here is Eric's patch. I've tested it a bit, and made a couple of
trivial changes. This is certainly better than mine: it should work
for all Ethernet drivers.
==================================================
The only concern I have about this patch is that the tap function may
want to fiddle with the mbuf, calling functions like m_pullup and the
like. If those force the networking code to rearrange the mbuf
structure, then the caller's call to m_freem may crash. I don't know
if this is a realistic concern--I don't know enough about the mbuf
layer.
-rw-r--r-- | c/src/exec/libcsupport/include/sys/sockio.h | 7 | ||||
-rw-r--r-- | c/src/exec/libnetworking/net/if.c | 11 | ||||
-rw-r--r-- | c/src/exec/libnetworking/net/if.h | 4 | ||||
-rw-r--r-- | c/src/exec/libnetworking/net/if_ethersubr.c | 9 | ||||
-rw-r--r-- | c/src/lib/include/sys/sockio.h | 7 | ||||
-rw-r--r-- | c/src/lib/libnetworking/net/if.c | 11 | ||||
-rw-r--r-- | c/src/lib/libnetworking/net/if.h | 4 | ||||
-rw-r--r-- | c/src/lib/libnetworking/net/if_ethersubr.c | 9 | ||||
-rw-r--r-- | c/src/lib/libnetworking/sys/sockio.h | 7 | ||||
-rw-r--r-- | c/src/libnetworking/net/if.c | 11 | ||||
-rw-r--r-- | c/src/libnetworking/net/if.h | 4 | ||||
-rw-r--r-- | c/src/libnetworking/net/if_ethersubr.c | 9 | ||||
-rw-r--r-- | c/src/libnetworking/sys/sockio.h | 7 | ||||
-rw-r--r-- | cpukit/libcsupport/include/sys/sockio.h | 7 | ||||
-rw-r--r-- | cpukit/libnetworking/net/if.c | 11 | ||||
-rw-r--r-- | cpukit/libnetworking/net/if.h | 4 | ||||
-rw-r--r-- | cpukit/libnetworking/net/if_ethersubr.c | 9 |
17 files changed, 131 insertions, 0 deletions
diff --git a/c/src/exec/libcsupport/include/sys/sockio.h b/c/src/exec/libcsupport/include/sys/sockio.h index 020061170f..03ec16e43a 100644 --- a/c/src/exec/libcsupport/include/sys/sockio.h +++ b/c/src/exec/libcsupport/include/sys/sockio.h @@ -83,4 +83,11 @@ #define SIOCSIFMEDIA _IOWR('i', 55, struct ifreq) /* set net media */ #define SIOCGIFMEDIA _IOWR('i', 56, struct ifmediareq) /* get net media */ + +/* + * RTEMS additions for setting/getting `tap' function on incoming packets. + */ +#define SIOCSIFTAP _IOW('i', 80, struct ifreq) /* set tap function */ +#define SIOCGIFTAP _IOWR('i', 81, struct ifreq) /* get tap function */ + #endif /* !_SYS_SOCKIO_H_ */ diff --git a/c/src/exec/libnetworking/net/if.c b/c/src/exec/libnetworking/net/if.c index af6f003de3..6f42b29903 100644 --- a/c/src/exec/libnetworking/net/if.c +++ b/c/src/exec/libnetworking/net/if.c @@ -664,6 +664,17 @@ ifioctl(so, cmd, data, p) } #endif + + /* + * RTEMS additions for setting/getting `tap' function + */ + case SIOCSIFTAP: + ifp->if_tap = ifr->ifr_tap; + return 0; + + case SIOCGIFTAP: + ifr->ifr_tap = ifp->if_tap; + return 0; } return (0); } diff --git a/c/src/exec/libnetworking/net/if.h b/c/src/exec/libnetworking/net/if.h index acddd4f095..16785d7626 100644 --- a/c/src/exec/libnetworking/net/if.h +++ b/c/src/exec/libnetworking/net/if.h @@ -162,6 +162,8 @@ struct ifnet { __P((struct ifnet *, struct mbuf *)); void (*if_init) /* Init routine */ __P((void *)); + int (*if_tap) /* Packet filter routine */ + (struct ifnet *, struct ether_header *, struct mbuf *); struct ifqueue if_snd; /* output queue */ struct ifqueue *if_poll_slowq; /* input queue for slow devices */ }; @@ -369,6 +371,7 @@ struct ifreq { int ifru_phys; int ifru_media; caddr_t ifru_data; + int (*ifru_tap)(struct ifnet *, struct ether_header *, struct mbuf *); } ifr_ifru; #define ifr_addr ifr_ifru.ifru_addr /* address */ #define ifr_dstaddr ifr_ifru.ifru_dstaddr /* other end of p-to-p link */ @@ -379,6 +382,7 @@ struct ifreq { #define ifr_phys ifr_ifru.ifru_phys /* physical wire */ #define ifr_media ifr_ifru.ifru_media /* physical media */ #define ifr_data ifr_ifru.ifru_data /* for use by interface */ +#define ifr_tap ifr_ifru.ifru_tap /* tap function */ }; struct ifaliasreq { diff --git a/c/src/exec/libnetworking/net/if_ethersubr.c b/c/src/exec/libnetworking/net/if_ethersubr.c index 4d1675ca3c..2a6446ebb6 100644 --- a/c/src/exec/libnetworking/net/if_ethersubr.c +++ b/c/src/exec/libnetworking/net/if_ethersubr.c @@ -483,6 +483,15 @@ ether_input(ifp, eh, m) if (m->m_flags & (M_BCAST|M_MCAST)) ifp->if_imcasts++; + /* + * RTEMS addition -- allow application to `tap into' + * the incoming packet stream. + */ + if (ifp->if_tap && (*ifp->if_tap)(ifp, eh, m)) { + m_freem(m); + return; + } + ether_type = ntohs(eh->ether_type); switch (ether_type) { diff --git a/c/src/lib/include/sys/sockio.h b/c/src/lib/include/sys/sockio.h index 020061170f..03ec16e43a 100644 --- a/c/src/lib/include/sys/sockio.h +++ b/c/src/lib/include/sys/sockio.h @@ -83,4 +83,11 @@ #define SIOCSIFMEDIA _IOWR('i', 55, struct ifreq) /* set net media */ #define SIOCGIFMEDIA _IOWR('i', 56, struct ifmediareq) /* get net media */ + +/* + * RTEMS additions for setting/getting `tap' function on incoming packets. + */ +#define SIOCSIFTAP _IOW('i', 80, struct ifreq) /* set tap function */ +#define SIOCGIFTAP _IOWR('i', 81, struct ifreq) /* get tap function */ + #endif /* !_SYS_SOCKIO_H_ */ diff --git a/c/src/lib/libnetworking/net/if.c b/c/src/lib/libnetworking/net/if.c index af6f003de3..6f42b29903 100644 --- a/c/src/lib/libnetworking/net/if.c +++ b/c/src/lib/libnetworking/net/if.c @@ -664,6 +664,17 @@ ifioctl(so, cmd, data, p) } #endif + + /* + * RTEMS additions for setting/getting `tap' function + */ + case SIOCSIFTAP: + ifp->if_tap = ifr->ifr_tap; + return 0; + + case SIOCGIFTAP: + ifr->ifr_tap = ifp->if_tap; + return 0; } return (0); } diff --git a/c/src/lib/libnetworking/net/if.h b/c/src/lib/libnetworking/net/if.h index acddd4f095..16785d7626 100644 --- a/c/src/lib/libnetworking/net/if.h +++ b/c/src/lib/libnetworking/net/if.h @@ -162,6 +162,8 @@ struct ifnet { __P((struct ifnet *, struct mbuf *)); void (*if_init) /* Init routine */ __P((void *)); + int (*if_tap) /* Packet filter routine */ + (struct ifnet *, struct ether_header *, struct mbuf *); struct ifqueue if_snd; /* output queue */ struct ifqueue *if_poll_slowq; /* input queue for slow devices */ }; @@ -369,6 +371,7 @@ struct ifreq { int ifru_phys; int ifru_media; caddr_t ifru_data; + int (*ifru_tap)(struct ifnet *, struct ether_header *, struct mbuf *); } ifr_ifru; #define ifr_addr ifr_ifru.ifru_addr /* address */ #define ifr_dstaddr ifr_ifru.ifru_dstaddr /* other end of p-to-p link */ @@ -379,6 +382,7 @@ struct ifreq { #define ifr_phys ifr_ifru.ifru_phys /* physical wire */ #define ifr_media ifr_ifru.ifru_media /* physical media */ #define ifr_data ifr_ifru.ifru_data /* for use by interface */ +#define ifr_tap ifr_ifru.ifru_tap /* tap function */ }; struct ifaliasreq { diff --git a/c/src/lib/libnetworking/net/if_ethersubr.c b/c/src/lib/libnetworking/net/if_ethersubr.c index 4d1675ca3c..2a6446ebb6 100644 --- a/c/src/lib/libnetworking/net/if_ethersubr.c +++ b/c/src/lib/libnetworking/net/if_ethersubr.c @@ -483,6 +483,15 @@ ether_input(ifp, eh, m) if (m->m_flags & (M_BCAST|M_MCAST)) ifp->if_imcasts++; + /* + * RTEMS addition -- allow application to `tap into' + * the incoming packet stream. + */ + if (ifp->if_tap && (*ifp->if_tap)(ifp, eh, m)) { + m_freem(m); + return; + } + ether_type = ntohs(eh->ether_type); switch (ether_type) { diff --git a/c/src/lib/libnetworking/sys/sockio.h b/c/src/lib/libnetworking/sys/sockio.h index 020061170f..03ec16e43a 100644 --- a/c/src/lib/libnetworking/sys/sockio.h +++ b/c/src/lib/libnetworking/sys/sockio.h @@ -83,4 +83,11 @@ #define SIOCSIFMEDIA _IOWR('i', 55, struct ifreq) /* set net media */ #define SIOCGIFMEDIA _IOWR('i', 56, struct ifmediareq) /* get net media */ + +/* + * RTEMS additions for setting/getting `tap' function on incoming packets. + */ +#define SIOCSIFTAP _IOW('i', 80, struct ifreq) /* set tap function */ +#define SIOCGIFTAP _IOWR('i', 81, struct ifreq) /* get tap function */ + #endif /* !_SYS_SOCKIO_H_ */ diff --git a/c/src/libnetworking/net/if.c b/c/src/libnetworking/net/if.c index af6f003de3..6f42b29903 100644 --- a/c/src/libnetworking/net/if.c +++ b/c/src/libnetworking/net/if.c @@ -664,6 +664,17 @@ ifioctl(so, cmd, data, p) } #endif + + /* + * RTEMS additions for setting/getting `tap' function + */ + case SIOCSIFTAP: + ifp->if_tap = ifr->ifr_tap; + return 0; + + case SIOCGIFTAP: + ifr->ifr_tap = ifp->if_tap; + return 0; } return (0); } diff --git a/c/src/libnetworking/net/if.h b/c/src/libnetworking/net/if.h index acddd4f095..16785d7626 100644 --- a/c/src/libnetworking/net/if.h +++ b/c/src/libnetworking/net/if.h @@ -162,6 +162,8 @@ struct ifnet { __P((struct ifnet *, struct mbuf *)); void (*if_init) /* Init routine */ __P((void *)); + int (*if_tap) /* Packet filter routine */ + (struct ifnet *, struct ether_header *, struct mbuf *); struct ifqueue if_snd; /* output queue */ struct ifqueue *if_poll_slowq; /* input queue for slow devices */ }; @@ -369,6 +371,7 @@ struct ifreq { int ifru_phys; int ifru_media; caddr_t ifru_data; + int (*ifru_tap)(struct ifnet *, struct ether_header *, struct mbuf *); } ifr_ifru; #define ifr_addr ifr_ifru.ifru_addr /* address */ #define ifr_dstaddr ifr_ifru.ifru_dstaddr /* other end of p-to-p link */ @@ -379,6 +382,7 @@ struct ifreq { #define ifr_phys ifr_ifru.ifru_phys /* physical wire */ #define ifr_media ifr_ifru.ifru_media /* physical media */ #define ifr_data ifr_ifru.ifru_data /* for use by interface */ +#define ifr_tap ifr_ifru.ifru_tap /* tap function */ }; struct ifaliasreq { diff --git a/c/src/libnetworking/net/if_ethersubr.c b/c/src/libnetworking/net/if_ethersubr.c index 4d1675ca3c..2a6446ebb6 100644 --- a/c/src/libnetworking/net/if_ethersubr.c +++ b/c/src/libnetworking/net/if_ethersubr.c @@ -483,6 +483,15 @@ ether_input(ifp, eh, m) if (m->m_flags & (M_BCAST|M_MCAST)) ifp->if_imcasts++; + /* + * RTEMS addition -- allow application to `tap into' + * the incoming packet stream. + */ + if (ifp->if_tap && (*ifp->if_tap)(ifp, eh, m)) { + m_freem(m); + return; + } + ether_type = ntohs(eh->ether_type); switch (ether_type) { diff --git a/c/src/libnetworking/sys/sockio.h b/c/src/libnetworking/sys/sockio.h index 020061170f..03ec16e43a 100644 --- a/c/src/libnetworking/sys/sockio.h +++ b/c/src/libnetworking/sys/sockio.h @@ -83,4 +83,11 @@ #define SIOCSIFMEDIA _IOWR('i', 55, struct ifreq) /* set net media */ #define SIOCGIFMEDIA _IOWR('i', 56, struct ifmediareq) /* get net media */ + +/* + * RTEMS additions for setting/getting `tap' function on incoming packets. + */ +#define SIOCSIFTAP _IOW('i', 80, struct ifreq) /* set tap function */ +#define SIOCGIFTAP _IOWR('i', 81, struct ifreq) /* get tap function */ + #endif /* !_SYS_SOCKIO_H_ */ diff --git a/cpukit/libcsupport/include/sys/sockio.h b/cpukit/libcsupport/include/sys/sockio.h index 020061170f..03ec16e43a 100644 --- a/cpukit/libcsupport/include/sys/sockio.h +++ b/cpukit/libcsupport/include/sys/sockio.h @@ -83,4 +83,11 @@ #define SIOCSIFMEDIA _IOWR('i', 55, struct ifreq) /* set net media */ #define SIOCGIFMEDIA _IOWR('i', 56, struct ifmediareq) /* get net media */ + +/* + * RTEMS additions for setting/getting `tap' function on incoming packets. + */ +#define SIOCSIFTAP _IOW('i', 80, struct ifreq) /* set tap function */ +#define SIOCGIFTAP _IOWR('i', 81, struct ifreq) /* get tap function */ + #endif /* !_SYS_SOCKIO_H_ */ diff --git a/cpukit/libnetworking/net/if.c b/cpukit/libnetworking/net/if.c index af6f003de3..6f42b29903 100644 --- a/cpukit/libnetworking/net/if.c +++ b/cpukit/libnetworking/net/if.c @@ -664,6 +664,17 @@ ifioctl(so, cmd, data, p) } #endif + + /* + * RTEMS additions for setting/getting `tap' function + */ + case SIOCSIFTAP: + ifp->if_tap = ifr->ifr_tap; + return 0; + + case SIOCGIFTAP: + ifr->ifr_tap = ifp->if_tap; + return 0; } return (0); } diff --git a/cpukit/libnetworking/net/if.h b/cpukit/libnetworking/net/if.h index acddd4f095..16785d7626 100644 --- a/cpukit/libnetworking/net/if.h +++ b/cpukit/libnetworking/net/if.h @@ -162,6 +162,8 @@ struct ifnet { __P((struct ifnet *, struct mbuf *)); void (*if_init) /* Init routine */ __P((void *)); + int (*if_tap) /* Packet filter routine */ + (struct ifnet *, struct ether_header *, struct mbuf *); struct ifqueue if_snd; /* output queue */ struct ifqueue *if_poll_slowq; /* input queue for slow devices */ }; @@ -369,6 +371,7 @@ struct ifreq { int ifru_phys; int ifru_media; caddr_t ifru_data; + int (*ifru_tap)(struct ifnet *, struct ether_header *, struct mbuf *); } ifr_ifru; #define ifr_addr ifr_ifru.ifru_addr /* address */ #define ifr_dstaddr ifr_ifru.ifru_dstaddr /* other end of p-to-p link */ @@ -379,6 +382,7 @@ struct ifreq { #define ifr_phys ifr_ifru.ifru_phys /* physical wire */ #define ifr_media ifr_ifru.ifru_media /* physical media */ #define ifr_data ifr_ifru.ifru_data /* for use by interface */ +#define ifr_tap ifr_ifru.ifru_tap /* tap function */ }; struct ifaliasreq { diff --git a/cpukit/libnetworking/net/if_ethersubr.c b/cpukit/libnetworking/net/if_ethersubr.c index 4d1675ca3c..2a6446ebb6 100644 --- a/cpukit/libnetworking/net/if_ethersubr.c +++ b/cpukit/libnetworking/net/if_ethersubr.c @@ -483,6 +483,15 @@ ether_input(ifp, eh, m) if (m->m_flags & (M_BCAST|M_MCAST)) ifp->if_imcasts++; + /* + * RTEMS addition -- allow application to `tap into' + * the incoming packet stream. + */ + if (ifp->if_tap && (*ifp->if_tap)(ifp, eh, m)) { + m_freem(m); + return; + } + ether_type = ntohs(eh->ether_type); switch (ether_type) { |