Home | History | Annotate | Line # | Download | only in npfctl
      1 /*-
      2  * Copyright (c) 2011-2025 The NetBSD Foundation, Inc.
      3  * All rights reserved.
      4  *
      5  * This code is derived from software contributed to The NetBSD Foundation
      6  * by Christos Zoulas.
      7  *
      8  * Redistribution and use in source and binary forms, with or without
      9  * modification, are permitted provided that the following conditions
     10  * are met:
     11  * 1. Redistributions of source code must retain the above copyright
     12  *    notice, this list of conditions and the following disclaimer.
     13  * 2. Redistributions in binary form must reproduce the above copyright
     14  *    notice, this list of conditions and the following disclaimer in the
     15  *    documentation and/or other materials provided with the distribution.
     16  *
     17  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     18  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     19  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     20  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     21  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     22  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     23  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     24  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     25  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     26  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     27  * POSSIBILITY OF SUCH DAMAGE.
     28  */
     29 
     30 #ifndef _NPF_VAR_H_
     31 #define _NPF_VAR_H_
     32 
     33 #define	NPFVAR_STRING		0
     34 #define	NPFVAR_IDENTIFIER	1
     35 #define	NPFVAR_VAR_ID		2
     36 #define	NPFVAR_NUM		3
     37 #define	NPFVAR_PORT_RANGE	4
     38 
     39 /* Note: primitive types are equivalent. */
     40 #define	NPFVAR_PRIM		NPFVAR_PORT_RANGE
     41 #define	NPFVAR_TYPE(x)		(((x) > NPFVAR_PRIM) ? (x) : 0)
     42 
     43 #define	NPFVAR_TABLE		5
     44 #define	NPFVAR_FAM		6
     45 #define	NPFVAR_PROC		7
     46 #define	NPFVAR_PROC_PARAM	8
     47 #define	NPFVAR_TCPFLAG		9
     48 #define	NPFVAR_ICMP		10
     49 #define	NPFVAR_INTERFACE	11
     50 #define	NPFVAR_PROTO		12
     51 #define	NPFVAR_MAC		13
     52 
     53 #ifdef _NPFVAR_PRIVATE
     54 static const char *npfvar_types[ ] = {
     55 	[NPFVAR_STRING]		= "string",
     56 	[NPFVAR_IDENTIFIER]	= "identifier",
     57 	[NPFVAR_VAR_ID]		= "variable-id",
     58 	[NPFVAR_NUM]		= "number",
     59 	[NPFVAR_PORT_RANGE]	= "port-range",
     60 	[NPFVAR_TABLE]		= "table",
     61 	[NPFVAR_FAM]		= "family-address-mask",
     62 	[NPFVAR_PROC]		= "procedure",
     63 	[NPFVAR_PROC_PARAM]	= "procedure-parameter",
     64 	[NPFVAR_TCPFLAG]	= "tcp-flag",
     65 	[NPFVAR_ICMP]		= "icmp",
     66 	[NPFVAR_INTERFACE]	= "interface-address",
     67 	[NPFVAR_PROTO]		= "proto",
     68 	[NPFVAR_MAC]		= "mac-address",
     69 };
     70 #endif
     71 
     72 struct npfvar;
     73 typedef struct npfvar npfvar_t;
     74 typedef int (*rid_parser)(const char *, uint32_t *);
     75 
     76 npfvar_t *	npfvar_create(void);
     77 npfvar_t *	npfvar_create_element(unsigned, const void *, size_t);
     78 npfvar_t *	npfvar_create_from_string(unsigned, const char *);
     79 npfvar_t *	npfvar_lookup(const char *);
     80 const char *	npfvar_type(size_t);
     81 void		npfvar_add(npfvar_t *, const char *);
     82 npfvar_t *	npfvar_add_element(npfvar_t *, unsigned, const void *, size_t);
     83 npfvar_t *	npfvar_add_elements(npfvar_t *, npfvar_t *);
     84 void		npfvar_destroy(npfvar_t *);
     85 
     86 char *		npfvar_expand_string(const npfvar_t *);
     87 size_t		npfvar_get_count(const npfvar_t *);
     88 uint32_t	npfvar_expand_number(const npfvar_t *);
     89 void *		npfvar_getfilt_data(const npfvar_t *, unsigned, size_t);
     90 int		npfvar_getfilt_type(const npfvar_t *, size_t);
     91 int		npfvar_get_type(const npfvar_t *, size_t);
     92 void *		npfvar_get_data(const npfvar_t *, unsigned, size_t);
     93 void		npf_var_rid(char *, rid_parser, uint32_t *, const char *);
     94 
     95 #endif
     96