PERFORCE change 45573 for review
Scott Long
scottl at FreeBSD.org
Sun Jan 18 18:01:44 PST 2004
http://perforce.freebsd.org/chv.cgi?CH=45573
Change 45573 by scottl at scottl_netperf_socket on 2004/01/18 18:00:45
Fix some mis-merges.
Affected files ...
.. //depot/projects/netperf_socket/sys/net/if_ethersubr.c#2 integrate
.. //depot/projects/netperf_socket/sys/netinet/ip_fastfwd.c#3 integrate
Differences ...
==== //depot/projects/netperf_socket/sys/net/if_ethersubr.c#2 (text+ko) ====
@@ -96,9 +96,6 @@
#endif /* NETATALK */
/* netgraph node hooks for ng_ether(4) */
-void (*ng_ether_input_p)(struct ifnet *ifp, struct mbuf **mp);
-void (*ng_ether_input_orphan_p)(struct ifnet *ifp, struct mbuf *m);
-int (*ng_ether_output_p)(struct ifnet *ifp, struct mbuf **mp);
void (*ng_ether_attach_p)(struct ifnet *ifp);
void (*ng_ether_detach_p)(struct ifnet *ifp);
@@ -111,6 +108,10 @@
bdgtakeifaces_t *bdgtakeifaces_ptr;
struct bdg_softc *ifp2sc;
+#ifdef PFIL_HOOKS
+struct pfil_head ether_pfil_hook;
+#endif
+
static u_char etherbroadcastaddr[ETHER_ADDR_LEN] =
{ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
@@ -297,20 +298,20 @@
return (0); /* XXX */
}
}
-
- /* Handle ng_ether(4) processing, if any */
- if (ng_ether_output_p != NULL) {
- if ((error = (*ng_ether_output_p)(ifp, &m)) != 0) {
-bad: if (m != NULL)
- m_freem(m);
- return (error);
- }
- if (m == NULL)
- return (0);
- }
-
+#ifdef PFIL_HOOKS
+ /*
+ * Run through list of hooks for output packets.
+ */
+ error = pfil_run_hooks(ðer_pfil_hook, &m, ifp, PFIL_OUT);
+ if (error != 0 || m == NULL)
+ goto bad;
+#endif
/* Continue with link-layer output */
return ether_output_frame(ifp, m);
+bad:
+ if (m != NULL)
+ m_freem(m);
+ return (error);
}
/*
@@ -322,12 +323,7 @@
int
ether_output_frame(struct ifnet *ifp, struct mbuf *m)
{
- struct ip_fw *rule = NULL;
-
- /* Extract info from dummynet tag, ignore others */
- for (; m->m_type == MT_TAG; m = m->m_next)
- if (m->m_flags == PACKET_TAG_DUMMYNET)
- rule = ((struct dn_pkt *)m)->rule;
+ struct ip_fw *rule = ip_dn_find_rule(m);
if (rule == NULL && BDG_ACTIVE(ifp)) {
/*
@@ -397,7 +393,6 @@
args.m = m; /* the packet we are looking at */
args.oif = dst; /* destination, if any */
- args.divert_rule = 0; /* we do not support divert yet */
args.rule = *rule; /* matching rule to restart */
args.next_hop = NULL; /* we do not support forward yet */
args.eh = &save_eh; /* MAC header for bridged/MAC packets */
@@ -536,14 +531,15 @@
}
ifp->if_ibytes += m->m_pkthdr.len;
-
- /* Handle ng_ether(4) processing, if any */
- if (ng_ether_input_p != NULL) {
- (*ng_ether_input_p)(ifp, &m);
- if (m == NULL)
- return;
- }
-
+#ifdef PFIL_HOOKS
+ /*
+ * Run through list of hooks for input packets.
+ */
+ if (pfil_run_hooks(&inet_pfil_hook, &m, ifp, PFIL_IN) != 0)
+ return;
+ if (m == NULL) /* consumed by filter */
+ return;
+#endif
/* Check for bridging mode */
if (BDG_ACTIVE(ifp) ) {
struct ifnet *bif;
@@ -611,14 +607,7 @@
#if defined(NETATALK)
struct llc *l;
#endif
- struct ip_fw *rule = NULL;
-
- /* Extract info from dummynet tag, ignore others */
- for (;m->m_type == MT_TAG; m = m->m_next)
- if (m->m_flags == PACKET_TAG_DUMMYNET) {
- rule = ((struct dn_pkt *)m)->rule;
- ifp = m->m_next->m_pkthdr.rcvif;
- }
+ struct ip_fw *rule = ip_dn_find_rule(m);
KASSERT(ifp != NULL, ("ether_demux: NULL interface pointer"));
@@ -783,20 +772,20 @@
discard:
/*
- * Packet is to be discarded. If netgraph is present,
- * hand the packet to it for last chance processing;
- * otherwise dispose of it.
+ * Packet is to be discarded. If let hooks have a
+ * last go at it before we reclaim storage.
+ */
+#ifdef PFIL_HOOKS
+ /*
+ * Put back the ethernet header so hooks have a
+ * consistent view of inbound packets.
*/
- if (ng_ether_input_orphan_p != NULL) {
- /*
- * Put back the ethernet header so netgraph has a
- * consistent view of inbound packets.
- */
- M_PREPEND(m, ETHER_HDR_LEN, M_DONTWAIT);
- (*ng_ether_input_orphan_p)(ifp, m);
- return;
- }
- m_freem(m);
+ M_PREPEND(m, ETHER_HDR_LEN, M_DONTWAIT);
+ if (pfil_run_hooks(ðer_pfil_hook, &m, ifp, PFIL_IN_DISCARD) != 0)
+ m = NULL; /* hook consumed packet, don't free */
+#endif
+ if (m != NULL)
+ m_freem(m);
}
/*
@@ -1029,11 +1018,53 @@
}
}
+static int
+ether_modinit(void)
+{
+#ifdef PFIL_HOOKS
+ int error;
+
+ ether_pfil_hook.ph_type = PFIL_TYPE_AF;
+ ether_pfil_hook.ph_af = AF_LINK; /* XXX */
+ error = pfil_head_register(ðer_pfil_hook);
+ if (error != 0)
+ printf("%s: Unable to register hook, error %d\n",
+ __func__, error);
+ return error;
+#else
+ return 0;
+#endif
+}
+
+static int
+ether_moddestroy(void)
+{
+#ifdef PFIL_HOOKS
+ (void) pfil_head_unregister(ðer_pfil_hook);
+#endif
+ return 0;
+}
+
+/*
+ * Module glue.
+ */
+static int
+ether_modevent(module_t mod, int type, void *unused)
+{
+ switch (type) {
+ case MOD_LOAD:
+ return ether_modinit();
+ case MOD_UNLOAD:
+ return ether_moddestroy();
+ }
+ return EINVAL;
+}
+
static moduledata_t ether_mod = {
- "ether",
- NULL,
- 0
+ "ether",
+ ether_modevent,
+ 0
};
-
-DECLARE_MODULE(ether, ether_mod, SI_SUB_PSEUDO, SI_ORDER_ANY);
+
+DECLARE_MODULE(ether, ether_mod, SI_SUB_PSEUDO, SI_ORDER_FIRST);
MODULE_VERSION(ether, 1);
==== //depot/projects/netperf_socket/sys/netinet/ip_fastfwd.c#3 (text+ko) ====
@@ -110,6 +110,7 @@
#include <machine/in_cksum.h>
#include <netinet/ip_fw.h>
+#include <netinet/ip_divert.h>
#include <netinet/ip_dummynet.h>
static int ipfastforward_active = 0;
@@ -132,7 +133,7 @@
struct ip *tip;
struct mbuf *teem = NULL;
#endif
- struct mbuf *tag = NULL;
+ struct m_tag *mtag;
struct route ro;
struct sockaddr_in *dst = NULL;
struct in_ifaddr *ia = NULL;
@@ -150,16 +151,6 @@
if (!ipfastforward_active || !ipforwarding)
return 0;
- /*
- * If there is any MT_TAG we fall back to ip_input because we can't
- * handle TAGs here. Should never happen as we get directly called
- * from the if_output routines.
- */
- if (m->m_type == MT_TAG) {
- KASSERT(0, ("%s: packet with MT_TAG not expected", __func__));
- return 0;
- }
-
M_ASSERTVALID(m);
M_ASSERTPKTHDR(m);
@@ -373,25 +364,13 @@
/*
* See if this is a fragment
*/
- if (ip->ip_off & (IP_MF | IP_OFFMASK)) {
- MGETHDR(tag, M_DONTWAIT, MT_TAG);
- if (tag == NULL)
- goto drop;
- tag->m_flags = PACKET_TAG_DIVERT;
- tag->m_data = (caddr_t)(intptr_t)args.divert_rule;
- tag->m_next = m;
- /* XXX: really bloody hack, see ip_input */
- tag->m_nextpkt = (struct mbuf *)1;
- m = tag;
- tag = NULL;
-
+ if (ip->ip_off & (IP_MF | IP_OFFMASK))
goto droptoours;
- }
/*
* Tee packet
*/
if ((ipfw & IP_FW_PORT_TEE_FLAG) != 0)
- teem = m_dup(m, M_DONTWAIT);
+ teem = divert_clone(m);
else
teem = m;
if (teem == NULL)
@@ -413,7 +392,7 @@
/*
* Deliver packet to divert input routine
*/
- divert_packet(teem, 0, ipfw & 0xffff, args.divert_rule);
+ divert_packet(teem, 0);
/*
* If this was not tee, we are done
*/
@@ -560,27 +539,13 @@
/*
* See if this is a fragment
*/
- if (ip->ip_off & (IP_MF | IP_OFFMASK)) {
- MGETHDR(tag, M_DONTWAIT, MT_TAG);
- if (tag == NULL) {
- RTFREE(ro.ro_rt);
- goto drop;
- }
- tag->m_flags = PACKET_TAG_DIVERT;
- tag->m_data = (caddr_t)(intptr_t)args.divert_rule;
- tag->m_next = m;
- /* XXX: really bloody hack, see ip_input */
- tag->m_nextpkt = (struct mbuf *)1;
- m = tag;
- tag = NULL;
-
+ if (ip->ip_off & (IP_MF | IP_OFFMASK))
goto droptoours;
- }
/*
* Tee packet
*/
if ((ipfw & IP_FW_PORT_TEE_FLAG) != 0)
- teem = m_dup(m, M_DONTWAIT);
+ teem = divert_clone(m);
else
teem = m;
if (teem == NULL)
@@ -602,7 +567,7 @@
/*
* Deliver packet to divert input routine
*/
- divert_packet(teem, 0, ipfw & 0xffff, args.divert_rule);
+ divert_packet(teem, 0);
/*
* If this was not tee, we are done
*/
@@ -638,38 +603,24 @@
if (IA_SIN(ia)->sin_addr.s_addr == ip->ip_dst.s_addr) {
forwardlocal:
if (args.next_hop) {
- /* XXX leak */
- MGETHDR(tag, M_DONTWAIT, MT_TAG);
- if (tag == NULL) {
+ mtag = m_tag_get(PACKET_TAG_IPFORWARD,
+ sizeof(struct sockaddr_in *),
+ M_NOWAIT);
+ if (mtag == NULL) {
+ /* XXX statistic */
if (ro.ro_rt)
RTFREE(ro.ro_rt);
goto drop;
}
- tag->m_flags = PACKET_TAG_IPFORWARD;
- tag->m_data = (caddr_t)args.next_hop;
- tag->m_next = m;
- /* XXX: really bloody hack,
- * see ip_input */
- tag->m_nextpkt = (struct mbuf *)1;
- m = tag;
- tag = NULL;
+ *(struct sockaddr_in **)(mtag+1) =
+ args.next_hop;
+ m_tag_prepend(m, mtag);
}
#ifdef IPDIVERT
droptoours: /* Used for DIVERT */
#endif
- MGETHDR(tag, M_DONTWAIT, MT_TAG);
- if (tag == NULL) {
- if (ro.ro_rt)
- RTFREE(ro.ro_rt);
- goto drop;
- }
- tag->m_flags = PACKET_TAG_IPFASTFWD_OURS;
- tag->m_data = NULL;
- tag->m_next = m;
- /* XXX: really bloody hack, see ip_input */
- tag->m_nextpkt = (struct mbuf *)1;
- m = tag;
- tag = NULL;
+ /* NB: ip_input understands this */
+ m->m_flags |= M_FASTFWD_OURS;
/* ip still points to the real packet */
ip->ip_len = htons(ip->ip_len);
More information about the p4-projects
mailing list