Index: sys/netgraph/ng_base.c =================================================================== --- sys/netgraph/ng_base.c +++ sys/netgraph/ng_base.c @@ -66,6 +66,10 @@ #include #include +#include +#include +#include + #include #include @@ -247,6 +251,8 @@ void ng_rmnode(node_p node, hook_p dummy1, void *dummy2, int dummy3); void ng_unname(node_p node); +extern void (*ng_ether_attach_p)(struct ifnet *ifp); + /* Our own netgraph malloc type */ MALLOC_DEFINE(M_NETGRAPH, "netgraph", "netgraph structures and ctrl messages"); MALLOC_DEFINE(M_NETGRAPH_MSG, "netgraph_msg", "netgraph name storage"); @@ -581,6 +587,13 @@ &ng_parse_ng_mesg_type, &ng_parse_ng_mesg_type }, + { + NGM_GENERIC_COOKIE, + NGM_ETHER_ATTACH, + "attach", + &ng_parse_string_type, + NULL + }, { 0 } }; @@ -2922,6 +2935,16 @@ break; } + case NGM_ETHER_ATTACH: + { + struct ifnet *ifp; + ifp = ifunit((char *)msg->data); + if (ifp && ng_ether_attach_p != NULL) { + ng_ether_attach_p(ifp); + } + break; + } + case NGM_TEXT_CONFIG: case NGM_TEXT_STATUS: /* Index: sys/netgraph/ng_message.h =================================================================== --- sys/netgraph/ng_message.h +++ sys/netgraph/ng_message.h @@ -138,6 +138,7 @@ NGM_ASCII2BINARY= (13|NGM_READONLY|NGM_HASREPLY), /* (optional) Get/set text config. */ NGM_TEXT_CONFIG = 14, + NGM_ETHER_ATTACH = 15, }; /* Index: usr.sbin/ngctl/Makefile =================================================================== --- usr.sbin/ngctl/Makefile +++ usr.sbin/ngctl/Makefile @@ -6,7 +6,8 @@ PROG= ngctl MAN= ngctl.8 SRCS= main.c mkpeer.c config.c connect.c dot.c name.c show.c list.c \ - msg.c debug.c shutdown.c rmhook.c status.c types.c write.c + msg.c debug.c shutdown.c rmhook.c status.c types.c write.c \ + etherattach.c WARNS?= 3 LIBADD= netgraph Index: usr.sbin/ngctl/etherattach.c =================================================================== --- /dev/null +++ usr.sbin/ngctl/etherattach.c @@ -0,0 +1,66 @@ +/* + * etherattach.c + * + * Copyright (c) 2021 Rubicon Communications, LLC (Netgate) + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#include +#include +#include + +#include "ngctl.h" + +static int EtherAttachCmd(int ac, char **av); + +const struct ngcmd etherattach_cmd = { + EtherAttachCmd, + "etherattach ", + "Attach an ng_ether interface to the \"ifname\" interface", + "The etherattach command re-attaches the ng_ether node, if it's " + "previously been disconnected with the \"detach\" msg.", + { NULL } +}; + +static int +EtherAttachCmd(int ac, char **av) +{ + struct ngm_name name; + + switch (ac) { + case 2: + snprintf(name.name, sizeof(name.name), "%s", av[1]); + break; + default: + return (CMDRTN_USAGE); + } + + if (NgSendMsg(csock, ".", NGM_GENERIC_COOKIE, + NGM_ETHER_ATTACH, &name, sizeof(name)) < 0) { + warn("send msg"); + return (CMDRTN_ERROR); + } + return (CMDRTN_OK); +} Index: usr.sbin/ngctl/main.c =================================================================== --- usr.sbin/ngctl/main.c +++ usr.sbin/ngctl/main.c @@ -92,6 +92,7 @@ &connect_cmd, &debug_cmd, &dot_cmd, + ðerattach_cmd, &help_cmd, &list_cmd, &mkpeer_cmd, Index: usr.sbin/ngctl/ngctl.h =================================================================== --- usr.sbin/ngctl/ngctl.h +++ usr.sbin/ngctl/ngctl.h @@ -59,6 +59,7 @@ extern const struct ngcmd connect_cmd; extern const struct ngcmd debug_cmd; extern const struct ngcmd dot_cmd; +extern const struct ngcmd etherattach_cmd; extern const struct ngcmd help_cmd; extern const struct ngcmd list_cmd; extern const struct ngcmd mkpeer_cmd;