124ea1dbfSLutz 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 37*9021c466SLutz Donnerhacke void _ng_connect (char const *path1, char const *hook1, 38*9021c466SLutz Donnerhacke char const *path2, char const *hook2, 39*9021c466SLutz Donnerhacke char const *file, size_t line); 40*9021c466SLutz Donnerhacke #define ng_connect(p1,h1,p2,h2) \ 41*9021c466SLutz Donnerhacke _ng_connect(p1,h1,p2,h2,__FILE__,__LINE__) 42*9021c466SLutz Donnerhacke 43*9021c466SLutz Donnerhacke void _ng_mkpeer (char const *path1, char const *hook1, 44*9021c466SLutz Donnerhacke char const *type, char const *hook2, 45*9021c466SLutz Donnerhacke char const *file, size_t line); 46*9021c466SLutz Donnerhacke #define ng_mkpeer(p1,h1,t,h2) \ 47*9021c466SLutz Donnerhacke _ng_mkpeer(p1,h1,t,h2,__FILE__,__LINE__) 48*9021c466SLutz Donnerhacke 49*9021c466SLutz Donnerhacke void _ng_shutdown(char const *path, 50*9021c466SLutz Donnerhacke char const *file, size_t line); 51*9021c466SLutz Donnerhacke #define ng_shutdown(p) \ 52*9021c466SLutz Donnerhacke _ng_shutdown(p,__FILE__,__LINE__) 53*9021c466SLutz Donnerhacke 54*9021c466SLutz Donnerhacke void _ng_rmhook (char const *path, char const *hook, 55*9021c466SLutz Donnerhacke char const *file, size_t line); 56*9021c466SLutz Donnerhacke #define ng_rmhook(p,h) \ 57*9021c466SLutz Donnerhacke _ng_rmhook(p,h,__FILE__,__LINE__) 58*9021c466SLutz Donnerhacke 59*9021c466SLutz Donnerhacke void _ng_name (char const *path, char const *name, 60*9021c466SLutz Donnerhacke char const *file, size_t line); 61*9021c466SLutz Donnerhacke #define ng_name(p,n) \ 62*9021c466SLutz Donnerhacke _ng_name(p,n,__FILE__,__LINE__) 63*9021c466SLutz Donnerhacke 6424ea1dbfSLutz Donnerhacke 6524ea1dbfSLutz Donnerhacke typedef void (*ng_data_handler_t)(void *, size_t, void *ctx); 6624ea1dbfSLutz Donnerhacke void ng_register_data(char const *hook, ng_data_handler_t proc); 67*9021c466SLutz Donnerhacke void _ng_send_data(char const *hook, void const *, size_t, 68*9021c466SLutz Donnerhacke char const *file, size_t line); 69*9021c466SLutz Donnerhacke #define ng_send_data(h,d,l) \ 70*9021c466SLutz Donnerhacke _ng_send_data(h,d,l,__FILE__,__LINE__) 7124ea1dbfSLutz Donnerhacke 7209307dbfSLutz Donnerhacke typedef void (*ng_msg_handler_t)(char const *, struct ng_mesg *, void *); 7309307dbfSLutz Donnerhacke void ng_register_msg(ng_msg_handler_t proc); 74*9021c466SLutz Donnerhacke int _ng_send_msg(char const *path, char const *msg, 75*9021c466SLutz Donnerhacke char const *file, size_t line); 76*9021c466SLutz Donnerhacke #define ng_send_msg(p,m) \ 77*9021c466SLutz Donnerhacke _ng_send_msg(p,m,__FILE__,__LINE__) 7824ea1dbfSLutz Donnerhacke 7924ea1dbfSLutz Donnerhacke int ng_handle_event (unsigned int ms, void *ctx); 8024ea1dbfSLutz Donnerhacke void ng_handle_events(unsigned int ms, void *ctx); 8124ea1dbfSLutz Donnerhacke 8224ea1dbfSLutz Donnerhacke typedef enum { FAIL, PASS } ng_error_t; 8324ea1dbfSLutz Donnerhacke ng_error_t ng_errors(ng_error_t); 8424ea1dbfSLutz Donnerhacke 85*9021c466SLutz Donnerhacke void _ng_init(char const *file, size_t line); 86*9021c466SLutz Donnerhacke #define ng_init() \ 87*9021c466SLutz Donnerhacke _ng_init(__FILE__,__LINE__) 88