Deleted Added
sdiff udiff text old ( 63543 ) new ( 64358 )
full compact
1
2/*
3 * ng_ether.c
4 *
5 * Copyright (c) 1996-2000 Whistle Communications, Inc.
6 * All rights reserved.
7 *
8 * Subject to the following obligations and disclaimer of warranty, use and

--- 23 unchanged lines hidden (view full) ---

32 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
33 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
34 * THIS SOFTWARE, EVEN IF WHISTLE COMMUNICATIONS IS ADVISED OF THE POSSIBILITY
35 * OF SUCH DAMAGE.
36 *
37 * Authors: Archie Cobbs <archie@freebsd.org>
38 * Julian Elischer <julian@freebsd.org>
39 *
40 * $FreeBSD: head/sys/netgraph/ng_ether.c 63543 2000-07-19 17:33:53Z archie $
41 */
42
43/*
44 * ng_ether(4) netgraph node type
45 */
46
47#include <sys/param.h>
48#include <sys/systm.h>

--- 19 unchanged lines hidden (view full) ---

68#define IFP2NG(ifp) ((struct ng_node *)((struct arpcom *)(ifp))->ac_netgraph)
69
70/* Per-node private data */
71struct private {
72 struct ifnet *ifp; /* associated interface */
73 hook_p upper; /* upper hook connection */
74 hook_p lower; /* lower OR orphan hook connection */
75 u_char lowerOrphan; /* whether lower is lower or orphan */
76};
77typedef struct private *priv_p;
78
79/* Functional hooks called from if_ethersubr.c */
80static void ng_ether_input(struct ifnet *ifp,
81 struct mbuf **mp, struct ether_header *eh);
82static void ng_ether_input_orphan(struct ifnet *ifp,
83 struct mbuf *m, struct ether_header *eh);

--- 13 unchanged lines hidden (view full) ---

97static ng_constructor_t ng_ether_constructor;
98static ng_rcvmsg_t ng_ether_rcvmsg;
99static ng_shutdown_t ng_ether_rmnode;
100static ng_newhook_t ng_ether_newhook;
101static ng_rcvdata_t ng_ether_rcvdata;
102static ng_disconnect_t ng_ether_disconnect;
103static int ng_ether_mod_event(module_t mod, int event, void *data);
104
105/* List of commands and how to convert arguments to/from ASCII */
106static const struct ng_cmdlist ng_ether_cmdlist[] = {
107 {
108 NGM_ETHER_COOKIE,
109 NGM_ETHER_GET_IFNAME,
110 "getifname",
111 NULL,
112 &ng_parse_string_type
113 },
114 {
115 NGM_ETHER_COOKIE,
116 NGM_ETHER_GET_IFINDEX,
117 "getifindex",
118 NULL,
119 &ng_parse_int32_type
120 },
121 { 0 }
122};
123
124static struct ng_type ng_ether_typestruct = {
125 NG_VERSION,
126 NG_ETHER_NODE_TYPE,
127 ng_ether_mod_event,
128 ng_ether_constructor,

--- 132 unchanged lines hidden (view full) ---

261 __FUNCTION__, "allocate memory", name);
262 ng_unref(node);
263 return;
264 }
265 bzero(priv, sizeof(*priv));
266 node->private = priv;
267 priv->ifp = ifp;
268 IFP2NG(ifp) = node;
269
270 /* Try to give the node the same name as the interface */
271 if (ng_name_node(node, name) != 0) {
272 log(LOG_WARNING, "%s: can't name node %s\n",
273 __FUNCTION__, name);
274 }
275}
276

--- 172 unchanged lines hidden (view full) ---

449 case NGM_ETHER_GET_IFINDEX:
450 NG_MKRESPONSE(resp, msg, sizeof(u_int32_t), M_NOWAIT);
451 if (resp == NULL) {
452 error = ENOMEM;
453 break;
454 }
455 *((u_int32_t *)resp->data) = priv->ifp->if_index;
456 break;
457 default:
458 error = EINVAL;
459 break;
460 }
461 break;
462 default:
463 error = EINVAL;
464 break;

--- 25 unchanged lines hidden (view full) ---

490
491/*
492 * Handle an mbuf received on the "lower" hook.
493 */
494static int
495ng_ether_rcv_lower(node_p node, struct mbuf *m, meta_p meta)
496{
497 const priv_p priv = node->private;
498 struct ether_header *eh;
499
500 /* Make sure header is fully pulled up */
501 if (m->m_pkthdr.len < sizeof(struct ether_header)) {
502 NG_FREE_DATA(m, meta);
503 return (EINVAL);
504 }
505 if (m->m_len < sizeof(struct ether_header)
506 && (m = m_pullup(m, sizeof(struct ether_header))) == NULL) {
507 NG_FREE_META(meta);
508 return (ENOBUFS);
509 }
510
511 /* drop in the MAC address */
512 eh = mtod(m, struct ether_header *);
513 bcopy((IFP2AC(priv->ifp))->ac_enaddr, eh->ether_shost, 6);
514
515 /* Send it on its way */
516 NG_FREE_META(meta);
517 return ether_output_frame(priv->ifp, m);
518}
519
520/*
521 * Handle an mbuf received on the "upper" hook.

--- 25 unchanged lines hidden (view full) ---

547}
548
549/*
550 * Shutdown node. This resets the node but does not remove it.
551 */
552static int
553ng_ether_rmnode(node_p node)
554{
555 ng_cutlinks(node);
556 node->flags &= ~NG_INVALID; /* bounce back to life */
557 return (0);
558}
559
560/*
561 * Hook disconnection.
562 */
563static int
564ng_ether_disconnect(hook_p hook)

--- 75 unchanged lines hidden ---