1d359a62dSAndrey V. Elsukov /*- 2*fe267a55SPedro F. Giffuni * SPDX-License-Identifier: BSD-2-Clause-FreeBSD 3*fe267a55SPedro 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 * $FreeBSD$ 30d359a62dSAndrey V. Elsukov */ 31d359a62dSAndrey V. Elsukov 32d359a62dSAndrey V. Elsukov #ifndef _NETGRAPH_NG_PATCH_H_ 33d359a62dSAndrey V. Elsukov #define _NETGRAPH_NG_PATCH_H_ 34d359a62dSAndrey V. Elsukov 35d359a62dSAndrey V. Elsukov /* Node type name. */ 36d359a62dSAndrey V. Elsukov #define NG_PATCH_NODE_TYPE "patch" 37d359a62dSAndrey V. Elsukov 38d359a62dSAndrey V. Elsukov /* Node type cookie. */ 39d359a62dSAndrey V. Elsukov #define NGM_PATCH_COOKIE 1262445509 40d359a62dSAndrey V. Elsukov 41d359a62dSAndrey V. Elsukov /* Hook names */ 42d359a62dSAndrey V. Elsukov #define NG_PATCH_HOOK_IN "in" 43d359a62dSAndrey V. Elsukov #define NG_PATCH_HOOK_OUT "out" 44d359a62dSAndrey V. Elsukov 45426b3d04SJulian Elischer /* Checksum flags */ 46426b3d04SJulian Elischer #define NG_PATCH_CSUM_IPV4 (CSUM_IP|CSUM_TCP|CSUM_UDP|CSUM_SCTP) 47426b3d04SJulian Elischer #define NG_PATCH_CSUM_IPV6 (CSUM_TCP_IPV6|CSUM_UDP_IPV6|CSUM_SCTP_IPV6) 48426b3d04SJulian Elischer 49d359a62dSAndrey V. Elsukov /* Netgraph commands understood by this node type */ 50d359a62dSAndrey V. Elsukov enum { 51d359a62dSAndrey V. Elsukov NGM_PATCH_SETCONFIG = 1, 52d359a62dSAndrey V. Elsukov NGM_PATCH_GETCONFIG, 53d359a62dSAndrey V. Elsukov NGM_PATCH_GET_STATS, 54d359a62dSAndrey V. Elsukov NGM_PATCH_CLR_STATS, 55426b3d04SJulian Elischer NGM_PATCH_GETCLR_STATS, 56426b3d04SJulian Elischer NGM_PATCH_GETDLT, 57426b3d04SJulian Elischer NGM_PATCH_SETDLT 58d359a62dSAndrey V. Elsukov }; 59d359a62dSAndrey V. Elsukov 60d359a62dSAndrey V. Elsukov /* Patching modes */ 61d359a62dSAndrey V. Elsukov enum { 62d359a62dSAndrey V. Elsukov NG_PATCH_MODE_SET = 1, 63d359a62dSAndrey V. Elsukov NG_PATCH_MODE_ADD = 2, 64d359a62dSAndrey V. Elsukov NG_PATCH_MODE_SUB = 3, 65d359a62dSAndrey V. Elsukov NG_PATCH_MODE_MUL = 4, 66d359a62dSAndrey V. Elsukov NG_PATCH_MODE_DIV = 5, 67d359a62dSAndrey V. Elsukov NG_PATCH_MODE_NEG = 6, 68d359a62dSAndrey V. Elsukov NG_PATCH_MODE_AND = 7, 69d359a62dSAndrey V. Elsukov NG_PATCH_MODE_OR = 8, 70d359a62dSAndrey V. Elsukov NG_PATCH_MODE_XOR = 9, 71d359a62dSAndrey V. Elsukov NG_PATCH_MODE_SHL = 10, 72d359a62dSAndrey V. Elsukov NG_PATCH_MODE_SHR = 11 73d359a62dSAndrey V. Elsukov }; 74d359a62dSAndrey V. Elsukov 75426b3d04SJulian Elischer /* Parsing declarations */ 76d359a62dSAndrey V. Elsukov 77426b3d04SJulian Elischer #define NG_PATCH_CONFIG_TYPE { \ 78d359a62dSAndrey V. Elsukov { "count", &ng_parse_uint32_type }, \ 79bf909fc9SJulian Elischer { "csum_flags", &ng_parse_uint64_type }, \ 80426b3d04SJulian Elischer { "relative_offset", &ng_parse_uint32_type }, \ 81bf909fc9SJulian Elischer { "ops", &ng_patch_ops_array_type }, \ 82d359a62dSAndrey V. Elsukov { NULL } \ 83d359a62dSAndrey V. Elsukov } 84d359a62dSAndrey V. Elsukov 85426b3d04SJulian Elischer #define NG_PATCH_OP_TYPE { \ 86426b3d04SJulian Elischer { "offset", &ng_parse_uint32_type }, \ 87426b3d04SJulian Elischer { "length", &ng_parse_uint16_type }, \ 88426b3d04SJulian Elischer { "mode", &ng_parse_uint16_type }, \ 89426b3d04SJulian Elischer { "value", &ng_parse_uint64_type }, \ 90426b3d04SJulian Elischer { NULL } \ 91426b3d04SJulian Elischer } 92426b3d04SJulian Elischer 93426b3d04SJulian Elischer #define NG_PATCH_STATS_TYPE { \ 94426b3d04SJulian Elischer { "Received", &ng_parse_uint64_type }, \ 95426b3d04SJulian Elischer { "Patched", &ng_parse_uint64_type }, \ 96426b3d04SJulian Elischer { "Dropped", &ng_parse_uint64_type }, \ 97426b3d04SJulian Elischer { NULL } \ 98426b3d04SJulian Elischer } 99426b3d04SJulian Elischer 100426b3d04SJulian Elischer union ng_patch_op_val { 101426b3d04SJulian Elischer uint8_t v1; 102426b3d04SJulian Elischer uint16_t v2; 103426b3d04SJulian Elischer uint32_t v4; 104426b3d04SJulian Elischer uint64_t v8; 105426b3d04SJulian Elischer }; 106426b3d04SJulian Elischer 107426b3d04SJulian Elischer struct ng_patch_op { 108426b3d04SJulian Elischer uint32_t offset; 109426b3d04SJulian Elischer uint16_t length; /* 1, 2, 4 or 8 (bytes) */ 110426b3d04SJulian Elischer uint16_t mode; 111426b3d04SJulian Elischer union ng_patch_op_val val; 112426b3d04SJulian Elischer }; 113426b3d04SJulian Elischer 114426b3d04SJulian Elischer struct ng_patch_config { 115426b3d04SJulian Elischer uint32_t count; 116426b3d04SJulian Elischer uint64_t csum_flags; 117426b3d04SJulian Elischer uint32_t relative_offset; 118426b3d04SJulian Elischer struct ng_patch_op ops[]; 119426b3d04SJulian Elischer }; 120426b3d04SJulian Elischer 121d359a62dSAndrey V. Elsukov struct ng_patch_stats { 122d359a62dSAndrey V. Elsukov uint64_t received; 123d359a62dSAndrey V. Elsukov uint64_t patched; 124d359a62dSAndrey V. Elsukov uint64_t dropped; 125d359a62dSAndrey V. Elsukov }; 126d359a62dSAndrey V. Elsukov 127426b3d04SJulian Elischer struct ng_patch_vlan_header { 128426b3d04SJulian Elischer u_int16_t tag; 129426b3d04SJulian Elischer u_int16_t etype; 130426b3d04SJulian Elischer }; 131426b3d04SJulian Elischer 132426b3d04SJulian Elischer #define NG_PATCH_CONF_SIZE(count) (sizeof(struct ng_patch_config) + \ 133426b3d04SJulian Elischer (count) * sizeof(struct ng_patch_op)) 134d359a62dSAndrey V. Elsukov 135d359a62dSAndrey V. Elsukov #endif /* _NETGRAPH_NG_PATCH_H_ */ 136