Date: Mon, 10 Feb 2003 15:48:00 +0300 (MSK) From: Gleb Smirnoff <glebius@cell.sick.ru> To: FreeBSD-gnats-submit@FreeBSD.org Cc: archie@FreeBSD.org Subject: ports/48138: mpd does not reuses netgraph pppoe nodes attached to ether node Message-ID: <200302101248.h1ACm0Gx009329@cell.sick.ru>
next in thread | raw e-mail | index | archive | help
>Number: 48138 >Category: ports >Synopsis: mpd does not reuses netgraph pppoe nodes attached to ether node >Confidential: no >Severity: serious >Priority: medium >Responsible: freebsd-ports-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: sw-bug >Submitter-Id: current-users >Arrival-Date: Mon Feb 10 04:50:08 PST 2003 >Closed-Date: >Last-Modified: >Originator: Gleb Smirnoff >Release: FreeBSD 4.7-STABLE i386 >Organization: Moscow State University >Environment: System: FreeBSD cell.sick.ru 4.7-STABLE FreeBSD 4.7-STABLE #9: Thu Dec 19 04:16:33 MSK 2002 root@cell.sick.ru:/usr/obj/usr/src/sys/NUCLEUS i386 mpd 3.10 from ports >Description: My host is a PPPoE client. As client software I use ppp(8). When I tried to move to mpd, I discovered that mpd does not starts, complaining in pppoe.c line 213 with "File already exists". >How-To-Repeat: Run another PPPoE client software, for example ppp(8), and then try mpd in pppoe mode. Do not reboot machine. >Fix: The code was taken directly from ppp(8). It first looks for created pppoe netgraph node, and uses it if one exists. Else a new node is created. --- pppoe.c.orig Fri Jan 24 20:15:56 2003 +++ pppoe.c Fri Jan 24 21:33:57 2003 @@ -161,6 +161,12 @@ struct ngpppoe_init_data *const idata = &u.poeid; char path[NG_PATHLEN + 1]; char linkHook[NG_HOOKLEN + 1]; + u_char rbuf[2048]; + struct ng_mesg *resp; + const struct hooklist *hlist; + const struct nodeinfo *ninfo; + const struct linkinfo *nlink; + int f; /* Sanity */ if (pe->state != PPPOE_DOWN) @@ -189,37 +195,93 @@ } (void)fcntl(pe->csock, F_SETFD, 1); -#if 0 /**** BUG IN NgSendAsciiMsg(), fixed in rev. 1.3 ****/ - /* Attach a new ng_pppoe(4) node to the Ethernet node */ - if (NgSendAsciiMsg(bund->csock, pe->path, + /* + * Ask for a list of hooks attached to the "ether" node. This node should + * magically exist as a way of hooking stuff onto an ethernet device + */ + if (NgSendMsg(bund->csock, pe->path, NGM_GENERIC_COOKIE, NGM_LISTHOOKS, + NULL, 0) < 0) { + Log(LG_ERR, ("[%s] Cannot send a netgraph message: %s:%s", + lnk->name, pe->path, strerror(errno))); + goto fail2; + } + + /* Get our list back */ + resp = (struct ng_mesg *)rbuf; + if (NgRecvMsg(bund->csock, resp, sizeof rbuf, NULL) <= 0) { + Log(LG_ERR, ("[%s] Cannot get netgraph response: %s", + lnk->name, strerror(errno))); + goto fail2; + } + + hlist = (const struct hooklist *)resp->data; + ninfo = &hlist->nodeinfo; + + /* Make sure we've got the right type of node */ + if (strncmp(ninfo->type, NG_ETHER_NODE_TYPE, + sizeof NG_ETHER_NODE_TYPE - 1)) { + Log(LG_ERR, ("[%s] Unexpected node type ``%s'' (wanted ``" NG_ETHER_NODE_TYPE "'') on %s", lnk->name, ninfo->type, pe->path)); + goto fail2; + } + + /* look for a hook already attached. */ + for (f = 0; f < ninfo->hooks; f++) { + nlink = &hlist->link[f]; + + if (!strcmp(nlink->ourhook, NG_ETHER_HOOK_ORPHAN) || + !strcmp(nlink->ourhook, NG_ETHER_HOOK_DIVERT)) { + /* + * Something is using the data coming out of this ``ether'' node. + * If it's a PPPoE node, we use that node, otherwise we complain that + * someone else is using the node. + */ + if (!strcmp(nlink->nodeinfo.type, NG_PPPOE_NODE_TYPE)) + /* Use this PPPoE node ! */ + snprintf(path, sizeof(path), "[%x]:", nlink->nodeinfo.id); + else { + Log(LG_ERR, ("%s Node type ``%s'' is currently active\n", + path, nlink->nodeinfo.type)); + goto fail2; + } + break; + } + } + + if (f == ninfo->hooks) { /* Create new PPP node */ + +#if 0 /**** BUG IN NgSendAsciiMsg(), fixed in rev. 1.3 ****/ + /* Attach a new ng_pppoe(4) node to the Ethernet node */ + if (NgSendAsciiMsg(bund->csock, pe->path, "mkpeer { type=\"%s\" ourhook=\"%s\" peerhook=\"%s\" }", NG_PPPOE_NODE_TYPE, pe->hook, NG_PPPOE_HOOK_ETHERNET) < 0) { Log(LG_ERR, ("[%s] can't create %s peer to %s,%s: %s", lnk->name, NG_PPPOE_NODE_TYPE, pe->path, pe->hook, strerror(errno))); goto fail2; - } + } #else - { - struct ngm_mkpeer mp; + { + struct ngm_mkpeer mp; - /* Create new PPP node */ - snprintf(mp.type, sizeof(mp.type), "%s", NG_PPPOE_NODE_TYPE); - snprintf(mp.ourhook, sizeof(mp.ourhook), "%s", pe->hook); - snprintf(mp.peerhook, sizeof(mp.peerhook), + snprintf(mp.type, sizeof(mp.type), "%s", NG_PPPOE_NODE_TYPE); + snprintf(mp.ourhook, sizeof(mp.ourhook), "%s", pe->hook); + snprintf(mp.peerhook, sizeof(mp.peerhook), "%s", NG_PPPOE_HOOK_ETHERNET); - if (NgSendMsg(bund->csock, pe->path, + if (NgSendMsg(bund->csock, pe->path, NGM_GENERIC_COOKIE, NGM_MKPEER, &mp, sizeof(mp)) < 0) { Log(LG_ERR, ("[%s] can't create %s peer to %s,%s: %s", lnk->name, NG_PPPOE_NODE_TYPE, pe->path, pe->hook, strerror(errno))); goto fail2; - } - } + } + } #endif /* Connect our ng_ppp(4) node link hook to the ng_pppoe(4) node */ snprintf(path, sizeof(path), "%s%s", pe->path, pe->hook); + + } + snprintf(linkHook, sizeof(linkHook), "%s%d", NG_PPP_HOOK_LINK_PREFIX, lnk->bundleIndex); if (NgFuncConnect(MPD_HOOK_PPP, linkHook, path, PPPOE_SESSION_HOOK) < 0) >Release-Note: >Audit-Trail: >Unformatted: To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-ports-bugs" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200302101248.h1ACm0Gx009329>