1/*- 2 * Copyright (c) 1999 Brian Somers <brian@Awfulhak.org> 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. 13 * 14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 * SUCH DAMAGE. 25 *
| 1/*- 2 * Copyright (c) 1999 Brian Somers <brian@Awfulhak.org> 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. 13 * 14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 * SUCH DAMAGE. 25 *
|
26 * $FreeBSD: head/usr.sbin/ppp/ether.c 71006 2001-01-14 00:54:48Z brian $
| 26 * $FreeBSD: head/usr.sbin/ppp/ether.c 74916 2001-03-28 09:45:27Z brian $
|
27 */ 28 29#include <sys/param.h> 30#include <sys/socket.h> 31#include <sys/un.h> 32#include <netinet/in.h> 33#include <arpa/inet.h> 34#include <netdb.h> 35#include <netgraph.h> 36#include <net/ethernet.h>
| 27 */ 28 29#include <sys/param.h> 30#include <sys/socket.h> 31#include <sys/un.h> 32#include <netinet/in.h> 33#include <arpa/inet.h> 34#include <netdb.h> 35#include <netgraph.h> 36#include <net/ethernet.h>
|
| 37#include <net/if.h> 38#include <net/route.h>
|
37#include <netinet/in_systm.h> 38#include <netinet/ip.h> 39#include <netgraph/ng_ether.h> 40#include <netgraph/ng_message.h> 41#include <netgraph/ng_pppoe.h> 42#include <netgraph/ng_socket.h> 43 44#include <errno.h> 45#include <stdio.h> 46#include <stdlib.h> 47#include <string.h> 48#include <sysexits.h> 49#include <sys/fcntl.h> 50#if defined(__FreeBSD__) && !defined(NOKLDLOAD) 51#include <sys/linker.h> 52#include <sys/module.h> 53#endif 54#include <sys/stat.h> 55#include <sys/uio.h> 56#include <termios.h> 57#include <sys/time.h> 58#include <unistd.h> 59 60#include "layer.h" 61#include "defs.h" 62#include "mbuf.h" 63#include "log.h" 64#include "timer.h" 65#include "lqr.h" 66#include "hdlc.h" 67#include "throughput.h" 68#include "fsm.h" 69#include "lcp.h" 70#include "ccp.h" 71#include "link.h" 72#include "async.h" 73#include "descriptor.h" 74#include "physical.h" 75#include "main.h" 76#include "mp.h" 77#include "chat.h" 78#include "auth.h" 79#include "chap.h" 80#include "cbcp.h" 81#include "datalink.h" 82#include "slcompress.h" 83#include "iplist.h" 84#include "ipcp.h" 85#include "filter.h" 86#ifndef NORADIUS 87#include "radius.h" 88#endif 89#include "bundle.h" 90#include "id.h"
| 39#include <netinet/in_systm.h> 40#include <netinet/ip.h> 41#include <netgraph/ng_ether.h> 42#include <netgraph/ng_message.h> 43#include <netgraph/ng_pppoe.h> 44#include <netgraph/ng_socket.h> 45 46#include <errno.h> 47#include <stdio.h> 48#include <stdlib.h> 49#include <string.h> 50#include <sysexits.h> 51#include <sys/fcntl.h> 52#if defined(__FreeBSD__) && !defined(NOKLDLOAD) 53#include <sys/linker.h> 54#include <sys/module.h> 55#endif 56#include <sys/stat.h> 57#include <sys/uio.h> 58#include <termios.h> 59#include <sys/time.h> 60#include <unistd.h> 61 62#include "layer.h" 63#include "defs.h" 64#include "mbuf.h" 65#include "log.h" 66#include "timer.h" 67#include "lqr.h" 68#include "hdlc.h" 69#include "throughput.h" 70#include "fsm.h" 71#include "lcp.h" 72#include "ccp.h" 73#include "link.h" 74#include "async.h" 75#include "descriptor.h" 76#include "physical.h" 77#include "main.h" 78#include "mp.h" 79#include "chat.h" 80#include "auth.h" 81#include "chap.h" 82#include "cbcp.h" 83#include "datalink.h" 84#include "slcompress.h" 85#include "iplist.h" 86#include "ipcp.h" 87#include "filter.h" 88#ifndef NORADIUS 89#include "radius.h" 90#endif 91#include "bundle.h" 92#include "id.h"
|
| 93#include "iface.h"
|
91#include "ether.h" 92 93 94#define PPPOE_NODE_TYPE_LEN (sizeof NG_PPPOE_NODE_TYPE - 1) /* "PPPoE" */ 95 96struct etherdevice { 97 struct device dev; /* What struct physical knows about */ 98 int cs; /* Control socket */ 99 int connected; /* Are we connected yet ? */ 100 int timeout; /* Seconds attempting to connect */ 101 char hook[sizeof TUN_NAME + 11]; /* Our socket node hook */ 102}; 103 104#define device2ether(d) \ 105 ((d)->type == ETHER_DEVICE ? (struct etherdevice *)d : NULL) 106 107int 108ether_DeviceSize(void) 109{ 110 return sizeof(struct etherdevice); 111} 112 113static ssize_t 114ether_Write(struct physical *p, const void *v, size_t n) 115{ 116 struct etherdevice *dev = device2ether(p->handler); 117 118 return NgSendData(p->fd, dev->hook, v, n) == -1 ? -1 : n; 119} 120 121static ssize_t 122ether_Read(struct physical *p, void *v, size_t n) 123{ 124 char hook[sizeof TUN_NAME + 11]; 125 126 return NgRecvData(p->fd, v, n, hook); 127} 128 129static int 130ether_RemoveFromSet(struct physical *p, fd_set *r, fd_set *w, fd_set *e) 131{ 132 struct etherdevice *dev = device2ether(p->handler); 133 int result; 134 135 if (r && dev->cs >= 0 && FD_ISSET(dev->cs, r)) { 136 FD_CLR(dev->cs, r); 137 log_Printf(LogTIMER, "%s: fdunset(ctrl) %d\n", p->link.name, dev->cs); 138 result = 1; 139 } else 140 result = 0; 141 142 /* Careful... physical_RemoveFromSet() called us ! */ 143 144 p->handler->removefromset = NULL; 145 result += physical_RemoveFromSet(p, r, w, e); 146 p->handler->removefromset = ether_RemoveFromSet; 147 148 return result; 149} 150 151static void 152ether_Free(struct physical *p) 153{ 154 struct etherdevice *dev = device2ether(p->handler); 155 156 physical_SetDescriptor(p); 157 if (dev->cs != -1) 158 close(dev->cs); 159 free(dev); 160} 161 162static const char * 163ether_OpenInfo(struct physical *p) 164{ 165 struct etherdevice *dev = device2ether(p->handler); 166 167 switch (dev->connected) { 168 case CARRIER_PENDING: 169 return "negotiating"; 170 case CARRIER_OK: 171 return "established"; 172 } 173 174 return "disconnected"; 175} 176 177static void 178ether_device2iov(struct device *d, struct iovec *iov, int *niov, 179 int maxiov, int *auxfd, int *nauxfd) 180{ 181 struct etherdevice *dev = device2ether(d); 182 int sz = physical_MaxDeviceSize(); 183 184 iov[*niov].iov_base = realloc(d, sz); 185 if (iov[*niov].iov_base == NULL) { 186 log_Printf(LogALERT, "Failed to allocate memory: %d\n", sz); 187 AbortProgram(EX_OSERR); 188 } 189 iov[*niov].iov_len = sz; 190 (*niov)++; 191 192 if (dev->cs >= 0) { 193 *auxfd = dev->cs; 194 (*nauxfd)++; 195 } 196} 197 198static void 199ether_MessageIn(struct etherdevice *dev) 200{ 201 char msgbuf[sizeof(struct ng_mesg) + sizeof(struct ngpppoe_sts)]; 202 struct ng_mesg *rep = (struct ng_mesg *)msgbuf; 203 struct ngpppoe_sts *sts = (struct ngpppoe_sts *)(msgbuf + sizeof *rep); 204 char unknown[14]; 205 const char *msg; 206 struct timeval t; 207 fd_set *r; 208 int ret; 209 210 if (dev->cs < 0) 211 return; 212 213 if ((r = mkfdset()) == NULL) { 214 log_Printf(LogERROR, "DoLoop: Cannot create fd_set\n"); 215 return; 216 } 217 zerofdset(r); 218 FD_SET(dev->cs, r); 219 t.tv_sec = t.tv_usec = 0; 220 ret = select(dev->cs + 1, r, NULL, NULL, &t); 221 free(r); 222 223 if (ret <= 0) 224 return; 225 226 if (NgRecvMsg(dev->cs, rep, sizeof msgbuf, NULL) < 0) 227 return; 228 229 if (rep->header.version != NG_VERSION) { 230 log_Printf(LogWARN, "%ld: Unexpected netgraph version, expected %ld\n", 231 (long)rep->header.version, (long)NG_VERSION); 232 return; 233 } 234 235 if (rep->header.typecookie != NGM_PPPOE_COOKIE) { 236 log_Printf(LogWARN, "%ld: Unexpected netgraph cookie, expected %ld\n", 237 (long)rep->header.typecookie, (long)NGM_PPPOE_COOKIE); 238 return; 239 } 240 241 switch (rep->header.cmd) { 242 case NGM_PPPOE_SET_FLAG: msg = "SET_FLAG"; break; 243 case NGM_PPPOE_CONNECT: msg = "CONNECT"; break; 244 case NGM_PPPOE_LISTEN: msg = "LISTEN"; break; 245 case NGM_PPPOE_OFFER: msg = "OFFER"; break; 246 case NGM_PPPOE_SUCCESS: msg = "SUCCESS"; break; 247 case NGM_PPPOE_FAIL: msg = "FAIL"; break; 248 case NGM_PPPOE_CLOSE: msg = "CLOSE"; break; 249 case NGM_PPPOE_GET_STATUS: msg = "GET_STATUS"; break; 250 default: 251 snprintf(unknown, sizeof unknown, "<%d>", (int)rep->header.cmd); 252 msg = unknown; 253 break; 254 } 255 256 log_Printf(LogPHASE, "Received NGM_PPPOE_%s (hook \"%s\")\n", msg, sts->hook); 257 258 switch (rep->header.cmd) { 259 case NGM_PPPOE_SUCCESS: 260 dev->connected = CARRIER_OK; 261 break; 262 case NGM_PPPOE_FAIL: 263 case NGM_PPPOE_CLOSE: 264 dev->connected = CARRIER_LOST; 265 break; 266 } 267} 268 269static int 270ether_AwaitCarrier(struct physical *p) 271{ 272 struct etherdevice *dev = device2ether(p->handler); 273 274 if (dev->connected != CARRIER_OK && !dev->timeout--) 275 dev->connected = CARRIER_LOST; 276 else if (dev->connected == CARRIER_PENDING) 277 ether_MessageIn(dev); 278 279 return dev->connected; 280} 281 282static const struct device baseetherdevice = { 283 ETHER_DEVICE, 284 "ether", 285 { CD_REQUIRED, DEF_ETHERCDDELAY }, 286 ether_AwaitCarrier, 287 ether_RemoveFromSet, 288 NULL, 289 NULL, 290 NULL, 291 NULL, 292 ether_Free, 293 ether_Read, 294 ether_Write, 295 ether_device2iov, 296 NULL, 297 ether_OpenInfo 298}; 299 300struct device * 301ether_iov2device(int type, struct physical *p, struct iovec *iov, int *niov, 302 int maxiov, int *auxfd, int *nauxfd) 303{ 304 if (type == ETHER_DEVICE) { 305 struct etherdevice *dev = (struct etherdevice *)iov[(*niov)++].iov_base; 306 307 dev = realloc(dev, sizeof *dev); /* Reduce to the correct size */ 308 if (dev == NULL) { 309 log_Printf(LogALERT, "Failed to allocate memory: %d\n", 310 (int)(sizeof *dev)); 311 AbortProgram(EX_OSERR); 312 } 313 314 if (*nauxfd) { 315 dev->cs = *auxfd; 316 (*nauxfd)--; 317 } else 318 dev->cs = -1; 319 320 /* Refresh function pointers etc */ 321 memcpy(&dev->dev, &baseetherdevice, sizeof dev->dev); 322 323 physical_SetupStack(p, dev->dev.name, PHYSICAL_FORCE_SYNCNOACF); 324 return &dev->dev; 325 } 326 327 return NULL; 328} 329 330static int 331ether_UpdateSet(struct fdescriptor *d, fd_set *r, fd_set *w, fd_set *e, int *n) 332{ 333 struct physical *p = descriptor2physical(d); 334 struct etherdevice *dev = device2ether(p->handler); 335 int result; 336 337 if (r && dev->cs >= 0) { 338 FD_SET(dev->cs, r); 339 log_Printf(LogTIMER, "%s(ctrl): fdset(r) %d\n", p->link.name, dev->cs); 340 result = 1; 341 } else 342 result = 0; 343 344 result += physical_doUpdateSet(d, r, w, e, n, 0); 345 346 return result; 347} 348 349static int 350ether_IsSet(struct fdescriptor *d, const fd_set *fdset) 351{ 352 struct physical *p = descriptor2physical(d); 353 struct etherdevice *dev = device2ether(p->handler); 354 int result; 355 356 result = dev->cs >= 0 && FD_ISSET(dev->cs, fdset); 357 result += physical_IsSet(d, fdset); 358 359 return result; 360} 361 362static void 363ether_DescriptorRead(struct fdescriptor *d, struct bundle *bundle, 364 const fd_set *fdset) 365{ 366 struct physical *p = descriptor2physical(d); 367 struct etherdevice *dev = device2ether(p->handler); 368 369 if (dev->cs >= 0 && FD_ISSET(dev->cs, fdset)) { 370 ether_MessageIn(dev); 371 if (dev->connected == CARRIER_LOST) { 372 log_Printf(LogPHASE, "%s: Device disconnected\n", p->link.name); 373 datalink_Down(p->dl, CLOSE_NORMAL); 374 return; 375 } 376 } 377 378 if (physical_IsSet(d, fdset)) 379 physical_DescriptorRead(d, bundle, fdset); 380} 381 382static struct device * 383ether_Abandon(struct etherdevice *dev, struct physical *p) 384{ 385 /* Abandon our node construction */ 386 close(dev->cs); 387 close(p->fd); 388 p->fd = -2; /* Nobody else need try.. */ 389 free(dev); 390 391 return NULL; 392} 393 394struct device * 395ether_Create(struct physical *p) 396{ 397 u_char rbuf[2048]; 398 struct etherdevice *dev; 399 struct ng_mesg *resp; 400 const struct hooklist *hlist; 401 const struct nodeinfo *ninfo;
| 94#include "ether.h" 95 96 97#define PPPOE_NODE_TYPE_LEN (sizeof NG_PPPOE_NODE_TYPE - 1) /* "PPPoE" */ 98 99struct etherdevice { 100 struct device dev; /* What struct physical knows about */ 101 int cs; /* Control socket */ 102 int connected; /* Are we connected yet ? */ 103 int timeout; /* Seconds attempting to connect */ 104 char hook[sizeof TUN_NAME + 11]; /* Our socket node hook */ 105}; 106 107#define device2ether(d) \ 108 ((d)->type == ETHER_DEVICE ? (struct etherdevice *)d : NULL) 109 110int 111ether_DeviceSize(void) 112{ 113 return sizeof(struct etherdevice); 114} 115 116static ssize_t 117ether_Write(struct physical *p, const void *v, size_t n) 118{ 119 struct etherdevice *dev = device2ether(p->handler); 120 121 return NgSendData(p->fd, dev->hook, v, n) == -1 ? -1 : n; 122} 123 124static ssize_t 125ether_Read(struct physical *p, void *v, size_t n) 126{ 127 char hook[sizeof TUN_NAME + 11]; 128 129 return NgRecvData(p->fd, v, n, hook); 130} 131 132static int 133ether_RemoveFromSet(struct physical *p, fd_set *r, fd_set *w, fd_set *e) 134{ 135 struct etherdevice *dev = device2ether(p->handler); 136 int result; 137 138 if (r && dev->cs >= 0 && FD_ISSET(dev->cs, r)) { 139 FD_CLR(dev->cs, r); 140 log_Printf(LogTIMER, "%s: fdunset(ctrl) %d\n", p->link.name, dev->cs); 141 result = 1; 142 } else 143 result = 0; 144 145 /* Careful... physical_RemoveFromSet() called us ! */ 146 147 p->handler->removefromset = NULL; 148 result += physical_RemoveFromSet(p, r, w, e); 149 p->handler->removefromset = ether_RemoveFromSet; 150 151 return result; 152} 153 154static void 155ether_Free(struct physical *p) 156{ 157 struct etherdevice *dev = device2ether(p->handler); 158 159 physical_SetDescriptor(p); 160 if (dev->cs != -1) 161 close(dev->cs); 162 free(dev); 163} 164 165static const char * 166ether_OpenInfo(struct physical *p) 167{ 168 struct etherdevice *dev = device2ether(p->handler); 169 170 switch (dev->connected) { 171 case CARRIER_PENDING: 172 return "negotiating"; 173 case CARRIER_OK: 174 return "established"; 175 } 176 177 return "disconnected"; 178} 179 180static void 181ether_device2iov(struct device *d, struct iovec *iov, int *niov, 182 int maxiov, int *auxfd, int *nauxfd) 183{ 184 struct etherdevice *dev = device2ether(d); 185 int sz = physical_MaxDeviceSize(); 186 187 iov[*niov].iov_base = realloc(d, sz); 188 if (iov[*niov].iov_base == NULL) { 189 log_Printf(LogALERT, "Failed to allocate memory: %d\n", sz); 190 AbortProgram(EX_OSERR); 191 } 192 iov[*niov].iov_len = sz; 193 (*niov)++; 194 195 if (dev->cs >= 0) { 196 *auxfd = dev->cs; 197 (*nauxfd)++; 198 } 199} 200 201static void 202ether_MessageIn(struct etherdevice *dev) 203{ 204 char msgbuf[sizeof(struct ng_mesg) + sizeof(struct ngpppoe_sts)]; 205 struct ng_mesg *rep = (struct ng_mesg *)msgbuf; 206 struct ngpppoe_sts *sts = (struct ngpppoe_sts *)(msgbuf + sizeof *rep); 207 char unknown[14]; 208 const char *msg; 209 struct timeval t; 210 fd_set *r; 211 int ret; 212 213 if (dev->cs < 0) 214 return; 215 216 if ((r = mkfdset()) == NULL) { 217 log_Printf(LogERROR, "DoLoop: Cannot create fd_set\n"); 218 return; 219 } 220 zerofdset(r); 221 FD_SET(dev->cs, r); 222 t.tv_sec = t.tv_usec = 0; 223 ret = select(dev->cs + 1, r, NULL, NULL, &t); 224 free(r); 225 226 if (ret <= 0) 227 return; 228 229 if (NgRecvMsg(dev->cs, rep, sizeof msgbuf, NULL) < 0) 230 return; 231 232 if (rep->header.version != NG_VERSION) { 233 log_Printf(LogWARN, "%ld: Unexpected netgraph version, expected %ld\n", 234 (long)rep->header.version, (long)NG_VERSION); 235 return; 236 } 237 238 if (rep->header.typecookie != NGM_PPPOE_COOKIE) { 239 log_Printf(LogWARN, "%ld: Unexpected netgraph cookie, expected %ld\n", 240 (long)rep->header.typecookie, (long)NGM_PPPOE_COOKIE); 241 return; 242 } 243 244 switch (rep->header.cmd) { 245 case NGM_PPPOE_SET_FLAG: msg = "SET_FLAG"; break; 246 case NGM_PPPOE_CONNECT: msg = "CONNECT"; break; 247 case NGM_PPPOE_LISTEN: msg = "LISTEN"; break; 248 case NGM_PPPOE_OFFER: msg = "OFFER"; break; 249 case NGM_PPPOE_SUCCESS: msg = "SUCCESS"; break; 250 case NGM_PPPOE_FAIL: msg = "FAIL"; break; 251 case NGM_PPPOE_CLOSE: msg = "CLOSE"; break; 252 case NGM_PPPOE_GET_STATUS: msg = "GET_STATUS"; break; 253 default: 254 snprintf(unknown, sizeof unknown, "<%d>", (int)rep->header.cmd); 255 msg = unknown; 256 break; 257 } 258 259 log_Printf(LogPHASE, "Received NGM_PPPOE_%s (hook \"%s\")\n", msg, sts->hook); 260 261 switch (rep->header.cmd) { 262 case NGM_PPPOE_SUCCESS: 263 dev->connected = CARRIER_OK; 264 break; 265 case NGM_PPPOE_FAIL: 266 case NGM_PPPOE_CLOSE: 267 dev->connected = CARRIER_LOST; 268 break; 269 } 270} 271 272static int 273ether_AwaitCarrier(struct physical *p) 274{ 275 struct etherdevice *dev = device2ether(p->handler); 276 277 if (dev->connected != CARRIER_OK && !dev->timeout--) 278 dev->connected = CARRIER_LOST; 279 else if (dev->connected == CARRIER_PENDING) 280 ether_MessageIn(dev); 281 282 return dev->connected; 283} 284 285static const struct device baseetherdevice = { 286 ETHER_DEVICE, 287 "ether", 288 { CD_REQUIRED, DEF_ETHERCDDELAY }, 289 ether_AwaitCarrier, 290 ether_RemoveFromSet, 291 NULL, 292 NULL, 293 NULL, 294 NULL, 295 ether_Free, 296 ether_Read, 297 ether_Write, 298 ether_device2iov, 299 NULL, 300 ether_OpenInfo 301}; 302 303struct device * 304ether_iov2device(int type, struct physical *p, struct iovec *iov, int *niov, 305 int maxiov, int *auxfd, int *nauxfd) 306{ 307 if (type == ETHER_DEVICE) { 308 struct etherdevice *dev = (struct etherdevice *)iov[(*niov)++].iov_base; 309 310 dev = realloc(dev, sizeof *dev); /* Reduce to the correct size */ 311 if (dev == NULL) { 312 log_Printf(LogALERT, "Failed to allocate memory: %d\n", 313 (int)(sizeof *dev)); 314 AbortProgram(EX_OSERR); 315 } 316 317 if (*nauxfd) { 318 dev->cs = *auxfd; 319 (*nauxfd)--; 320 } else 321 dev->cs = -1; 322 323 /* Refresh function pointers etc */ 324 memcpy(&dev->dev, &baseetherdevice, sizeof dev->dev); 325 326 physical_SetupStack(p, dev->dev.name, PHYSICAL_FORCE_SYNCNOACF); 327 return &dev->dev; 328 } 329 330 return NULL; 331} 332 333static int 334ether_UpdateSet(struct fdescriptor *d, fd_set *r, fd_set *w, fd_set *e, int *n) 335{ 336 struct physical *p = descriptor2physical(d); 337 struct etherdevice *dev = device2ether(p->handler); 338 int result; 339 340 if (r && dev->cs >= 0) { 341 FD_SET(dev->cs, r); 342 log_Printf(LogTIMER, "%s(ctrl): fdset(r) %d\n", p->link.name, dev->cs); 343 result = 1; 344 } else 345 result = 0; 346 347 result += physical_doUpdateSet(d, r, w, e, n, 0); 348 349 return result; 350} 351 352static int 353ether_IsSet(struct fdescriptor *d, const fd_set *fdset) 354{ 355 struct physical *p = descriptor2physical(d); 356 struct etherdevice *dev = device2ether(p->handler); 357 int result; 358 359 result = dev->cs >= 0 && FD_ISSET(dev->cs, fdset); 360 result += physical_IsSet(d, fdset); 361 362 return result; 363} 364 365static void 366ether_DescriptorRead(struct fdescriptor *d, struct bundle *bundle, 367 const fd_set *fdset) 368{ 369 struct physical *p = descriptor2physical(d); 370 struct etherdevice *dev = device2ether(p->handler); 371 372 if (dev->cs >= 0 && FD_ISSET(dev->cs, fdset)) { 373 ether_MessageIn(dev); 374 if (dev->connected == CARRIER_LOST) { 375 log_Printf(LogPHASE, "%s: Device disconnected\n", p->link.name); 376 datalink_Down(p->dl, CLOSE_NORMAL); 377 return; 378 } 379 } 380 381 if (physical_IsSet(d, fdset)) 382 physical_DescriptorRead(d, bundle, fdset); 383} 384 385static struct device * 386ether_Abandon(struct etherdevice *dev, struct physical *p) 387{ 388 /* Abandon our node construction */ 389 close(dev->cs); 390 close(p->fd); 391 p->fd = -2; /* Nobody else need try.. */ 392 free(dev); 393 394 return NULL; 395} 396 397struct device * 398ether_Create(struct physical *p) 399{ 400 u_char rbuf[2048]; 401 struct etherdevice *dev; 402 struct ng_mesg *resp; 403 const struct hooklist *hlist; 404 const struct nodeinfo *ninfo;
|
402 int f;
| 405 char *path; 406 int ifacelen, f;
|
403 404 dev = NULL;
| 407 408 dev = NULL;
|
| 409 path = NULL; 410 ifacelen = 0;
|
405 if (p->fd < 0 && !strncasecmp(p->name.full, NG_PPPOE_NODE_TYPE, 406 PPPOE_NODE_TYPE_LEN) && 407 p->name.full[PPPOE_NODE_TYPE_LEN] == ':') { 408 const struct linkinfo *nlink; 409 struct ngpppoe_init_data *data; 410 struct ngm_mkpeer mkp; 411 struct ngm_connect ngc; 412 const char *iface, *provider;
| 411 if (p->fd < 0 && !strncasecmp(p->name.full, NG_PPPOE_NODE_TYPE, 412 PPPOE_NODE_TYPE_LEN) && 413 p->name.full[PPPOE_NODE_TYPE_LEN] == ':') { 414 const struct linkinfo *nlink; 415 struct ngpppoe_init_data *data; 416 struct ngm_mkpeer mkp; 417 struct ngm_connect ngc; 418 const char *iface, *provider;
|
413 char *path, etherid[12]; 414 int ifacelen, providerlen;
| 419 char etherid[12]; 420 int providerlen;
|
415 char connectpath[sizeof dev->hook + 2]; /* .:<hook> */ 416 417 p->fd--; /* We own the device - change fd */ 418 419#if defined(__FreeBSD__) && !defined(NOKLDLOAD) 420 if (modfind("netgraph") == -1) { 421 log_Printf(LogWARN, "Netgraph is not built into the kernel\n"); 422 return NULL; 423 } 424 425 if (modfind("ng_ether") == -1 && ID0kldload("ng_ether") == -1) 426 /* 427 * Don't treat this as an error as older kernels have this stuff 428 * built in as part of the netgraph node itself. 429 */ 430 log_Printf(LogWARN, "kldload: ng_ether: %s\n", strerror(errno)); 431 432 if (modfind("ng_socket") == -1 && ID0kldload("ng_socket") == -1) { 433 log_Printf(LogWARN, "kldload: ng_socket: %s\n", strerror(errno)); 434 return NULL; 435 } 436#endif 437 438 if ((dev = malloc(sizeof *dev)) == NULL) 439 return NULL; 440 441 iface = p->name.full + PPPOE_NODE_TYPE_LEN + 1; 442 443 provider = strchr(iface, ':'); 444 if (provider) { 445 ifacelen = provider - iface; 446 provider++; 447 providerlen = strlen(provider); 448 } else { 449 ifacelen = strlen(iface); 450 provider = ""; 451 providerlen = 0; 452 } 453 454 /* 455 * We're going to do this (where tunN is our tunnel device): 456 * 457 * .---------. 458 * | ether | 459 * | <iface> | dev->cs 460 * `---------' | 461 * (orphan) p->fd | 462 * | | | 463 * | | | 464 * (ethernet) | | 465 * .---------. .-----------. 466 * | pppoe | | socket | 467 * | <iface> |(tunN)<---->(tunN)| <unnamed> | 468 * `--------- `-----------' 469 * (tunX) 470 * ^ 471 * | 472 * `--->(tunX) 473 */ 474 475 /* Create a socket node */ 476 if (ID0NgMkSockNode(NULL, &dev->cs, &p->fd) == -1) { 477 log_Printf(LogWARN, "Cannot create netgraph socket node: %s\n", 478 strerror(errno)); 479 free(dev); 480 return NULL; 481 } 482 483 /* 484 * Ask for a list of hooks attached to the "ether" node. This node should 485 * magically exist as a way of hooking stuff onto an ethernet device 486 */ 487 path = (char *)alloca(ifacelen + 2); 488 sprintf(path, "%.*s:", ifacelen, iface); 489 if (NgSendMsg(dev->cs, path, NGM_GENERIC_COOKIE, NGM_LISTHOOKS, 490 NULL, 0) < 0) { 491 log_Printf(LogWARN, "%s Cannot send a netgraph message: %s\n", 492 path, strerror(errno)); 493 return ether_Abandon(dev, p); 494 } 495 496 /* Get our list back */ 497 resp = (struct ng_mesg *)rbuf; 498 if (NgRecvMsg(dev->cs, resp, sizeof rbuf, NULL) < 0) { 499 log_Printf(LogWARN, "Cannot get netgraph response: %s\n", 500 strerror(errno)); 501 return ether_Abandon(dev, p); 502 } 503 504 hlist = (const struct hooklist *)resp->data; 505 ninfo = &hlist->nodeinfo; 506 507 /* Make sure we've got the right type of node */ 508 if (strncmp(ninfo->type, NG_ETHER_NODE_TYPE, 509 sizeof NG_ETHER_NODE_TYPE - 1)) { 510 log_Printf(LogWARN, "%s Unexpected node type ``%s'' (wanted ``" 511 NG_ETHER_NODE_TYPE "'')\n", path, ninfo->type); 512 return ether_Abandon(dev, p); 513 } 514 515 log_Printf(LogDEBUG, "List of netgraph node ``%s'' (id %x) hooks:\n", 516 path, ninfo->id); 517 518 /* look for a hook already attached. */ 519 for (f = 0; f < ninfo->hooks; f++) { 520 nlink = &hlist->link[f]; 521 522 log_Printf(LogDEBUG, " Found %s -> %s\n", nlink->ourhook, 523 nlink->peerhook); 524 525 if (!strcmp(nlink->ourhook, NG_ETHER_HOOK_ORPHAN) || 526 !strcmp(nlink->ourhook, NG_ETHER_HOOK_DIVERT)) { 527 /* 528 * Something is using the data coming out of this ``ether'' node. 529 * If it's a PPPoE node, we use that node, otherwise we complain that 530 * someone else is using the node. 531 */ 532 if (!strcmp(nlink->nodeinfo.type, NG_PPPOE_NODE_TYPE)) 533 /* Use this PPPoE node ! */ 534 snprintf(ngc.path, sizeof ngc.path, "[%x]:", nlink->nodeinfo.id); 535 else { 536 log_Printf(LogWARN, "%s Node type ``%s'' is currently active\n", 537 path, nlink->nodeinfo.type); 538 return ether_Abandon(dev, p); 539 } 540 break; 541 } 542 } 543 544 if (f == ninfo->hooks) { 545 /* 546 * Create a new ``PPPoE'' node connected to the ``ether'' node using 547 * the magic ``orphan'' and ``ethernet'' hooks 548 */ 549 snprintf(mkp.type, sizeof mkp.type, "%s", NG_PPPOE_NODE_TYPE); 550 snprintf(mkp.ourhook, sizeof mkp.ourhook, "%s", NG_ETHER_HOOK_ORPHAN); 551 snprintf(mkp.peerhook, sizeof mkp.peerhook, "%s", NG_PPPOE_HOOK_ETHERNET); 552 snprintf(etherid, sizeof etherid, "[%x]:", ninfo->id); 553 554 log_Printf(LogDEBUG, "Creating PPPoE netgraph node %s%s -> %s\n", 555 etherid, mkp.ourhook, mkp.peerhook); 556 557 if (NgSendMsg(dev->cs, etherid, NGM_GENERIC_COOKIE, 558 NGM_MKPEER, &mkp, sizeof mkp) < 0) { 559 log_Printf(LogWARN, "%s Cannot create PPPoE netgraph node: %s\n", 560 etherid, strerror(errno)); 561 return ether_Abandon(dev, p); 562 } 563 564 snprintf(ngc.path, sizeof ngc.path, "%s%s", path, NG_ETHER_HOOK_ORPHAN); 565 } 566 567 snprintf(dev->hook, sizeof dev->hook, "%s%d", 568 TUN_NAME, p->dl->bundle->unit); 569 570 /* 571 * Connect the PPPoE node to our socket node. 572 * ngc.path has already been set up 573 */ 574 snprintf(ngc.ourhook, sizeof ngc.ourhook, "%s", dev->hook); 575 memcpy(ngc.peerhook, ngc.ourhook, sizeof ngc.peerhook); 576 577 log_Printf(LogDEBUG, "Connecting netgraph socket .:%s -> %s:%s\n", 578 ngc.ourhook, ngc.path, ngc.peerhook); 579 if (NgSendMsg(dev->cs, ".:", NGM_GENERIC_COOKIE, 580 NGM_CONNECT, &ngc, sizeof ngc) < 0) { 581 log_Printf(LogWARN, "Cannot connect PPPoE and socket netgraph " 582 "nodes: %s\n", strerror(errno)); 583 return ether_Abandon(dev, p); 584 } 585 586 /* And finally, request a connection to the given provider */ 587 588 data = (struct ngpppoe_init_data *)alloca(sizeof *data + providerlen); 589 snprintf(data->hook, sizeof data->hook, "%s", dev->hook); 590 memcpy(data->data, provider, providerlen); 591 data->data_len = providerlen; 592 593 snprintf(connectpath, sizeof connectpath, ".:%s", dev->hook); 594 log_Printf(LogDEBUG, "Sending PPPOE_CONNECT to %s\n", connectpath); 595 if (NgSendMsg(dev->cs, connectpath, NGM_PPPOE_COOKIE, 596 NGM_PPPOE_CONNECT, data, sizeof *data + providerlen) == -1) { 597 log_Printf(LogWARN, "``%s'': Cannot start netgraph node: %s\n", 598 connectpath, strerror(errno)); 599 return ether_Abandon(dev, p); 600 } 601 602 /* Hook things up so that we monitor dev->cs */ 603 p->desc.UpdateSet = ether_UpdateSet; 604 p->desc.IsSet = ether_IsSet; 605 p->desc.Read = ether_DescriptorRead; 606 607 memcpy(&dev->dev, &baseetherdevice, sizeof dev->dev); 608 switch (p->cfg.cd.necessity) { 609 case CD_VARIABLE: 610 dev->dev.cd.delay = p->cfg.cd.delay; 611 break; 612 case CD_REQUIRED: 613 dev->dev.cd = p->cfg.cd; 614 break; 615 case CD_NOTREQUIRED: 616 log_Printf(LogWARN, "%s: Carrier must be set, using ``set cd %d!''\n", 617 p->link.name, dev->dev.cd.delay); 618 case CD_DEFAULT: 619 break; 620 } 621 622 dev->timeout = dev->dev.cd.delay; 623 dev->connected = CARRIER_PENDING; 624 625 } else { 626 /* See if we're a netgraph socket */ 627 struct stat st; 628 629 if (fstat(p->fd, &st) != -1 && (st.st_mode & S_IFSOCK)) { 630 struct sockaddr_storage ssock; 631 struct sockaddr *sock = (struct sockaddr *)&ssock; 632 int sz; 633 634 sz = sizeof ssock; 635 if (getsockname(p->fd, sock, &sz) == -1) { 636 log_Printf(LogPHASE, "%s: Link is a closed socket !\n", p->link.name); 637 close(p->fd); 638 p->fd = -1; 639 return NULL; 640 } 641 642 if (sock->sa_family == AF_NETGRAPH) { 643 /* 644 * It's a netgraph node... We can't determine hook names etc, so we 645 * stay pretty impartial.... 646 */ 647 log_Printf(LogPHASE, "%s: Link is a netgraph node\n", p->link.name); 648 649 if ((dev = malloc(sizeof *dev)) == NULL) { 650 log_Printf(LogWARN, "%s: Cannot allocate an ether device: %s\n", 651 p->link.name, strerror(errno)); 652 return NULL; 653 } 654 655 memcpy(&dev->dev, &baseetherdevice, sizeof dev->dev); 656 dev->cs = -1; 657 dev->timeout = 0; 658 dev->connected = CARRIER_OK; 659 *dev->hook = '\0'; 660 } 661 } 662 } 663 664 if (dev) { 665 physical_SetupStack(p, dev->dev.name, PHYSICAL_FORCE_SYNCNOACF); 666 667 /* Moan about (and fix) invalid LCP configurations */ 668 if (p->link.lcp.cfg.mru > 1492) { 669 log_Printf(LogWARN, "%s: Reducing MRU to 1492\n", p->link.name); 670 p->link.lcp.cfg.mru = 1492; 671 } 672 if (p->dl->bundle->cfg.mtu > 1492) { 673 log_Printf(LogWARN, "%s: Reducing MTU to 1492\n", p->link.name); 674 p->dl->bundle->cfg.mtu = 1492; 675 } 676
| 421 char connectpath[sizeof dev->hook + 2]; /* .:<hook> */ 422 423 p->fd--; /* We own the device - change fd */ 424 425#if defined(__FreeBSD__) && !defined(NOKLDLOAD) 426 if (modfind("netgraph") == -1) { 427 log_Printf(LogWARN, "Netgraph is not built into the kernel\n"); 428 return NULL; 429 } 430 431 if (modfind("ng_ether") == -1 && ID0kldload("ng_ether") == -1) 432 /* 433 * Don't treat this as an error as older kernels have this stuff 434 * built in as part of the netgraph node itself. 435 */ 436 log_Printf(LogWARN, "kldload: ng_ether: %s\n", strerror(errno)); 437 438 if (modfind("ng_socket") == -1 && ID0kldload("ng_socket") == -1) { 439 log_Printf(LogWARN, "kldload: ng_socket: %s\n", strerror(errno)); 440 return NULL; 441 } 442#endif 443 444 if ((dev = malloc(sizeof *dev)) == NULL) 445 return NULL; 446 447 iface = p->name.full + PPPOE_NODE_TYPE_LEN + 1; 448 449 provider = strchr(iface, ':'); 450 if (provider) { 451 ifacelen = provider - iface; 452 provider++; 453 providerlen = strlen(provider); 454 } else { 455 ifacelen = strlen(iface); 456 provider = ""; 457 providerlen = 0; 458 } 459 460 /* 461 * We're going to do this (where tunN is our tunnel device): 462 * 463 * .---------. 464 * | ether | 465 * | <iface> | dev->cs 466 * `---------' | 467 * (orphan) p->fd | 468 * | | | 469 * | | | 470 * (ethernet) | | 471 * .---------. .-----------. 472 * | pppoe | | socket | 473 * | <iface> |(tunN)<---->(tunN)| <unnamed> | 474 * `--------- `-----------' 475 * (tunX) 476 * ^ 477 * | 478 * `--->(tunX) 479 */ 480 481 /* Create a socket node */ 482 if (ID0NgMkSockNode(NULL, &dev->cs, &p->fd) == -1) { 483 log_Printf(LogWARN, "Cannot create netgraph socket node: %s\n", 484 strerror(errno)); 485 free(dev); 486 return NULL; 487 } 488 489 /* 490 * Ask for a list of hooks attached to the "ether" node. This node should 491 * magically exist as a way of hooking stuff onto an ethernet device 492 */ 493 path = (char *)alloca(ifacelen + 2); 494 sprintf(path, "%.*s:", ifacelen, iface); 495 if (NgSendMsg(dev->cs, path, NGM_GENERIC_COOKIE, NGM_LISTHOOKS, 496 NULL, 0) < 0) { 497 log_Printf(LogWARN, "%s Cannot send a netgraph message: %s\n", 498 path, strerror(errno)); 499 return ether_Abandon(dev, p); 500 } 501 502 /* Get our list back */ 503 resp = (struct ng_mesg *)rbuf; 504 if (NgRecvMsg(dev->cs, resp, sizeof rbuf, NULL) < 0) { 505 log_Printf(LogWARN, "Cannot get netgraph response: %s\n", 506 strerror(errno)); 507 return ether_Abandon(dev, p); 508 } 509 510 hlist = (const struct hooklist *)resp->data; 511 ninfo = &hlist->nodeinfo; 512 513 /* Make sure we've got the right type of node */ 514 if (strncmp(ninfo->type, NG_ETHER_NODE_TYPE, 515 sizeof NG_ETHER_NODE_TYPE - 1)) { 516 log_Printf(LogWARN, "%s Unexpected node type ``%s'' (wanted ``" 517 NG_ETHER_NODE_TYPE "'')\n", path, ninfo->type); 518 return ether_Abandon(dev, p); 519 } 520 521 log_Printf(LogDEBUG, "List of netgraph node ``%s'' (id %x) hooks:\n", 522 path, ninfo->id); 523 524 /* look for a hook already attached. */ 525 for (f = 0; f < ninfo->hooks; f++) { 526 nlink = &hlist->link[f]; 527 528 log_Printf(LogDEBUG, " Found %s -> %s\n", nlink->ourhook, 529 nlink->peerhook); 530 531 if (!strcmp(nlink->ourhook, NG_ETHER_HOOK_ORPHAN) || 532 !strcmp(nlink->ourhook, NG_ETHER_HOOK_DIVERT)) { 533 /* 534 * Something is using the data coming out of this ``ether'' node. 535 * If it's a PPPoE node, we use that node, otherwise we complain that 536 * someone else is using the node. 537 */ 538 if (!strcmp(nlink->nodeinfo.type, NG_PPPOE_NODE_TYPE)) 539 /* Use this PPPoE node ! */ 540 snprintf(ngc.path, sizeof ngc.path, "[%x]:", nlink->nodeinfo.id); 541 else { 542 log_Printf(LogWARN, "%s Node type ``%s'' is currently active\n", 543 path, nlink->nodeinfo.type); 544 return ether_Abandon(dev, p); 545 } 546 break; 547 } 548 } 549 550 if (f == ninfo->hooks) { 551 /* 552 * Create a new ``PPPoE'' node connected to the ``ether'' node using 553 * the magic ``orphan'' and ``ethernet'' hooks 554 */ 555 snprintf(mkp.type, sizeof mkp.type, "%s", NG_PPPOE_NODE_TYPE); 556 snprintf(mkp.ourhook, sizeof mkp.ourhook, "%s", NG_ETHER_HOOK_ORPHAN); 557 snprintf(mkp.peerhook, sizeof mkp.peerhook, "%s", NG_PPPOE_HOOK_ETHERNET); 558 snprintf(etherid, sizeof etherid, "[%x]:", ninfo->id); 559 560 log_Printf(LogDEBUG, "Creating PPPoE netgraph node %s%s -> %s\n", 561 etherid, mkp.ourhook, mkp.peerhook); 562 563 if (NgSendMsg(dev->cs, etherid, NGM_GENERIC_COOKIE, 564 NGM_MKPEER, &mkp, sizeof mkp) < 0) { 565 log_Printf(LogWARN, "%s Cannot create PPPoE netgraph node: %s\n", 566 etherid, strerror(errno)); 567 return ether_Abandon(dev, p); 568 } 569 570 snprintf(ngc.path, sizeof ngc.path, "%s%s", path, NG_ETHER_HOOK_ORPHAN); 571 } 572 573 snprintf(dev->hook, sizeof dev->hook, "%s%d", 574 TUN_NAME, p->dl->bundle->unit); 575 576 /* 577 * Connect the PPPoE node to our socket node. 578 * ngc.path has already been set up 579 */ 580 snprintf(ngc.ourhook, sizeof ngc.ourhook, "%s", dev->hook); 581 memcpy(ngc.peerhook, ngc.ourhook, sizeof ngc.peerhook); 582 583 log_Printf(LogDEBUG, "Connecting netgraph socket .:%s -> %s:%s\n", 584 ngc.ourhook, ngc.path, ngc.peerhook); 585 if (NgSendMsg(dev->cs, ".:", NGM_GENERIC_COOKIE, 586 NGM_CONNECT, &ngc, sizeof ngc) < 0) { 587 log_Printf(LogWARN, "Cannot connect PPPoE and socket netgraph " 588 "nodes: %s\n", strerror(errno)); 589 return ether_Abandon(dev, p); 590 } 591 592 /* And finally, request a connection to the given provider */ 593 594 data = (struct ngpppoe_init_data *)alloca(sizeof *data + providerlen); 595 snprintf(data->hook, sizeof data->hook, "%s", dev->hook); 596 memcpy(data->data, provider, providerlen); 597 data->data_len = providerlen; 598 599 snprintf(connectpath, sizeof connectpath, ".:%s", dev->hook); 600 log_Printf(LogDEBUG, "Sending PPPOE_CONNECT to %s\n", connectpath); 601 if (NgSendMsg(dev->cs, connectpath, NGM_PPPOE_COOKIE, 602 NGM_PPPOE_CONNECT, data, sizeof *data + providerlen) == -1) { 603 log_Printf(LogWARN, "``%s'': Cannot start netgraph node: %s\n", 604 connectpath, strerror(errno)); 605 return ether_Abandon(dev, p); 606 } 607 608 /* Hook things up so that we monitor dev->cs */ 609 p->desc.UpdateSet = ether_UpdateSet; 610 p->desc.IsSet = ether_IsSet; 611 p->desc.Read = ether_DescriptorRead; 612 613 memcpy(&dev->dev, &baseetherdevice, sizeof dev->dev); 614 switch (p->cfg.cd.necessity) { 615 case CD_VARIABLE: 616 dev->dev.cd.delay = p->cfg.cd.delay; 617 break; 618 case CD_REQUIRED: 619 dev->dev.cd = p->cfg.cd; 620 break; 621 case CD_NOTREQUIRED: 622 log_Printf(LogWARN, "%s: Carrier must be set, using ``set cd %d!''\n", 623 p->link.name, dev->dev.cd.delay); 624 case CD_DEFAULT: 625 break; 626 } 627 628 dev->timeout = dev->dev.cd.delay; 629 dev->connected = CARRIER_PENDING; 630 631 } else { 632 /* See if we're a netgraph socket */ 633 struct stat st; 634 635 if (fstat(p->fd, &st) != -1 && (st.st_mode & S_IFSOCK)) { 636 struct sockaddr_storage ssock; 637 struct sockaddr *sock = (struct sockaddr *)&ssock; 638 int sz; 639 640 sz = sizeof ssock; 641 if (getsockname(p->fd, sock, &sz) == -1) { 642 log_Printf(LogPHASE, "%s: Link is a closed socket !\n", p->link.name); 643 close(p->fd); 644 p->fd = -1; 645 return NULL; 646 } 647 648 if (sock->sa_family == AF_NETGRAPH) { 649 /* 650 * It's a netgraph node... We can't determine hook names etc, so we 651 * stay pretty impartial.... 652 */ 653 log_Printf(LogPHASE, "%s: Link is a netgraph node\n", p->link.name); 654 655 if ((dev = malloc(sizeof *dev)) == NULL) { 656 log_Printf(LogWARN, "%s: Cannot allocate an ether device: %s\n", 657 p->link.name, strerror(errno)); 658 return NULL; 659 } 660 661 memcpy(&dev->dev, &baseetherdevice, sizeof dev->dev); 662 dev->cs = -1; 663 dev->timeout = 0; 664 dev->connected = CARRIER_OK; 665 *dev->hook = '\0'; 666 } 667 } 668 } 669 670 if (dev) { 671 physical_SetupStack(p, dev->dev.name, PHYSICAL_FORCE_SYNCNOACF); 672 673 /* Moan about (and fix) invalid LCP configurations */ 674 if (p->link.lcp.cfg.mru > 1492) { 675 log_Printf(LogWARN, "%s: Reducing MRU to 1492\n", p->link.name); 676 p->link.lcp.cfg.mru = 1492; 677 } 678 if (p->dl->bundle->cfg.mtu > 1492) { 679 log_Printf(LogWARN, "%s: Reducing MTU to 1492\n", p->link.name); 680 p->dl->bundle->cfg.mtu = 1492; 681 } 682
|
| 683 if (path != NULL) { 684 /* Mark the interface as UP if it's not already */ 685 686 path[ifacelen] = '\0'; /* Remove the trailing ':' */ 687 if (!iface_SetFlags(path, IFF_UP)) 688 log_Printf(LogWARN, "%s: Failed to set the IFF_UP flag on %s\n", 689 p->link.name, path); 690 } 691
|
677 return &dev->dev; 678 } 679 680 return NULL; 681}
| 692 return &dev->dev; 693 } 694 695 return NULL; 696}
|