1a664ade9SLutz Donnerhacke /*- 224ea1dbfSLutz Donnerhacke * SPDX-License-Identifier: BSD-3-Clause 324ea1dbfSLutz Donnerhacke * 424ea1dbfSLutz Donnerhacke * Copyright 2021 Lutz Donnerhacke 524ea1dbfSLutz Donnerhacke * 624ea1dbfSLutz Donnerhacke * Redistribution and use in source and binary forms, with or without 724ea1dbfSLutz Donnerhacke * modification, are permitted provided that the following conditions 824ea1dbfSLutz Donnerhacke * are met: 924ea1dbfSLutz Donnerhacke * 1024ea1dbfSLutz Donnerhacke * 1. Redistributions of source code must retain the above copyright 1124ea1dbfSLutz Donnerhacke * notice, this list of conditions and the following disclaimer. 1224ea1dbfSLutz Donnerhacke * 2. Redistributions in binary form must reproduce the above 1324ea1dbfSLutz Donnerhacke * copyright notice, this list of conditions and the following 1424ea1dbfSLutz Donnerhacke * disclaimer in the documentation and/or other materials provided 1524ea1dbfSLutz Donnerhacke * with the distribution. 1624ea1dbfSLutz Donnerhacke * 3. Neither the name of the copyright holder nor the names of its 1724ea1dbfSLutz Donnerhacke * contributors may be used to endorse or promote products derived 1824ea1dbfSLutz Donnerhacke * from this software without specific prior written permission. 1924ea1dbfSLutz Donnerhacke * 2024ea1dbfSLutz Donnerhacke * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 2124ea1dbfSLutz Donnerhacke * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 2224ea1dbfSLutz Donnerhacke * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 2324ea1dbfSLutz Donnerhacke * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 2424ea1dbfSLutz Donnerhacke * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS 2524ea1dbfSLutz Donnerhacke * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 2624ea1dbfSLutz Donnerhacke * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED 2724ea1dbfSLutz Donnerhacke * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 2824ea1dbfSLutz Donnerhacke * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 2924ea1dbfSLutz Donnerhacke * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR 3024ea1dbfSLutz Donnerhacke * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 3124ea1dbfSLutz Donnerhacke * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 3224ea1dbfSLutz Donnerhacke * SUCH DAMAGE. 3324ea1dbfSLutz Donnerhacke */ 3424ea1dbfSLutz Donnerhacke 3524ea1dbfSLutz Donnerhacke #include <netgraph.h> 3624ea1dbfSLutz Donnerhacke 37a664ade9SLutz Donnerhacke void 38a664ade9SLutz Donnerhacke _ng_connect(char const *path1, char const *hook1, 399021c466SLutz Donnerhacke char const *path2, char const *hook2, 409021c466SLutz Donnerhacke char const *file, size_t line); 419021c466SLutz Donnerhacke #define ng_connect(p1,h1,p2,h2) \ 429021c466SLutz Donnerhacke _ng_connect(p1,h1,p2,h2,__FILE__,__LINE__) 439021c466SLutz Donnerhacke 44a664ade9SLutz Donnerhacke void 45a664ade9SLutz Donnerhacke _ng_mkpeer(char const *path1, char const *hook1, 469021c466SLutz Donnerhacke char const *type, char const *hook2, 479021c466SLutz Donnerhacke char const *file, size_t line); 489021c466SLutz Donnerhacke #define ng_mkpeer(p1,h1,t,h2) \ 499021c466SLutz Donnerhacke _ng_mkpeer(p1,h1,t,h2,__FILE__,__LINE__) 509021c466SLutz Donnerhacke 51a664ade9SLutz Donnerhacke void 52a664ade9SLutz Donnerhacke _ng_shutdown(char const *path, 539021c466SLutz Donnerhacke char const *file, size_t line); 549021c466SLutz Donnerhacke #define ng_shutdown(p) \ 559021c466SLutz Donnerhacke _ng_shutdown(p,__FILE__,__LINE__) 569021c466SLutz Donnerhacke 57a664ade9SLutz Donnerhacke void 58a664ade9SLutz Donnerhacke _ng_rmhook(char const *path, char const *hook, 599021c466SLutz Donnerhacke char const *file, size_t line); 609021c466SLutz Donnerhacke #define ng_rmhook(p,h) \ 619021c466SLutz Donnerhacke _ng_rmhook(p,h,__FILE__,__LINE__) 629021c466SLutz Donnerhacke 63a664ade9SLutz Donnerhacke void 64a664ade9SLutz Donnerhacke _ng_name(char const *path, char const *name, 659021c466SLutz Donnerhacke char const *file, size_t line); 669021c466SLutz Donnerhacke #define ng_name(p,n) \ 679021c466SLutz Donnerhacke _ng_name(p,n,__FILE__,__LINE__) 689021c466SLutz Donnerhacke 6924ea1dbfSLutz Donnerhacke 7024ea1dbfSLutz Donnerhacke typedef void (*ng_data_handler_t)(void *, size_t, void *ctx); 7124ea1dbfSLutz Donnerhacke void ng_register_data(char const *hook, ng_data_handler_t proc); 72a664ade9SLutz Donnerhacke void 73a664ade9SLutz Donnerhacke _ng_send_data(char const *hook, void const *, size_t, 749021c466SLutz Donnerhacke char const *file, size_t line); 759021c466SLutz Donnerhacke #define ng_send_data(h,d,l) \ 769021c466SLutz Donnerhacke _ng_send_data(h,d,l,__FILE__,__LINE__) 7724ea1dbfSLutz Donnerhacke 7809307dbfSLutz Donnerhacke typedef void (*ng_msg_handler_t)(char const *, struct ng_mesg *, void *); 7909307dbfSLutz Donnerhacke void ng_register_msg(ng_msg_handler_t proc); 80a664ade9SLutz Donnerhacke int 81a664ade9SLutz Donnerhacke _ng_send_msg(char const *path, char const *msg, 829021c466SLutz Donnerhacke char const *file, size_t line); 839021c466SLutz Donnerhacke #define ng_send_msg(p,m) \ 849021c466SLutz Donnerhacke _ng_send_msg(p,m,__FILE__,__LINE__) 8524ea1dbfSLutz Donnerhacke 8624ea1dbfSLutz Donnerhacke int ng_handle_event(unsigned int ms, void *ctx); 8724ea1dbfSLutz Donnerhacke void ng_handle_events(unsigned int ms, void *ctx); 8824ea1dbfSLutz Donnerhacke 89a664ade9SLutz Donnerhacke typedef enum 90a664ade9SLutz Donnerhacke { 91a664ade9SLutz Donnerhacke FAIL, PASS 92a664ade9SLutz Donnerhacke } ng_error_t; 9324ea1dbfSLutz Donnerhacke ng_error_t ng_errors(ng_error_t); 9424ea1dbfSLutz Donnerhacke 959021c466SLutz Donnerhacke void _ng_init(char const *file, size_t line); 969021c466SLutz Donnerhacke #define ng_init() \ 979021c466SLutz Donnerhacke _ng_init(__FILE__,__LINE__) 98*5554abd9SLutz Donnerhacke 99*5554abd9SLutz Donnerhacke /* Helper function to count received data */ 100*5554abd9SLutz Donnerhacke 101*5554abd9SLutz Donnerhacke typedef int ng_counter_t[10]; 102*5554abd9SLutz Donnerhacke #define ng_counter_clear(x)\ 103*5554abd9SLutz Donnerhacke bzero((x), sizeof(x)) 104*5554abd9SLutz Donnerhacke 105*5554abd9SLutz Donnerhacke void get_data0(void *data, size_t len, void *ctx); 106*5554abd9SLutz Donnerhacke void get_data1(void *data, size_t len, void *ctx); 107*5554abd9SLutz Donnerhacke void get_data2(void *data, size_t len, void *ctx); 108*5554abd9SLutz Donnerhacke void get_data3(void *data, size_t len, void *ctx); 109*5554abd9SLutz Donnerhacke void get_data4(void *data, size_t len, void *ctx); 110*5554abd9SLutz Donnerhacke void get_data5(void *data, size_t len, void *ctx); 111*5554abd9SLutz Donnerhacke void get_data6(void *data, size_t len, void *ctx); 112*5554abd9SLutz Donnerhacke void get_data7(void *data, size_t len, void *ctx); 113*5554abd9SLutz Donnerhacke void get_data8(void *data, size_t len, void *ctx); 114*5554abd9SLutz Donnerhacke void get_data9(void *data, size_t len, void *ctx); 115