View | Details | Raw Unified | Return to bug 48138
Collapse All | Expand All

(-)pppoe.c (-13 / +75 lines)
Lines 161-166 Link Here
161
	struct ngpppoe_init_data *const idata = &u.poeid;
161
	struct ngpppoe_init_data *const idata = &u.poeid;
162
	char path[NG_PATHLEN + 1];
162
	char path[NG_PATHLEN + 1];
163
	char linkHook[NG_HOOKLEN + 1];
163
	char linkHook[NG_HOOKLEN + 1];
164
	u_char rbuf[2048];
165
	struct ng_mesg *resp;
166
	const struct hooklist *hlist;
167
	const struct nodeinfo *ninfo;
168
	const struct linkinfo *nlink;
169
	int f;
164
170
165
	/* Sanity */
171
	/* Sanity */
166
	if (pe->state != PPPOE_DOWN)
172
	if (pe->state != PPPOE_DOWN)
Lines 189-225 Link Here
189
	}
195
	}
190
	(void)fcntl(pe->csock, F_SETFD, 1);
196
	(void)fcntl(pe->csock, F_SETFD, 1);
191
197
192
#if 0	/**** BUG IN NgSendAsciiMsg(), fixed in rev. 1.3 ****/
198
	/*
193
	/* Attach a new ng_pppoe(4) node to the Ethernet node */
199
	* Ask for a list of hooks attached to the "ether" node.  This node should
194
	if (NgSendAsciiMsg(bund->csock, pe->path,
200
	* magically exist as a way of hooking stuff onto an ethernet device
201
	*/
202
	if (NgSendMsg(bund->csock, pe->path, NGM_GENERIC_COOKIE, NGM_LISTHOOKS,
203
		NULL, 0) < 0) {
204
		Log(LG_ERR, ("[%s] Cannot send a netgraph message: %s:%s",
205
                 lnk->name, pe->path, strerror(errno)));
206
		goto fail2;
207
	}
208
209
	/* Get our list back */
210
	resp = (struct ng_mesg *)rbuf;
211
	if (NgRecvMsg(bund->csock, resp, sizeof rbuf, NULL) <= 0) {
212
		Log(LG_ERR, ("[%s] Cannot get netgraph response: %s",
213
			lnk->name, strerror(errno)));
214
		goto fail2;
215
	}
216
217
	hlist = (const struct hooklist *)resp->data;
218
	ninfo = &hlist->nodeinfo;
219
220
	/* Make sure we've got the right type of node */
221
	if (strncmp(ninfo->type, NG_ETHER_NODE_TYPE,
222
		sizeof NG_ETHER_NODE_TYPE - 1)) {
223
		Log(LG_ERR, ("[%s] Unexpected node type ``%s'' (wanted ``" NG_ETHER_NODE_TYPE "'') on %s", lnk->name, ninfo->type, pe->path));
224
		goto fail2;
225
	}
226
227
	/* look for a hook already attached.  */
228
	for (f = 0; f < ninfo->hooks; f++) {
229
	  nlink = &hlist->link[f];
230
231
	  if (!strcmp(nlink->ourhook, NG_ETHER_HOOK_ORPHAN) ||
232
		!strcmp(nlink->ourhook, NG_ETHER_HOOK_DIVERT)) {
233
	  /*
234
	   * Something is using the data coming out of this ``ether'' node.
235
	   * If it's a PPPoE node, we use that node, otherwise we complain that
236
	   * someone else is using the node.
237
	   */
238
	  if (!strcmp(nlink->nodeinfo.type, NG_PPPOE_NODE_TYPE))
239
	     /* Use this PPPoE node ! */
240
	     snprintf(path, sizeof(path), "[%x]:", nlink->nodeinfo.id);
241
	  else {
242
		Log(LG_ERR, ("%s Node type ``%s'' is currently active\n",
243
                     path, nlink->nodeinfo.type));
244
		goto fail2;
245
	       }
246
	  break;
247
	  }
248
	}
249
250
	if (f == ninfo->hooks) { /* Create new PPP node */
251
252
#if 0	  /**** BUG IN NgSendAsciiMsg(), fixed in rev. 1.3 ****/
253
	  /* Attach a new ng_pppoe(4) node to the Ethernet node */
254
	  if (NgSendAsciiMsg(bund->csock, pe->path,
195
	    "mkpeer { type=\"%s\" ourhook=\"%s\" peerhook=\"%s\" }",
255
	    "mkpeer { type=\"%s\" ourhook=\"%s\" peerhook=\"%s\" }",
196
	    NG_PPPOE_NODE_TYPE, pe->hook, NG_PPPOE_HOOK_ETHERNET) < 0) {
256
	    NG_PPPOE_NODE_TYPE, pe->hook, NG_PPPOE_HOOK_ETHERNET) < 0) {
197
		Log(LG_ERR, ("[%s] can't create %s peer to %s,%s: %s",
257
		Log(LG_ERR, ("[%s] can't create %s peer to %s,%s: %s",
198
		    lnk->name, NG_PPPOE_NODE_TYPE,
258
		    lnk->name, NG_PPPOE_NODE_TYPE,
199
		    pe->path, pe->hook, strerror(errno)));
259
		    pe->path, pe->hook, strerror(errno)));
200
		goto fail2;
260
		goto fail2;
201
	}
261
	  }
202
#else
262
#else
203
    {
263
        {
204
	struct ngm_mkpeer mp;
264
	  struct ngm_mkpeer mp;
205
265
206
	/* Create new PPP node */
266
	  snprintf(mp.type, sizeof(mp.type), "%s", NG_PPPOE_NODE_TYPE);
207
	snprintf(mp.type, sizeof(mp.type), "%s", NG_PPPOE_NODE_TYPE);
267
	  snprintf(mp.ourhook, sizeof(mp.ourhook), "%s", pe->hook);
208
	snprintf(mp.ourhook, sizeof(mp.ourhook), "%s", pe->hook);
268
	  snprintf(mp.peerhook, sizeof(mp.peerhook),
209
	snprintf(mp.peerhook, sizeof(mp.peerhook),
210
	    "%s", NG_PPPOE_HOOK_ETHERNET);
269
	    "%s", NG_PPPOE_HOOK_ETHERNET);
211
	if (NgSendMsg(bund->csock, pe->path,
270
	  if (NgSendMsg(bund->csock, pe->path,
212
	    NGM_GENERIC_COOKIE, NGM_MKPEER, &mp, sizeof(mp)) < 0) {
271
	    NGM_GENERIC_COOKIE, NGM_MKPEER, &mp, sizeof(mp)) < 0) {
213
		Log(LG_ERR, ("[%s] can't create %s peer to %s,%s: %s",
272
		Log(LG_ERR, ("[%s] can't create %s peer to %s,%s: %s",
214
		    lnk->name, NG_PPPOE_NODE_TYPE,
273
		    lnk->name, NG_PPPOE_NODE_TYPE,
215
		    pe->path, pe->hook, strerror(errno)));
274
		    pe->path, pe->hook, strerror(errno)));
216
		goto fail2;
275
		goto fail2;
217
	}
276
	  }
218
    }
277
        }
219
#endif
278
#endif
220
279
221
	/* Connect our ng_ppp(4) node link hook to the ng_pppoe(4) node */
280
	/* Connect our ng_ppp(4) node link hook to the ng_pppoe(4) node */
222
	snprintf(path, sizeof(path), "%s%s", pe->path, pe->hook);
281
	snprintf(path, sizeof(path), "%s%s", pe->path, pe->hook);
282
283
	}
284
223
	snprintf(linkHook, sizeof(linkHook),
285
	snprintf(linkHook, sizeof(linkHook),
224
	    "%s%d", NG_PPP_HOOK_LINK_PREFIX, lnk->bundleIndex);
286
	    "%s%d", NG_PPP_HOOK_LINK_PREFIX, lnk->bundleIndex);
225
	if (NgFuncConnect(MPD_HOOK_PPP, linkHook, path, PPPOE_SESSION_HOOK) < 0)
287
	if (NgFuncConnect(MPD_HOOK_PPP, linkHook, path, PPPOE_SESSION_HOOK) < 0)

Return to bug 48138