1d359a62dSAndrey V. Elsukov /*- 2*4d846d26SWarner Losh * SPDX-License-Identifier: BSD-2-Clause 3fe267a55SPedro F. Giffuni * 4426b3d04SJulian Elischer * Copyright (c) 2010 Maxim Ignatenko <gelraen.ua@gmail.com> 5426b3d04SJulian Elischer * Copyright (c) 2015 Dmitry Vagin <daemon.hammer@ya.ru> 6d359a62dSAndrey V. Elsukov * All rights reserved. 7d359a62dSAndrey V. Elsukov * 8d359a62dSAndrey V. Elsukov * Redistribution and use in source and binary forms, with or without 9d359a62dSAndrey V. Elsukov * modification, are permitted provided that the following conditions 10d359a62dSAndrey V. Elsukov * are met: 11d359a62dSAndrey V. Elsukov * 1. Redistributions of source code must retain the above copyright 12d359a62dSAndrey V. Elsukov * notice, this list of conditions and the following disclaimer. 13d359a62dSAndrey V. Elsukov * 2. Redistributions in binary form must reproduce the above copyright 14d359a62dSAndrey V. Elsukov * notice, this list of conditions and the following disclaimer in the 15d359a62dSAndrey V. Elsukov * documentation and/or other materials provided with the distribution. 16d359a62dSAndrey V. Elsukov * 17d359a62dSAndrey V. Elsukov * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 18d359a62dSAndrey V. Elsukov * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19d359a62dSAndrey V. Elsukov * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20d359a62dSAndrey V. Elsukov * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 21d359a62dSAndrey V. Elsukov * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22d359a62dSAndrey V. Elsukov * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23d359a62dSAndrey V. Elsukov * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24d359a62dSAndrey V. Elsukov * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25d359a62dSAndrey V. Elsukov * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26d359a62dSAndrey V. Elsukov * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27d359a62dSAndrey V. Elsukov * SUCH DAMAGE. 28d359a62dSAndrey V. Elsukov */ 29d359a62dSAndrey V. Elsukov 30d359a62dSAndrey V. Elsukov #ifndef _NETGRAPH_NG_PATCH_H_ 31d359a62dSAndrey V. Elsukov #define _NETGRAPH_NG_PATCH_H_ 32d359a62dSAndrey V. Elsukov 33d359a62dSAndrey V. Elsukov /* Node type name. */ 34d359a62dSAndrey V. Elsukov #define NG_PATCH_NODE_TYPE "patch" 35d359a62dSAndrey V. Elsukov 36d359a62dSAndrey V. Elsukov /* Node type cookie. */ 37d359a62dSAndrey V. Elsukov #define NGM_PATCH_COOKIE 1262445509 38d359a62dSAndrey V. Elsukov 39d359a62dSAndrey V. Elsukov /* Hook names */ 40d359a62dSAndrey V. Elsukov #define NG_PATCH_HOOK_IN "in" 41d359a62dSAndrey V. Elsukov #define NG_PATCH_HOOK_OUT "out" 42d359a62dSAndrey V. Elsukov 43426b3d04SJulian Elischer /* Checksum flags */ 44426b3d04SJulian Elischer #define NG_PATCH_CSUM_IPV4 (CSUM_IP|CSUM_TCP|CSUM_UDP|CSUM_SCTP) 45426b3d04SJulian Elischer #define NG_PATCH_CSUM_IPV6 (CSUM_TCP_IPV6|CSUM_UDP_IPV6|CSUM_SCTP_IPV6) 46426b3d04SJulian Elischer 47d359a62dSAndrey V. Elsukov /* Netgraph commands understood by this node type */ 48d359a62dSAndrey V. Elsukov enum { 49d359a62dSAndrey V. Elsukov NGM_PATCH_SETCONFIG = 1, 50d359a62dSAndrey V. Elsukov NGM_PATCH_GETCONFIG, 51d359a62dSAndrey V. Elsukov NGM_PATCH_GET_STATS, 52d359a62dSAndrey V. Elsukov NGM_PATCH_CLR_STATS, 53426b3d04SJulian Elischer NGM_PATCH_GETCLR_STATS, 54426b3d04SJulian Elischer NGM_PATCH_GETDLT, 55426b3d04SJulian Elischer NGM_PATCH_SETDLT 56d359a62dSAndrey V. Elsukov }; 57d359a62dSAndrey V. Elsukov 58d359a62dSAndrey V. Elsukov /* Patching modes */ 59d359a62dSAndrey V. Elsukov enum { 60d359a62dSAndrey V. Elsukov NG_PATCH_MODE_SET = 1, 61d359a62dSAndrey V. Elsukov NG_PATCH_MODE_ADD = 2, 62d359a62dSAndrey V. Elsukov NG_PATCH_MODE_SUB = 3, 63d359a62dSAndrey V. Elsukov NG_PATCH_MODE_MUL = 4, 64d359a62dSAndrey V. Elsukov NG_PATCH_MODE_DIV = 5, 65d359a62dSAndrey V. Elsukov NG_PATCH_MODE_NEG = 6, 66d359a62dSAndrey V. Elsukov NG_PATCH_MODE_AND = 7, 67d359a62dSAndrey V. Elsukov NG_PATCH_MODE_OR = 8, 68d359a62dSAndrey V. Elsukov NG_PATCH_MODE_XOR = 9, 69d359a62dSAndrey V. Elsukov NG_PATCH_MODE_SHL = 10, 70d359a62dSAndrey V. Elsukov NG_PATCH_MODE_SHR = 11 71d359a62dSAndrey V. Elsukov }; 72d359a62dSAndrey V. Elsukov 73426b3d04SJulian Elischer /* Parsing declarations */ 74d359a62dSAndrey V. Elsukov 75426b3d04SJulian Elischer #define NG_PATCH_CONFIG_TYPE { \ 76d359a62dSAndrey V. Elsukov { "count", &ng_parse_uint32_type }, \ 77bf909fc9SJulian Elischer { "csum_flags", &ng_parse_uint64_type }, \ 78426b3d04SJulian Elischer { "relative_offset", &ng_parse_uint32_type }, \ 79bf909fc9SJulian Elischer { "ops", &ng_patch_ops_array_type }, \ 80d359a62dSAndrey V. Elsukov { NULL } \ 81d359a62dSAndrey V. Elsukov } 82d359a62dSAndrey V. Elsukov 83426b3d04SJulian Elischer #define NG_PATCH_OP_TYPE { \ 84426b3d04SJulian Elischer { "offset", &ng_parse_uint32_type }, \ 85426b3d04SJulian Elischer { "length", &ng_parse_uint16_type }, \ 86426b3d04SJulian Elischer { "mode", &ng_parse_uint16_type }, \ 87426b3d04SJulian Elischer { "value", &ng_parse_uint64_type }, \ 88426b3d04SJulian Elischer { NULL } \ 89426b3d04SJulian Elischer } 90426b3d04SJulian Elischer 91426b3d04SJulian Elischer #define NG_PATCH_STATS_TYPE { \ 92426b3d04SJulian Elischer { "Received", &ng_parse_uint64_type }, \ 93426b3d04SJulian Elischer { "Patched", &ng_parse_uint64_type }, \ 94426b3d04SJulian Elischer { "Dropped", &ng_parse_uint64_type }, \ 95426b3d04SJulian Elischer { NULL } \ 96426b3d04SJulian Elischer } 97426b3d04SJulian Elischer 98426b3d04SJulian Elischer union ng_patch_op_val { 99426b3d04SJulian Elischer uint8_t v1; 100426b3d04SJulian Elischer uint16_t v2; 101426b3d04SJulian Elischer uint32_t v4; 102426b3d04SJulian Elischer uint64_t v8; 103426b3d04SJulian Elischer }; 104426b3d04SJulian Elischer 105426b3d04SJulian Elischer struct ng_patch_op { 106426b3d04SJulian Elischer uint32_t offset; 107426b3d04SJulian Elischer uint16_t length; /* 1, 2, 4 or 8 (bytes) */ 108426b3d04SJulian Elischer uint16_t mode; 109426b3d04SJulian Elischer union ng_patch_op_val val; 110426b3d04SJulian Elischer }; 111426b3d04SJulian Elischer 112426b3d04SJulian Elischer struct ng_patch_config { 113426b3d04SJulian Elischer uint32_t count; 114426b3d04SJulian Elischer uint64_t csum_flags; 115426b3d04SJulian Elischer uint32_t relative_offset; 116426b3d04SJulian Elischer struct ng_patch_op ops[]; 117426b3d04SJulian Elischer }; 118426b3d04SJulian Elischer 119d359a62dSAndrey V. Elsukov struct ng_patch_stats { 120d359a62dSAndrey V. Elsukov uint64_t received; 121d359a62dSAndrey V. Elsukov uint64_t patched; 122d359a62dSAndrey V. Elsukov uint64_t dropped; 123d359a62dSAndrey V. Elsukov }; 124d359a62dSAndrey V. Elsukov 125426b3d04SJulian Elischer struct ng_patch_vlan_header { 126426b3d04SJulian Elischer u_int16_t tag; 127426b3d04SJulian Elischer u_int16_t etype; 128426b3d04SJulian Elischer }; 129426b3d04SJulian Elischer 130426b3d04SJulian Elischer #define NG_PATCH_CONF_SIZE(count) (sizeof(struct ng_patch_config) + \ 131426b3d04SJulian Elischer (count) * sizeof(struct ng_patch_op)) 132d359a62dSAndrey V. Elsukov 133d359a62dSAndrey V. Elsukov #endif /* _NETGRAPH_NG_PATCH_H_ */ 134