1 /* $NetBSD: npf_var.h,v 1.8 2013/11/19 00:28:41 rmind Exp $ */ 2 3 /*- 4 * Copyright (c) 2011-2012 The NetBSD Foundation, Inc. 5 * All rights reserved. 6 * 7 * This code is derived from software contributed to The NetBSD Foundation 8 * by Christos Zoulas. 9 * 10 * Redistribution and use in source and binary forms, with or without 11 * modification, are permitted provided that the following conditions 12 * are met: 13 * 1. Redistributions of source code must retain the above copyright 14 * notice, this list of conditions and the following disclaimer. 15 * 2. Redistributions in binary form must reproduce the above copyright 16 * notice, this list of conditions and the following disclaimer in the 17 * documentation and/or other materials provided with the distribution. 18 * 19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 * POSSIBILITY OF SUCH DAMAGE. 30 */ 31 32 #ifndef _NPF_VAR_H_ 33 #define _NPF_VAR_H_ 34 35 #define NPFVAR_STRING 0 36 #define NPFVAR_IDENTIFIER 1 37 #define NPFVAR_VAR_ID 2 38 #define NPFVAR_NUM 3 39 #define NPFVAR_PORT_RANGE 4 40 41 /* Note: primitive types are equivalent. */ 42 #define NPFVAR_PRIM NPFVAR_PORT_RANGE 43 #define NPFVAR_TYPE(x) (((x) > NPFVAR_PRIM) ? (x) : 0) 44 45 #define NPFVAR_TABLE 5 46 #define NPFVAR_FAM 6 47 #define NPFVAR_PROC 7 48 #define NPFVAR_PROC_PARAM 8 49 #define NPFVAR_TCPFLAG 9 50 #define NPFVAR_ICMP 10 51 #define NPFVAR_INTERFACE 11 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 }; 68 #endif 69 70 struct npfvar; 71 typedef struct npfvar npfvar_t; 72 73 npfvar_t * npfvar_create(void); 74 npfvar_t * npfvar_create_element(int, const void *, size_t); 75 npfvar_t * npfvar_create_from_string(int, const char *); 76 npfvar_t * npfvar_lookup(const char *); 77 const char * npfvar_type(size_t); 78 void npfvar_add(npfvar_t *, const char *); 79 npfvar_t * npfvar_add_element(npfvar_t *, int, const void *, size_t); 80 npfvar_t * npfvar_add_elements(npfvar_t *, npfvar_t *); 81 void npfvar_destroy(npfvar_t *); 82 83 char * npfvar_expand_string(const npfvar_t *); 84 size_t npfvar_get_count(const npfvar_t *); 85 int npfvar_get_type(const npfvar_t *, size_t); 86 void * npfvar_get_data(const npfvar_t *, int, size_t); 87 88 #endif 89