View | Details | Raw Unified | Return to bug 220076 | Differences between
and this patch

Collapse All | Expand All

(-)sys/netgraph/ng_iface.c (-1 / +19 lines)
Lines 64-69 Link Here
64
#include <sys/errno.h>
64
#include <sys/errno.h>
65
#include <sys/proc.h>
65
#include <sys/proc.h>
66
#include <sys/random.h>
66
#include <sys/random.h>
67
#include <sys/rmlock.h>
67
#include <sys/sockio.h>
68
#include <sys/sockio.h>
68
#include <sys/socket.h>
69
#include <sys/socket.h>
69
#include <sys/syslog.h>
70
#include <sys/syslog.h>
Lines 112-120 struct ng_iface_private { Link Here
112
	int	unit;			/* Interface unit number */
113
	int	unit;			/* Interface unit number */
113
	node_p	node;			/* Our netgraph node */
114
	node_p	node;			/* Our netgraph node */
114
	hook_p	hooks[NUM_FAMILIES];	/* Hook for each address family */
115
	hook_p	hooks[NUM_FAMILIES];	/* Hook for each address family */
116
	struct rmlock	lock;		/* Protect private data changes */
115
};
117
};
116
typedef struct ng_iface_private *priv_p;
118
typedef struct ng_iface_private *priv_p;
117
119
120
#define	PRIV_RLOCK(priv, t)	rm_rlock(&priv->lock, t)
121
#define	PRIV_RUNLOCK(priv, t)	rm_runlock(&priv->lock, t)
122
#define	PRIV_WLOCK(priv)	rm_wlock(&priv->lock)
123
#define	PRIV_WUNLOCK(priv)	rm_wunlock(&priv->lock)
124
118
/* Interface methods */
125
/* Interface methods */
119
static void	ng_iface_start(struct ifnet *ifp);
126
static void	ng_iface_start(struct ifnet *ifp);
120
static int	ng_iface_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data);
127
static int	ng_iface_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data);
Lines 431-436 ng_iface_bpftap(struct ifnet *ifp, struc Link Here
431
static int
438
static int
432
ng_iface_send(struct ifnet *ifp, struct mbuf *m, sa_family_t sa)
439
ng_iface_send(struct ifnet *ifp, struct mbuf *m, sa_family_t sa)
433
{
440
{
441
	struct rm_priotracker priv_tracker;
434
	const priv_p priv = (priv_p) ifp->if_softc;
442
	const priv_p priv = (priv_p) ifp->if_softc;
435
	const iffam_p iffam = get_iffam_from_af(sa);
443
	const iffam_p iffam = get_iffam_from_af(sa);
436
	int error;
444
	int error;
Lines 448-454 ng_iface_send(struct ifnet *ifp, struct Link Here
448
456
449
	/* Send packet. If hook is not connected, mbuf will get freed. */
457
	/* Send packet. If hook is not connected, mbuf will get freed. */
450
	NG_OUTBOUND_THREAD_REF();
458
	NG_OUTBOUND_THREAD_REF();
459
	PRIV_RLOCK(priv, &priv_tracker);
451
	NG_SEND_DATA_ONLY(error, *get_hook_from_iffam(priv, iffam), m);
460
	NG_SEND_DATA_ONLY(error, *get_hook_from_iffam(priv, iffam), m);
461
	PRIV_RUNLOCK(priv, &priv_tracker);
452
	NG_OUTBOUND_THREAD_UNREF();
462
	NG_OUTBOUND_THREAD_UNREF();
453
463
454
	/* Update stats. */
464
	/* Update stats. */
Lines 516-521 ng_iface_constructor(node_p node) Link Here
516
		return (ENOMEM);
526
		return (ENOMEM);
517
	}
527
	}
518
528
529
	rm_init(&priv->lock, "ng_iface private rmlock");
530
519
	/* Link them together */
531
	/* Link them together */
520
	ifp->if_softc = priv;
532
	ifp->if_softc = priv;
521
	priv->ifp = ifp;
533
	priv->ifp = ifp;
Lines 562-577 static int Link Here
562
ng_iface_newhook(node_p node, hook_p hook, const char *name)
574
ng_iface_newhook(node_p node, hook_p hook, const char *name)
563
{
575
{
564
	const iffam_p iffam = get_iffam_from_name(name);
576
	const iffam_p iffam = get_iffam_from_name(name);
577
	const priv_p priv = NG_NODE_PRIVATE(node);
565
	hook_p *hookptr;
578
	hook_p *hookptr;
566
579
567
	if (iffam == NULL)
580
	if (iffam == NULL)
568
		return (EPFNOSUPPORT);
581
		return (EPFNOSUPPORT);
569
	hookptr = get_hook_from_iffam(NG_NODE_PRIVATE(node), iffam);
582
	PRIV_WLOCK(priv);
583
	hookptr = get_hook_from_iffam(priv, iffam);
570
	if (*hookptr != NULL)
584
	if (*hookptr != NULL)
571
		return (EISCONN);
585
		return (EISCONN);
572
	*hookptr = hook;
586
	*hookptr = hook;
573
	NG_HOOK_HI_STACK(hook);
587
	NG_HOOK_HI_STACK(hook);
574
	NG_HOOK_SET_TO_INBOUND(hook);
588
	NG_HOOK_SET_TO_INBOUND(hook);
589
	PRIV_WUNLOCK(priv);
575
	return (0);
590
	return (0);
576
}
591
}
577
592
Lines 730-735 ng_iface_shutdown(node_p node) Link Here
730
	CURVNET_RESTORE();
745
	CURVNET_RESTORE();
731
	priv->ifp = NULL;
746
	priv->ifp = NULL;
732
	free_unr(V_ng_iface_unit, priv->unit);
747
	free_unr(V_ng_iface_unit, priv->unit);
748
	rm_destroy(&priv->lock);
733
	free(priv, M_NETGRAPH_IFACE);
749
	free(priv, M_NETGRAPH_IFACE);
734
	NG_NODE_SET_PRIVATE(node, NULL);
750
	NG_NODE_SET_PRIVATE(node, NULL);
735
	NG_NODE_UNREF(node);
751
	NG_NODE_UNREF(node);
Lines 748-754 ng_iface_disconnect(hook_p hook) Link Here
748
764
749
	if (iffam == NULL)
765
	if (iffam == NULL)
750
		panic("%s", __func__);
766
		panic("%s", __func__);
767
	PRIV_WLOCK(priv);
751
	*get_hook_from_iffam(priv, iffam) = NULL;
768
	*get_hook_from_iffam(priv, iffam) = NULL;
769
	PRIV_WUNLOCK(priv);
752
	return (0);
770
	return (0);
753
}
771
}
754
772

Return to bug 220076