1 /* $NetBSD: pf_mtag.c,v 1.3 2018/11/15 10:23:55 maxv Exp $ */
2 /* $OpenBSD: pf.c,v 1.504 2005/10/17 08:43:35 henning Exp $ */
3
4 /*
5 * Copyright (c) 2001 Daniel Hartmeier
6 * Copyright (c) 2002,2003 Henning Brauer
7 * All rights reserved.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 *
13 * - Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * - Redistributions in binary form must reproduce the above
16 * copyright notice, this list of conditions and the following
17 * disclaimer in the documentation and/or other materials provided
18 * with the distribution.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
23 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
24 * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
25 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
26 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
27 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
30 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31 * POSSIBILITY OF SUCH DAMAGE.
32 *
33 * Effort sponsored in part by the Defense Advanced Research Projects
34 * Agency (DARPA) and Air Force Research Laboratory, Air Force
35 * Materiel Command, USAF, under agreement number F30602-01-2-0537.
36 *
37 */
38
39 #include <sys/cdefs.h>
40 __KERNEL_RCSID(0, "$NetBSD: pf_mtag.c,v 1.3 2018/11/15 10:23:55 maxv Exp $");
41
42 #include <sys/param.h>
43 #include <sys/systm.h>
44 #include <sys/mbuf.h>
45 #include <sys/kernel.h>
46
47 #include <net/pf_mtag.h>
48
49 struct pf_mtag *
pf_find_mtag(struct mbuf * m)50 pf_find_mtag(struct mbuf *m)
51 {
52 struct m_tag *mtag;
53
54 if ((mtag = m_tag_find(m, PACKET_TAG_PF)) == NULL)
55 return (NULL);
56
57 return ((struct pf_mtag *)(mtag + 1));
58 }
59
60 struct pf_mtag *
pf_get_mtag(struct mbuf * m)61 pf_get_mtag(struct mbuf *m)
62 {
63 struct m_tag *mtag;
64
65 if ((mtag = m_tag_find(m, PACKET_TAG_PF)) == NULL) {
66 mtag = m_tag_get(PACKET_TAG_PF, sizeof(struct pf_mtag),
67 M_NOWAIT);
68 if (mtag == NULL)
69 return (NULL);
70 bzero(mtag + 1, sizeof(struct pf_mtag));
71 m_tag_prepend(m, mtag);
72 }
73
74 return ((struct pf_mtag *)(mtag + 1));
75 }
76