Deleted Added
full compact
ng_tag.c (159979) ng_tag.c (184205)
1/*-
2 * Copyright (c) 2006 Vadim Goncharov <vadimnuclight@tpu.ru>
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

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

22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25 * SUCH DAMAGE.
26 *
27 * Portions Copyright (c) 1999 Whistle Communications, Inc.
28 * (ng_bpf by Archie Cobbs <archie@freebsd.org>)
29 *
1/*-
2 * Copyright (c) 2006 Vadim Goncharov <vadimnuclight@tpu.ru>
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

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

22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25 * SUCH DAMAGE.
26 *
27 * Portions Copyright (c) 1999 Whistle Communications, Inc.
28 * (ng_bpf by Archie Cobbs <archie@freebsd.org>)
29 *
30 * $FreeBSD: head/sys/netgraph/ng_tag.c 159979 2006-06-27 12:45:28Z glebius $
30 * $FreeBSD: head/sys/netgraph/ng_tag.c 184205 2008-10-23 15:53:51Z des $
31 */
32
33/*
34 * TAG NETGRAPH NODE TYPE
35 *
36 * This node type accepts an arbitrary number of hooks. Each hook can be
37 * configured for an mbuf_tags(9) definition and two hook names: a hook
38 * for matched packets, and a hook for packets, that didn't match. Incoming

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

298 */
299static int
300ng_tag_newhook(node_p node, hook_p hook, const char *name)
301{
302 hinfo_p hip;
303 int error;
304
305 /* Create hook private structure. */
31 */
32
33/*
34 * TAG NETGRAPH NODE TYPE
35 *
36 * This node type accepts an arbitrary number of hooks. Each hook can be
37 * configured for an mbuf_tags(9) definition and two hook names: a hook
38 * for matched packets, and a hook for packets, that didn't match. Incoming

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

298 */
299static int
300ng_tag_newhook(node_p node, hook_p hook, const char *name)
301{
302 hinfo_p hip;
303 int error;
304
305 /* Create hook private structure. */
306 MALLOC(hip, hinfo_p, sizeof(*hip), M_NETGRAPH_TAG, M_WAITOK | M_ZERO);
306 hip = malloc(sizeof(*hip), M_NETGRAPH_TAG, M_WAITOK | M_ZERO);
307 /* M_WAITOK can't return NULL. */
308 NG_HOOK_SET_PRIVATE(hook, hip);
309
310 /*
311 * After M_ZERO both in and out hook pointers are set to NULL,
312 * as well as all members and pointers to in and out API
313 * structures, so we need to set explicitly only thisHook field
314 * in that structures (after allocating them, of course).
315 */
316
317 /* Attach the default IN data. */
318 if ((error = ng_tag_setdata_in(hook, &ng_tag_default_in)) != 0) {
307 /* M_WAITOK can't return NULL. */
308 NG_HOOK_SET_PRIVATE(hook, hip);
309
310 /*
311 * After M_ZERO both in and out hook pointers are set to NULL,
312 * as well as all members and pointers to in and out API
313 * structures, so we need to set explicitly only thisHook field
314 * in that structures (after allocating them, of course).
315 */
316
317 /* Attach the default IN data. */
318 if ((error = ng_tag_setdata_in(hook, &ng_tag_default_in)) != 0) {
319 FREE(hip, M_NETGRAPH_TAG);
319 free(hip, M_NETGRAPH_TAG);
320 return (error);
321 }
322
323 /* Attach the default OUT data. */
324 if ((error = ng_tag_setdata_out(hook, &ng_tag_default_out)) != 0) {
320 return (error);
321 }
322
323 /* Attach the default OUT data. */
324 if ((error = ng_tag_setdata_out(hook, &ng_tag_default_out)) != 0) {
325 FREE(hip, M_NETGRAPH_TAG);
325 free(hip, M_NETGRAPH_TAG);
326 return (error);
327 }
328
329 /*
330 * Set hook name. This is done only once at hook creation time
331 * since hook name can't change, rather than to do it on every
332 * response to messages requesting API structures with data who
333 * we are etc.

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

616 hinfo_p priv = NG_HOOK_PRIVATE(hook2);
617
618 if (priv->hi_match == hook)
619 priv->hi_match = NULL;
620 if (priv->hi_nonmatch == hook)
621 priv->hi_nonmatch = NULL;
622 }
623
326 return (error);
327 }
328
329 /*
330 * Set hook name. This is done only once at hook creation time
331 * since hook name can't change, rather than to do it on every
332 * response to messages requesting API structures with data who
333 * we are etc.

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

616 hinfo_p priv = NG_HOOK_PRIVATE(hook2);
617
618 if (priv->hi_match == hook)
619 priv->hi_match = NULL;
620 if (priv->hi_nonmatch == hook)
621 priv->hi_nonmatch = NULL;
622 }
623
624 FREE(hip->in, M_NETGRAPH_TAG);
625 FREE(hip->out, M_NETGRAPH_TAG);
626 FREE(hip, M_NETGRAPH_TAG);
624 free(hip->in, M_NETGRAPH_TAG);
625 free(hip->out, M_NETGRAPH_TAG);
626 free(hip, M_NETGRAPH_TAG);
627 NG_HOOK_SET_PRIVATE(hook, NULL); /* for good measure */
628 if ((NG_NODE_NUMHOOKS(NG_HOOK_NODE(hook)) == 0) &&
629 (NG_NODE_IS_VALID(NG_HOOK_NODE(hook)))) {
630 ng_rmnode_self(NG_HOOK_NODE(hook));
631 }
632 return (0);
633}
634

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

643ng_tag_setdata_in(hook_p hook, const struct ng_tag_hookin *hp0)
644{
645 const hinfo_p hip = NG_HOOK_PRIVATE(hook);
646 struct ng_tag_hookin *hp;
647 int size;
648
649 /* Make a copy of the tag values and data. */
650 size = NG_TAG_HOOKIN_SIZE(hp0->tag_len);
627 NG_HOOK_SET_PRIVATE(hook, NULL); /* for good measure */
628 if ((NG_NODE_NUMHOOKS(NG_HOOK_NODE(hook)) == 0) &&
629 (NG_NODE_IS_VALID(NG_HOOK_NODE(hook)))) {
630 ng_rmnode_self(NG_HOOK_NODE(hook));
631 }
632 return (0);
633}
634

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

643ng_tag_setdata_in(hook_p hook, const struct ng_tag_hookin *hp0)
644{
645 const hinfo_p hip = NG_HOOK_PRIVATE(hook);
646 struct ng_tag_hookin *hp;
647 int size;
648
649 /* Make a copy of the tag values and data. */
650 size = NG_TAG_HOOKIN_SIZE(hp0->tag_len);
651 MALLOC(hp, struct ng_tag_hookin *, size, M_NETGRAPH_TAG, M_WAITOK);
651 hp = malloc(size, M_NETGRAPH_TAG, M_WAITOK);
652 /* M_WAITOK can't return NULL. */
653 bcopy(hp0, hp, size);
654
655 /* Free previous tag, if any, and assign new one. */
656 if (hip->in != NULL)
652 /* M_WAITOK can't return NULL. */
653 bcopy(hp0, hp, size);
654
655 /* Free previous tag, if any, and assign new one. */
656 if (hip->in != NULL)
657 FREE(hip->in, M_NETGRAPH_TAG);
657 free(hip->in, M_NETGRAPH_TAG);
658 hip->in = hp;
659
660 /*
661 * Resolve hook names to pointers.
662 *
663 * As ng_findhook() is expensive operation to do it on every packet
664 * after tag matching check, we do it here and use resolved pointers
665 * where appropriate.

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

693ng_tag_setdata_out(hook_p hook, const struct ng_tag_hookout *hp0)
694{
695 const hinfo_p hip = NG_HOOK_PRIVATE(hook);
696 struct ng_tag_hookout *hp;
697 int size;
698
699 /* Make a copy of the tag values and data. */
700 size = NG_TAG_HOOKOUT_SIZE(hp0->tag_len);
658 hip->in = hp;
659
660 /*
661 * Resolve hook names to pointers.
662 *
663 * As ng_findhook() is expensive operation to do it on every packet
664 * after tag matching check, we do it here and use resolved pointers
665 * where appropriate.

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

693ng_tag_setdata_out(hook_p hook, const struct ng_tag_hookout *hp0)
694{
695 const hinfo_p hip = NG_HOOK_PRIVATE(hook);
696 struct ng_tag_hookout *hp;
697 int size;
698
699 /* Make a copy of the tag values and data. */
700 size = NG_TAG_HOOKOUT_SIZE(hp0->tag_len);
701 MALLOC(hp, struct ng_tag_hookout *, size, M_NETGRAPH_TAG, M_WAITOK);
701 hp = malloc(size, M_NETGRAPH_TAG, M_WAITOK);
702 /* M_WAITOK can't return NULL. */
703 bcopy(hp0, hp, size);
704
705 /* Free previous tag, if any, and assign new one. */
706 if (hip->out != NULL)
702 /* M_WAITOK can't return NULL. */
703 bcopy(hp0, hp, size);
704
705 /* Free previous tag, if any, and assign new one. */
706 if (hip->out != NULL)
707 FREE(hip->out, M_NETGRAPH_TAG);
707 free(hip->out, M_NETGRAPH_TAG);
708 hip->out = hp;
709
710 /* Fill internal values from API structures. */
711 hip->out_tag_cookie = hip->out->tag_cookie;
712 hip->out_tag_id = hip->out->tag_id;
713 hip->out_tag_len = hip->out->tag_len;
714 hip->out_tag_data = (void*)(hip->out->tag_data);
715 return (0);
716}
717
708 hip->out = hp;
709
710 /* Fill internal values from API structures. */
711 hip->out_tag_cookie = hip->out->tag_cookie;
712 hip->out_tag_id = hip->out->tag_id;
713 hip->out_tag_len = hip->out->tag_len;
714 hip->out_tag_data = (void*)(hip->out->tag_data);
715 return (0);
716}
717