1 /* $NetBSD: npf_var.h,v 1.2 2012/02/26 21:50:05 christos 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_TCPFLAG 7 48 #define NPFVAR_ICMP 8 49 #define NPFVAR_PROC_OP 9 50 #define NPFVAR_MODULE_ARG 10 51 52 #ifdef _NPFVAR_PRIVATE 53 static const char *npfvar_types[ ] = { 54 "string", "identifier", "var_id", "num", "table", "fam", "port_range", 55 "tcpflag", "icmp", "proc_op", "module_arg" 56 }; 57 #endif 58 59 struct npfvar; 60 typedef struct npfvar npfvar_t; 61 62 npfvar_t * npfvar_create(const char *); 63 npfvar_t * npfvar_lookup(const char *); 64 const char * npfvar_type(size_t); 65 void npfvar_add(npfvar_t *); 66 npfvar_t * npfvar_add_element(npfvar_t *, int, const void *, size_t); 67 npfvar_t * npfvar_add_elements(npfvar_t *, npfvar_t *); 68 void npfvar_destroy(npfvar_t *); 69 70 char * npfvar_expand_string(const npfvar_t *); 71 size_t npfvar_get_count(const npfvar_t *); 72 int npfvar_get_type(const npfvar_t *, size_t); 73 void * npfvar_get_data(const npfvar_t *, int, size_t); 74 75 #endif 76