1/*- 2 * Copyright (c) 2011-2012 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 52#ifdef _NPFVAR_PRIVATE 53static const char *npfvar_types[ ] = { 54 [NPFVAR_STRING] = "string", 55 [NPFVAR_IDENTIFIER] = "identifier", 56 [NPFVAR_VAR_ID] = "variable-id", 57 [NPFVAR_NUM] = "number", 58 [NPFVAR_PORT_RANGE] = "port-range", 59 [NPFVAR_TABLE] = "table", 60 [NPFVAR_FAM] = "family-address-mask", 61 [NPFVAR_PROC] = "procedure", 62 [NPFVAR_PROC_PARAM] = "procedure-parameter", 63 [NPFVAR_TCPFLAG] = "tcp-flag", 64 [NPFVAR_ICMP] = "icmp", 65 [NPFVAR_INTERFACE] = "interface-address", 66 [NPFVAR_PROTO] = "proto", 67}; 68#endif 69 70struct npfvar; 71typedef struct npfvar npfvar_t; 72 73npfvar_t * npfvar_create(void); 74npfvar_t * npfvar_create_element(unsigned, const void *, size_t); 75npfvar_t * npfvar_create_from_string(unsigned, const char *); 76npfvar_t * npfvar_lookup(const char *); 77const char * npfvar_type(size_t); 78void npfvar_add(npfvar_t *, const char *); 79npfvar_t * npfvar_add_element(npfvar_t *, unsigned, const void *, size_t); 80npfvar_t * npfvar_add_elements(npfvar_t *, npfvar_t *); 81void npfvar_destroy(npfvar_t *); 82 83char * npfvar_expand_string(const npfvar_t *); 84size_t npfvar_get_count(const npfvar_t *); 85int npfvar_get_type(const npfvar_t *, size_t); 86void * npfvar_get_data(const npfvar_t *, unsigned, size_t); 87 88#endif 89