1 diff -Naur ppp-2.4.4.orig/pppd/plugins/rp-pppoe/common.c ppp-2.4.4/pppd/plugins/rp-pppoe/common.c
2 --- ppp-2.4.4.orig/pppd/plugins/rp-pppoe/common.c 2004-02-01 22:36:46.000000000 -0500
3 +++ ppp-2.4.4/pppd/plugins/rp-pppoe/common.c 2009-05-07 17:01:46.000000000 -0400
16 UINT16_t tagType, tagLen;
18 if (packet->ver != 1) {
19 - syslog(LOG_ERR, "Invalid PPPoE version (%d)", (int) packet->ver);
20 + error("Invalid PPPoE version (%u)", packet->ver);
23 if (packet->type != 1) {
24 - syslog(LOG_ERR, "Invalid PPPoE type (%d)", (int) packet->type);
25 + error("Invalid PPPoE type (%u)", packet->type);
29 /* Do some sanity checks on packet */
30 if (len > ETH_DATA_LEN - 6) { /* 6-byte overhead for PPPoE header */
31 - syslog(LOG_ERR, "Invalid PPPoE packet length (%u)", len);
32 + error("Invalid PPPoE packet length (%u)", len);
39 if ((curTag - packet->payload) + tagLen + TAG_HDR_SIZE > len) {
40 - syslog(LOG_ERR, "Invalid PPPoE tag length (%u)", tagLen);
41 + error("Invalid PPPoE tag length (%u)", tagLen);
44 func(tagType, tagLen, curTag+TAG_HDR_SIZE, extra);
46 UINT16_t tagType, tagLen;
48 if (packet->ver != 1) {
49 - syslog(LOG_ERR, "Invalid PPPoE version (%d)", (int) packet->ver);
50 + error("Invalid PPPoE version (%u)", packet->ver);
53 if (packet->type != 1) {
54 - syslog(LOG_ERR, "Invalid PPPoE type (%d)", (int) packet->type);
55 + error("Invalid PPPoE type (%u)", packet->type);
59 /* Do some sanity checks on packet */
60 if (len > ETH_DATA_LEN - 6) { /* 6-byte overhead for PPPoE header */
61 - syslog(LOG_ERR, "Invalid PPPoE packet length (%u)", len);
62 + error("Invalid PPPoE packet length (%u)", len);
69 if ((curTag - packet->payload) + tagLen + TAG_HDR_SIZE > len) {
70 - syslog(LOG_ERR, "Invalid PPPoE tag length (%u)", tagLen);
71 + error("Invalid PPPoE tag length (%u)", tagLen);
74 if (tagType == type) {
80 /**********************************************************************
84 fprintf(stderr, "pppoe: %s\n", str);
85 syslog(LOG_ERR, "%s", str);
90 /**********************************************************************
93 char *copy = malloc(strlen(str)+1);
95 - rp_fatal("strdup failed");
96 + fatal("strdup failed");
101 fprintf(conn->debugFile, "\n");
102 fflush(conn->debugFile);
104 - syslog(LOG_INFO,"Sent PADT");
109 /**********************************************************************
110 *%FUNCTION: parseLogErrs
118 diff -Naur ppp-2.4.4.orig/pppd/plugins/rp-pppoe/discovery.c ppp-2.4.4/pppd/plugins/rp-pppoe/discovery.c
119 --- ppp-2.4.4.orig/pppd/plugins/rp-pppoe/discovery.c 2005-03-22 05:22:32.000000000 -0500
120 +++ ppp-2.4.4/pppd/plugins/rp-pppoe/discovery.c 2009-05-07 17:01:46.000000000 -0400
125 -#ifdef HAVE_SYSLOG_H
132 @@ -167,24 +163,21 @@
133 if (conn->printACNames) {
134 printf("Got a Service-Name-Error tag: %.*s\n", (int) len, data);
136 - syslog(LOG_ERR, "PADO: Service-Name-Error: %.*s", (int) len, data);
138 + fatal("PADO: Service-Name-Error: %.*s", (int) len, data);
141 case TAG_AC_SYSTEM_ERROR:
142 if (conn->printACNames) {
143 printf("Got a System-Error tag: %.*s\n", (int) len, data);
145 - syslog(LOG_ERR, "PADO: System-Error: %.*s", (int) len, data);
147 + fatal("PADO: System-Error: %.*s", (int) len, data);
150 case TAG_GENERIC_ERROR:
151 if (conn->printACNames) {
152 printf("Got a Generic-Error tag: %.*s\n", (int) len, data);
154 - syslog(LOG_ERR, "PADO: Generic-Error: %.*s", (int) len, data);
156 + fatal("PADO: Generic-Error: %.*s", (int) len, data);
160 @@ -209,20 +202,14 @@
161 PPPoEConnection *conn = (PPPoEConnection *) extra;
163 case TAG_SERVICE_NAME:
164 - syslog(LOG_DEBUG, "PADS: Service-Name: '%.*s'", (int) len, data);
165 + dbglog("PADS: Service-Name: '%.*s'", (int) len, data);
167 case TAG_SERVICE_NAME_ERROR:
168 - syslog(LOG_ERR, "PADS: Service-Name-Error: %.*s", (int) len, data);
169 - fprintf(stderr, "PADS: Service-Name-Error: %.*s\n", (int) len, data);
171 + fatal("PADS: Service-Name-Error: %.*s", (int) len, data);
172 case TAG_AC_SYSTEM_ERROR:
173 - syslog(LOG_ERR, "PADS: System-Error: %.*s", (int) len, data);
174 - fprintf(stderr, "PADS: System-Error: %.*s\n", (int) len, data);
176 + fatal("PADS: System-Error: %.*s", (int) len, data);
177 case TAG_GENERIC_ERROR:
178 - syslog(LOG_ERR, "PADS: Generic-Error: %.*s", (int) len, data);
179 - fprintf(stderr, "PADS: Generic-Error: %.*s\n", (int) len, data);
181 + fatal("PADS: Generic-Error: %.*s", (int) len, data);
182 case TAG_RELAY_SESSION_ID:
183 conn->relayId.type = htons(type);
184 conn->relayId.length = htons(len);
186 if (r >= 0 || errno != EINTR) break;
189 - fatalSys("select (waitForPADO)");
190 + fatal("waitForPADO: select: %m");
192 if (r == 0) return; /* Timed out */
197 if (ntohs(packet.length) + HDR_SIZE > len) {
198 - syslog(LOG_ERR, "Bogus PPPoE length field (%u)",
199 - (unsigned int) ntohs(packet.length));
200 + error("Bogus PPPoE length field (%u)", ntohs(packet.length));
204 @@ -366,16 +352,16 @@
206 if (packet.code == CODE_PADO) {
207 if (BROADCAST(packet.ethHdr.h_source)) {
208 - printErr("Ignoring PADO packet from broadcast MAC address");
209 + error("Ignoring PADO packet from broadcast MAC address");
212 parsePacket(&packet, parsePADOTags, &pc);
213 if (!pc.seenACName) {
214 - printErr("Ignoring PADO packet with no AC-Name tag");
215 + error("Ignoring PADO packet with no AC-Name tag");
218 if (!pc.seenServiceName) {
219 - printErr("Ignoring PADO packet with no Service-Name tag");
220 + error("Ignoring PADO packet with no Service-Name tag");
225 if (r >= 0 || errno != EINTR) break;
228 - fatalSys("select (waitForPADS)");
229 + fatal("waitForPADS: select: %m");
236 if (ntohs(packet.length) + HDR_SIZE > len) {
237 - syslog(LOG_ERR, "Bogus PPPoE length field (%u)",
238 - (unsigned int) ntohs(packet.length));
239 + error("Bogus PPPoE length field (%u)", ntohs(packet.length));
243 @@ -556,11 +541,12 @@
244 /* Don't bother with ntohs; we'll just end up converting it back... */
245 conn->session = packet.session;
247 - syslog(LOG_INFO, "PPP session is %d", (int) ntohs(conn->session));
248 + info("PPP session is %d", ntohs(conn->session));
250 /* RFC 2516 says session id MUST NOT be zero or 0xFFFF */
251 if (ntohs(conn->session) == 0 || ntohs(conn->session) == 0xFFFF) {
252 - syslog(LOG_ERR, "Access concentrator used a session value of %x -- the AC is violating RFC 2516", (unsigned int) ntohs(conn->session));
253 + error("Access concentrator used a session value of 0x%x"
254 + " -- the AC is violating RFC 2516", ntohs(conn->session));
260 /* If we're only printing access concentrator names, we're done */
261 if (conn->printACNames) {
266 timeout = PADI_TIMEOUT;
267 diff -Naur ppp-2.4.4.orig/pppd/plugins/rp-pppoe/if.c ppp-2.4.4/pppd/plugins/rp-pppoe/if.c
268 --- ppp-2.4.4.orig/pppd/plugins/rp-pppoe/if.c 2001-12-13 21:55:20.000000000 -0500
269 +++ ppp-2.4.4/pppd/plugins/rp-pppoe/if.c 2009-05-07 17:01:46.000000000 -0400
271 #include <sys/ioctl.h>
274 -#ifdef HAVE_SYSLOG_H
283 UINT16_t type = (UINT16_t) ntohs(packet->ethHdr.h_proto);
284 if (type != Eth_PPPOE_Discovery && type != Eth_PPPOE_Session) {
285 - syslog(LOG_ERR, "Invalid ether type 0x%x", type);
286 + error("Invalid ethernet type 0x%x", type);
291 ifc.ifc_len = sizeof(inbuf);
293 if (ioctl(sock, SIOCGIFCONF, &ifc) < 0) {
294 - fatalSys("SIOCGIFCONF");
295 + fatal("SIOCGIFCONF: %m");
298 ifreq.ifr_name[0] = '\0';
300 (sdl->sdl_alen == ETH_ALEN) &&
301 !strncmp(ifname, ifr->ifr_name, sizeof(ifr->ifr_name))) {
304 - sprintf(buffer, "interface %.16s has more than one ethernet address", ifname);
306 + fatal("interface %s has more than one ethernet address", ifname);
309 memcpy(hwaddr, LLADDR(sdl), ETH_ALEN);
315 - sprintf(buffer, "interface %.16s has no ethernet address", ifname);
317 + fatal("interface %s has no ethernet address", ifname);
323 /* Apply the filter */
324 if (ioctl(fd, BIOCSETF, &bpfProgram) < 0) {
325 - fatalSys("ioctl(BIOCSETF)");
326 + fatal("ioctl(BIOCSETF): %m");
330 @@ -298,42 +290,36 @@
333 case EACCES: /* permission denied */
336 - sprintf(buffer, "Cannot open %.32s -- pppoe must be run as root.", bpfName);
339 + fatal("Cannot open %s -- pppoe must be run as root.", bpfName);
342 case ENOENT: /* no such file */
344 - rp_fatal("No /dev/bpf* devices (check your kernel configuration for BPF support)");
345 + fatal("No /dev/bpf* devices (check your kernel configuration for BPF support)");
347 - rp_fatal("All /dev/bpf* devices are in use");
348 + fatal("All /dev/bpf* devices are in use");
353 + fatal("%s: %m", bpfName);
356 if ((sock = socket(AF_LOCAL, SOCK_DGRAM, 0)) < 0) {
357 - fatalSys("socket");
358 + fatal("socket: %m");
361 /* Check that the interface is up */
362 strncpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
363 if (ioctl(sock, SIOCGIFFLAGS, &ifr) < 0) {
364 - fatalSys("ioctl(SIOCGIFFLAGS)");
365 + fatal("ioctl(SIOCGIFFLAGS): %m");
367 if ((ifr.ifr_flags & IFF_UP) == 0) {
369 - sprintf(buffer, "Interface %.16s is not up\n", ifname);
371 + fatal("Interface %s is not up", ifname);
374 /* Fill in hardware address and initialize the packet filter rules */
375 if (hwaddr == NULL) {
376 - rp_fatal("openInterface: no hwaddr arg.");
377 + fatal("openInterface: no hwaddr arg.");
379 getHWaddr(sock, ifname, hwaddr);
380 initFilter(fd, type, hwaddr);
381 @@ -342,58 +328,52 @@
382 #if !defined(__OpenBSD__)
383 strncpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
384 if (ioctl(sock, SIOCGIFMTU, &ifr) < 0) {
385 - fatalSys("ioctl(SIOCGIFMTU)");
386 + fatal("ioctl(SIOCGIFMTU): %m");
388 if (ifr.ifr_mtu < ETH_DATA_LEN) {
390 - sprintf(buffer, "Interface %.16s has MTU of %d -- should be %d. You may have serious connection problems.",
391 + error("Interface %s has MTU of %d -- should be %d."
392 + " You may have serious connection problems.",
393 ifname, ifr.ifr_mtu, ETH_DATA_LEN);
398 /* done with the socket */
399 if (close(sock) < 0) {
401 + fatal("close: %m");
404 /* Check the BPF version number */
405 if (ioctl(fd, BIOCVERSION, &bpf_ver) < 0) {
406 - fatalSys("ioctl(BIOCVERSION)");
407 + fatal("ioctl(BIOCVERSION): %m");
409 if ((bpf_ver.bv_major != BPF_MAJOR_VERSION) ||
410 (bpf_ver.bv_minor < BPF_MINOR_VERSION)) {
412 - sprintf(buffer, "Unsupported BPF version: %d.%d (kernel: %d.%d)",
413 + fatal("Unsupported BPF version: %d.%d (kernel: %d.%d)",
414 BPF_MAJOR_VERSION, BPF_MINOR_VERSION,
415 bpf_ver.bv_major, bpf_ver.bv_minor);
419 /* allocate a receive packet buffer */
420 if (ioctl(fd, BIOCGBLEN, &bpfLength) < 0) {
421 - fatalSys("ioctl(BIOCGBLEN)");
422 + fatal("ioctl(BIOCGBLEN): %m");
424 if (!(bpfBuffer = (unsigned char *) malloc(bpfLength))) {
425 - rp_fatal("malloc");
429 /* reads should return as soon as there is a packet available */
431 if (ioctl(fd, BIOCIMMEDIATE, &optval) < 0) {
432 - fatalSys("ioctl(BIOCIMMEDIATE)");
433 + fatal("ioctl(BIOCIMMEDIATE): %m");
436 /* Bind the interface to the filter */
437 strncpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
438 if (ioctl(fd, BIOCSETIF, &ifr) < 0) {
440 - sprintf(buffer, "ioctl(BIOCSETIF) can't select interface %.16s",
443 + fatal("ioctl(BIOCSETIF) can't select interface %s: %m", ifname);
446 - syslog(LOG_INFO, "Interface=%.16s HWaddr=%02X:%02X:%02X:%02X:%02X:%02X Device=%.32s Buffer size=%d",
447 + info("Interface=%s HWaddr=%02X:%02X:%02X:%02X:%02X:%02X Device=%s Buffer size=%d",
449 hwaddr[0], hwaddr[1], hwaddr[2],
450 hwaddr[3], hwaddr[4], hwaddr[5],
451 @@ -442,48 +422,41 @@
452 if ((fd = socket(domain, stype, htons(type))) < 0) {
453 /* Give a more helpful message for the common error case */
454 if (errno == EPERM) {
455 - rp_fatal("Cannot create raw socket -- pppoe must be run as root.");
456 + fatal("Cannot create raw socket -- pppoe must be run as root.");
458 - fatalSys("socket");
459 + fatal("cannot create the raw socket: %m");
462 if (setsockopt(fd, SOL_SOCKET, SO_BROADCAST, &optval, sizeof(optval)) < 0) {
463 - fatalSys("setsockopt");
464 + fatal("setsockopt(SOL_SOCKET, SO_BROADCAST): %m");
467 /* Fill in hardware address */
469 strncpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
470 - if (ioctl(fd, SIOCGIFHWADDR, &ifr) < 0) {
471 - fatalSys("ioctl(SIOCGIFHWADDR)");
473 + if (ioctl(fd, SIOCGIFHWADDR, &ifr) < 0)
474 + fatal("ioctl(SIOCGIFHWADDR): %m");
475 memcpy(hwaddr, ifr.ifr_hwaddr.sa_data, ETH_ALEN);
477 if (ifr.ifr_hwaddr.sa_family != ARPHRD_ETHER) {
479 - sprintf(buffer, "Interface %.16s is not Ethernet", ifname);
481 + fatal("Interface %s is not Ethernet", ifname);
484 if (NOT_UNICAST(hwaddr)) {
487 - "Interface %.16s has broadcast/multicast MAC address??",
488 + fatal("Interface %s has broadcast/multicast MAC address",
494 /* Sanity check on MTU */
495 strncpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
496 if (ioctl(fd, SIOCGIFMTU, &ifr) < 0) {
497 - fatalSys("ioctl(SIOCGIFMTU)");
498 + fatal("ioctl(SIOCGIFMTU): %m");
500 if (ifr.ifr_mtu < ETH_DATA_LEN) {
502 - sprintf(buffer, "Interface %.16s has MTU of %d -- should be %d. You may have serious connection problems.",
503 + error("Interface %s has MTU of %d -- should be %d."
504 + " You may have serious connection problems.",
505 ifname, ifr.ifr_mtu, ETH_DATA_LEN);
509 #ifdef HAVE_STRUCT_SOCKADDR_LL
512 strncpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
513 if (ioctl(fd, SIOCGIFINDEX, &ifr) < 0) {
514 - fatalSys("ioctl(SIOCFIGINDEX): Could not get interface index");
515 + fatal("ioctl(SIOCFIGINDEX): Could not get interface index: %m");
517 sa.sll_ifindex = ifr.ifr_ifindex;
521 /* We're only interested in packets on specified interface */
522 if (bind(fd, (struct sockaddr *) &sa, sizeof(sa)) < 0) {
528 @@ -527,13 +500,11 @@
531 if (write(sock, pkt, size) < 0) {
532 - sysErr("write (sendPacket)");
534 + fatal("sendPacket: write: %m");
536 #elif defined(HAVE_STRUCT_SOCKADDR_LL)
537 if (send(sock, pkt, size, 0) < 0) {
538 - sysErr("send (sendPacket)");
540 + fatal("sendPacket: send: %m");
544 @@ -577,12 +548,11 @@
548 - rp_fatal("relay and server not supported on Linux 2.0 kernels");
549 + fatal("relay and server not supported on Linux 2.0 kernels");
551 strcpy(sa.sa_data, conn->ifName);
552 if (sendto(sock, pkt, size, 0, &sa, sizeof(sa)) < 0) {
553 - sysErr("sendto (sendPacket)");
555 + fatal("sendPacket: sendto: %m");
559 @@ -632,26 +602,24 @@
562 if ((bpfSize = read(sock, bpfBuffer, bpfLength)) < 0) {
563 - sysErr("read (receivePacket)");
565 + fatal("receivePacket: read: %m");
568 if (bpfSize < sizeof(hdr)) {
569 - syslog(LOG_ERR, "Truncated bpf packet header: len=%d", bpfSize);
570 + error("Truncated bpf packet header: len=%d", bpfSize);
571 clearPacketHeader(pkt); /* resets bpfSize and bpfOffset */
574 memcpy(&hdr, bpfBuffer + bpfOffset, sizeof(hdr));
575 if (hdr.bh_caplen != hdr.bh_datalen) {
576 - syslog(LOG_ERR, "Truncated bpf packet: caplen=%d, datalen=%d",
577 + error("Truncated bpf packet: caplen=%d, datalen=%d",
578 hdr.bh_caplen, hdr.bh_datalen);
579 clearPacketHeader(pkt); /* resets bpfSize and bpfOffset */
582 seglen = hdr.bh_hdrlen + hdr.bh_caplen;
583 if (seglen > bpfSize) {
584 - syslog(LOG_ERR, "Truncated bpf packet: seglen=%d, bpfSize=%d",
586 + error("Truncated bpf packet: seglen=%d, bpfSize=%d", seglen, bpfSize);
587 clearPacketHeader(pkt); /* resets bpfSize and bpfOffset */
590 @@ -676,16 +644,14 @@
593 if ((retval = getmsg(sock, NULL, &data, &flags)) < 0) {
594 - sysErr("read (receivePacket)");
596 + fatal("receivePacket: getmsg: %m");
602 if ((*size = recv(sock, pkt, sizeof(PPPoEPacket), 0)) < 0) {
603 - sysErr("recv (receivePacket)");
605 + fatal("receivePacket: recv: %m");
612 if(strlen(ifname) > PATH_MAX) {
613 - rp_fatal("socket: string to long");
614 + fatal("openInterface: interface name too long");
617 ppa = atoi(&ifname[strlen(ifname)-1]);
619 if (( fd = open(base_dev, O_RDWR)) < 0) {
620 /* Give a more helpful message for the common error case */
621 if (errno == EPERM) {
622 - rp_fatal("Cannot create raw socket -- pppoe must be run as root.");
623 + fatal("Cannot create raw socket -- pppoe must be run as root.");
625 - fatalSys("socket");
626 + fatal("open(%s): %m", base_dev);
629 /* rearranged order of DLPI code - delphys 20010803 */
630 @@ -747,17 +713,18 @@
631 dl_abssaplen = ABS(dlp->info_ack.dl_sap_length);
632 dl_saplen = dlp->info_ack.dl_sap_length;
633 if (ETHERADDRL != (dlp->info_ack.dl_addr_length - dl_abssaplen))
634 - fatalSys("invalid destination physical address length");
635 + fatal("invalid destination physical address length");
636 dl_addrlen = dl_abssaplen + ETHERADDRL;
638 /* ethernet address retrieved as part of DL_INFO_ACK - delphys 20010803 */
639 memcpy(hwaddr, (u_char*)((char*)(dlp) + (int)(dlp->info_ack.dl_addr_offset)), ETHERADDRL);
641 if ( strioctl(fd, DLIOCRAW, -1, 0, NULL) < 0 ) {
642 - fatalSys("DLIOCRAW");
643 + fatal("DLIOCRAW: %m");
646 - if (ioctl(fd, I_FLUSH, FLUSHR) < 0) fatalSys("I_FLUSH");
647 + if (ioctl(fd, I_FLUSH, FLUSHR) < 0)
648 + fatal("I_FLUSH: %m");
655 if (putmsg(fd, &ctl, (struct strbuf*) NULL, flags) < 0)
656 - fatalSys("dlpromiscon: putmsg");
657 + fatal("dlpromiscon: putmsg: %m");
664 if (putmsg(fd, &ctl, (struct strbuf*) NULL, flags) < 0)
665 - fatalSys("dlinforeq: putmsg");
666 + fatal("dlinforeq: putmsg: %m");
669 void dlunitdatareq(int fd, u_char *addrp, int addrlen, u_long minpri, u_long maxpri, u_char *datap, int datalen)
671 data.buf = (char *) datap;
673 if (putmsg(fd, &ctl, &data, 0) < 0)
674 - fatalSys("dlunitdatareq: putmsg");
675 + fatal("dlunitdatareq: putmsg: %m");
678 void dlinfoack(int fd, char *bufp)
679 @@ -847,18 +814,14 @@
680 expecting(DL_INFO_ACK, dlp);
682 if (ctl.len < sizeof (dl_info_ack_t)) {
684 - sprintf(buffer, "dlinfoack: response ctl.len too short: %d", ctl.len);
686 + fatal("dlinfoack: response ctl.len too short: %d", ctl.len);
689 if (flags != RS_HIPRI)
690 - rp_fatal("dlinfoack: DL_INFO_ACK was not M_PCPROTO");
691 + fatal("dlinfoack: DL_INFO_ACK was not M_PCPROTO");
693 if (ctl.len < sizeof (dl_info_ack_t)) {
695 - sprintf(buffer, "dlinfoack: short response ctl.len: %d", ctl.len);
697 + fatal("dlinfoack: short response ctl.len: %d", ctl.len);
704 if (putmsg(fd, &ctl, (struct strbuf*) NULL, flags) < 0)
705 - fatalSys("dlbindreq: putmsg");
706 + fatal("dlbindreq: putmsg: %m");
709 void dlattachreq(int fd, u_long ppa)
713 if (putmsg(fd, &ctl, (struct strbuf*) NULL, flags) < 0)
714 - fatalSys("dlattachreq: putmsg");
715 + fatal("dlattachreq: putmsg: %m");
718 void dlokack(int fd, char *bufp)
719 @@ -921,18 +884,14 @@
720 expecting(DL_OK_ACK, dlp);
722 if (ctl.len < sizeof (dl_ok_ack_t)) {
724 - sprintf(buffer, "dlokack: response ctl.len too short: %d", ctl.len);
726 + fatal("dlokack: response ctl.len too short: %d", ctl.len);
729 if (flags != RS_HIPRI)
730 - rp_fatal("dlokack: DL_OK_ACK was not M_PCPROTO");
731 + fatal("dlokack: DL_OK_ACK was not M_PCPROTO");
733 if (ctl.len < sizeof (dl_ok_ack_t)) {
735 - sprintf(buffer, "dlokack: short response ctl.len: %d", ctl.len);
737 + fatal("dlokack: short response ctl.len: %d", ctl.len);
741 @@ -953,12 +912,10 @@
742 expecting(DL_BIND_ACK, dlp);
744 if (flags != RS_HIPRI)
745 - rp_fatal("dlbindack: DL_OK_ACK was not M_PCPROTO");
746 + fatal("dlbindack: DL_OK_ACK was not M_PCPROTO");
748 if (ctl.len < sizeof (dl_bind_ack_t)) {
750 - sprintf(buffer, "dlbindack: short response ctl.len: %d", ctl.len);
752 + fatal("dlbindack: short response ctl.len: %d", ctl.len);
758 (void) signal(SIGALRM, sigalrm);
759 if (alarm(MAXWAIT) < 0) {
760 - (void) sprintf(errmsg, "%s: alarm", caller);
762 + fatal("%s: alarm", caller);
766 @@ -998,61 +954,48 @@
769 if ((rc = getmsg(fd, ctlp, datap, flagsp)) < 0) {
770 - (void) sprintf(errmsg, "%s: getmsg", caller);
772 + fatal(errmsg, "%s: getmsg: %m", caller);
779 - (void) sprintf(errmsg, "%s: alarm", caller);
781 + fatal("%s: alarm", caller);
785 * Check for MOREDATA and/or MORECTL.
787 if ((rc & (MORECTL | MOREDATA)) == (MORECTL | MOREDATA)) {
789 - sprintf(buffer, "%s: MORECTL|MOREDATA", caller);
791 + fatal("%s: MORECTL|MOREDATA", caller);
796 - sprintf(buffer, "%s: MORECTL", caller);
798 + fatal("%s: MORECTL", caller);
803 - sprintf(buffer, "%s: MOREDATA", caller);
805 + fatal("%s: MOREDATA", caller);
809 * Check for at least sizeof (long) control data portion.
811 if (ctlp->len < sizeof (long)) {
813 - sprintf(buffer, "getmsg: control portion length < sizeof (long): %d", ctlp->len);
815 + fatal("getmsg: control portion length < sizeof (long): %d", ctlp->len);
819 void sigalrm(int sig)
821 - (void) rp_fatal("sigalrm: TIMEOUT");
822 + fatal("sigalrm: TIMEOUT");
825 void expecting(int prim, union DL_primitives *dlp)
827 if (dlp->dl_primitive != (u_long)prim) {
829 - sprintf(buffer, "expected %s got %s", dlprim(prim), dlprim(dlp->dl_primitive));
832 + fatal("expected %s got %s", dlprim(prim), dlprim(dlp->dl_primitive));
836 diff -Naur ppp-2.4.4.orig/pppd/plugins/rp-pppoe/Makefile.linux ppp-2.4.4/pppd/plugins/rp-pppoe/Makefile.linux
837 --- ppp-2.4.4.orig/pppd/plugins/rp-pppoe/Makefile.linux 2006-06-04 01:07:46.000000000 -0400
838 +++ ppp-2.4.4/pppd/plugins/rp-pppoe/Makefile.linux 2009-05-07 17:01:46.000000000 -0400
840 CFLAGS=$(COPTS) -I../../../include/linux
841 all: rp-pppoe.so pppoe-discovery
843 -pppoe-discovery: libplugin.a pppoe-discovery.o
844 - $(CC) -o pppoe-discovery pppoe-discovery.o libplugin.a
845 +pppoe-discovery: pppoe-discovery.o utils.o libplugin.a
846 + $(CC) -o pppoe-discovery pppoe-discovery.o utils.o libplugin.a
848 pppoe-discovery.o: pppoe-discovery.c
849 $(CC) $(CFLAGS) '-DVERSION="$(VERSION)"' -c -o pppoe-discovery.o pppoe-discovery.c
850 diff -Naur ppp-2.4.4.orig/pppd/plugins/rp-pppoe/plugin.c ppp-2.4.4/pppd/plugins/rp-pppoe/plugin.c
851 --- ppp-2.4.4.orig/pppd/plugins/rp-pppoe/plugin.c 2006-05-29 19:29:16.000000000 -0400
852 +++ ppp-2.4.4/pppd/plugins/rp-pppoe/plugin.c 2009-05-07 17:01:46.000000000 -0400
854 #include "pppd/pathnames.h"
856 #include <linux/types.h>
858 #include <sys/ioctl.h>
859 #include <sys/types.h>
860 #include <sys/socket.h>
862 (unsigned) conn->peerEth[5]);
864 if (connect(conn->sessionSocket, (struct sockaddr *) &sp,
865 - sizeof(struct sockaddr_pppox)) < 0) {
866 + sizeof(struct sockaddr_pppox)) < 0)
867 fatal("Failed to connect PPPoE socket: %d %m", errno);
871 return conn->sessionSocket;
876 add_options(Options);
878 - info("RP-PPPoE plugin version %s compiled against pppd %s",
879 - RP_VERSION, VERSION);
883 /**********************************************************************
892 void pppoe_check_options(void)
894 diff -Naur ppp-2.4.4.orig/pppd/plugins/rp-pppoe/pppoe-discovery.c ppp-2.4.4/pppd/plugins/rp-pppoe/pppoe-discovery.c
895 --- ppp-2.4.4.orig/pppd/plugins/rp-pppoe/pppoe-discovery.c 2004-11-13 07:12:05.000000000 -0500
896 +++ ppp-2.4.4/pppd/plugins/rp-pppoe/pppoe-discovery.c 2009-05-07 17:01:46.000000000 -0400
901 -char *xstrdup(const char *s);
904 -void die(int status)
909 int main(int argc, char *argv[])
914 conn = malloc(sizeof(PPPoEConnection));
916 - fatalSys("malloc");
919 memset(conn, 0, sizeof(PPPoEConnection));
921 while ((opt = getopt(argc, argv, "I:D:VUAS:C:h")) > 0) {
924 - conn->serviceName = xstrdup(optarg);
925 + conn->serviceName = strDup(optarg);
928 - conn->acName = xstrdup(optarg);
929 + conn->acName = strDup(optarg);
932 conn->useHostUniq = 1;
934 fprintf(conn->debugFile, "pppoe-discovery %s\n", VERSION);
937 - conn->ifName = xstrdup(optarg);
938 + conn->ifName = strDup(optarg);
941 /* this is the default */
944 /* default interface name */
946 - conn->ifName = strdup("eth0");
947 + conn->ifName = strDup("eth0");
949 conn->discoverySocket = -1;
950 conn->sessionSocket = -1;
955 -void rp_fatal(char const *str)
960 - sprintf(buf, "pppoe-discovery: %.256s", str);
964 -void fatalSys(char const *str)
969 - sprintf(buf, "%.256s: %.256s", str, strerror(i));
971 - sprintf(buf, "pppoe-discovery: %.256s: %.256s", str, strerror(i));
975 -void sysErr(char const *str)
980 -char *xstrdup(const char *s)
982 - register char *ret = strdup(s);
990 fprintf(stderr, "Usage: pppoe-discovery [options]\n");
991 diff -Naur ppp-2.4.4.orig/pppd/plugins/rp-pppoe/pppoe.h ppp-2.4.4/pppd/plugins/rp-pppoe/pppoe.h
992 --- ppp-2.4.4.orig/pppd/plugins/rp-pppoe/pppoe.h 2004-11-04 05:07:37.000000000 -0500
993 +++ ppp-2.4.4/pppd/plugins/rp-pppoe/pppoe.h 2009-05-07 17:01:46.000000000 -0400
994 @@ -307,12 +307,18 @@
995 unsigned char *findTag(PPPoEPacket *packet, UINT16_t tagType,
998 +void dbglog(char *, ...); /* log a debug message */
999 +void info(char *, ...); /* log an informational message */
1000 +void warn(char *, ...); /* log a warning message */
1001 +void error(char *, ...); /* log an error message */
1002 +void fatal(char *, ...); /* log an error message and die(1) */
1004 #define SET_STRING(var, val) do { if (var) free(var); var = strDup(val); } while(0);
1006 #define CHECK_ROOM(cursor, start, len) \
1008 if (((cursor)-(start))+(len) > MAX_PPPOE_PAYLOAD) { \
1009 - syslog(LOG_ERR, "Would create too-long packet"); \
1010 + error("Would create too-long packet"); \
1014 diff -Naur ppp-2.4.4.orig/pppd/plugins/rp-pppoe/utils.c ppp-2.4.4/pppd/plugins/rp-pppoe/utils.c
1015 --- ppp-2.4.4.orig/pppd/plugins/rp-pppoe/utils.c 1969-12-31 19:00:00.000000000 -0500
1016 +++ ppp-2.4.4/pppd/plugins/rp-pppoe/utils.c 2009-05-07 17:01:46.000000000 -0400
1019 +#include <stdlib.h>
1020 +#include <unistd.h>
1021 +#include <stdarg.h>
1022 +#include <syslog.h>
1024 +void dbglog(const char *fmt, ...)
1028 + va_start(ap, fmt);
1029 + vsyslog(LOG_DEBUG, fmt, ap);
1030 + vfprintf(stderr, fmt, ap);
1031 + fputs("\n", stderr);
1035 +void info(const char *fmt, ...)
1039 + va_start(ap, fmt);
1040 + vsyslog(LOG_INFO, fmt, ap);
1041 + vfprintf(stderr, fmt, ap);
1042 + fputs("\n", stderr);
1046 +void warn(const char *fmt, ...)
1050 + va_start(ap, fmt);
1051 + vsyslog(LOG_WARNING, fmt, ap);
1052 + vfprintf(stderr, fmt, ap);
1053 + fputs("\n", stderr);
1057 +void error(const char *fmt, ...)
1061 + va_start(ap, fmt);
1062 + vsyslog(LOG_ERR, fmt, ap);
1063 + vfprintf(stderr, fmt, ap);
1064 + fputs("\n", stderr);
1068 +void fatal(const char *fmt, ...)
1072 + va_start(ap, fmt);
1073 + vsyslog(LOG_ERR, fmt, ap);
1074 + vfprintf(stderr, fmt, ap);
1075 + fputs("\n", stderr);
1080 diff -Naur ppp-2.4.4.orig/pppd/plugins/rp-pppoe/common.c ppp-2.4.4/pppd/plugins/rp-pppoe/common.c
1081 --- ppp-2.4.4.orig/pppd/plugins/rp-pppoe/common.c 2004-02-01 22:36:46.000000000 -0500
1082 +++ ppp-2.4.4/pppd/plugins/rp-pppoe/common.c 2009-05-07 17:01:46.000000000 -0400
1087 -#ifdef HAVE_SYSLOG_H
1088 -#include <syslog.h>
1095 UINT16_t tagType, tagLen;
1097 if (packet->ver != 1) {
1098 - syslog(LOG_ERR, "Invalid PPPoE version (%d)", (int) packet->ver);
1099 + error("Invalid PPPoE version (%u)", packet->ver);
1102 if (packet->type != 1) {
1103 - syslog(LOG_ERR, "Invalid PPPoE type (%d)", (int) packet->type);
1104 + error("Invalid PPPoE type (%u)", packet->type);
1108 /* Do some sanity checks on packet */
1109 if (len > ETH_DATA_LEN - 6) { /* 6-byte overhead for PPPoE header */
1110 - syslog(LOG_ERR, "Invalid PPPoE packet length (%u)", len);
1111 + error("Invalid PPPoE packet length (%u)", len);
1118 if ((curTag - packet->payload) + tagLen + TAG_HDR_SIZE > len) {
1119 - syslog(LOG_ERR, "Invalid PPPoE tag length (%u)", tagLen);
1120 + error("Invalid PPPoE tag length (%u)", tagLen);
1123 func(tagType, tagLen, curTag+TAG_HDR_SIZE, extra);
1124 @@ -105,17 +101,17 @@
1125 UINT16_t tagType, tagLen;
1127 if (packet->ver != 1) {
1128 - syslog(LOG_ERR, "Invalid PPPoE version (%d)", (int) packet->ver);
1129 + error("Invalid PPPoE version (%u)", packet->ver);
1132 if (packet->type != 1) {
1133 - syslog(LOG_ERR, "Invalid PPPoE type (%d)", (int) packet->type);
1134 + error("Invalid PPPoE type (%u)", packet->type);
1138 /* Do some sanity checks on packet */
1139 if (len > ETH_DATA_LEN - 6) { /* 6-byte overhead for PPPoE header */
1140 - syslog(LOG_ERR, "Invalid PPPoE packet length (%u)", len);
1141 + error("Invalid PPPoE packet length (%u)", len);
1148 if ((curTag - packet->payload) + tagLen + TAG_HDR_SIZE > len) {
1149 - syslog(LOG_ERR, "Invalid PPPoE tag length (%u)", tagLen);
1150 + error("Invalid PPPoE tag length (%u)", tagLen);
1153 if (tagType == type) {
1159 /**********************************************************************
1160 *%FUNCTION: printErr
1163 fprintf(stderr, "pppoe: %s\n", str);
1164 syslog(LOG_ERR, "%s", str);
1169 /**********************************************************************
1172 char *copy = malloc(strlen(str)+1);
1174 - rp_fatal("strdup failed");
1175 + fatal("strdup failed");
1179 @@ -467,9 +465,10 @@
1180 fprintf(conn->debugFile, "\n");
1181 fflush(conn->debugFile);
1183 - syslog(LOG_INFO,"Sent PADT");
1184 + info("Sent PADT");
1188 /**********************************************************************
1189 *%FUNCTION: parseLogErrs
1197 diff -Naur ppp-2.4.4.orig/pppd/plugins/rp-pppoe/discovery.c ppp-2.4.4/pppd/plugins/rp-pppoe/discovery.c
1198 --- ppp-2.4.4.orig/pppd/plugins/rp-pppoe/discovery.c 2005-03-22 05:22:32.000000000 -0500
1199 +++ ppp-2.4.4/pppd/plugins/rp-pppoe/discovery.c 2009-05-07 17:01:46.000000000 -0400
1204 -#ifdef HAVE_SYSLOG_H
1205 -#include <syslog.h>
1211 @@ -167,24 +163,21 @@
1212 if (conn->printACNames) {
1213 printf("Got a Service-Name-Error tag: %.*s\n", (int) len, data);
1215 - syslog(LOG_ERR, "PADO: Service-Name-Error: %.*s", (int) len, data);
1217 + fatal("PADO: Service-Name-Error: %.*s", (int) len, data);
1220 case TAG_AC_SYSTEM_ERROR:
1221 if (conn->printACNames) {
1222 printf("Got a System-Error tag: %.*s\n", (int) len, data);
1224 - syslog(LOG_ERR, "PADO: System-Error: %.*s", (int) len, data);
1226 + fatal("PADO: System-Error: %.*s", (int) len, data);
1229 case TAG_GENERIC_ERROR:
1230 if (conn->printACNames) {
1231 printf("Got a Generic-Error tag: %.*s\n", (int) len, data);
1233 - syslog(LOG_ERR, "PADO: Generic-Error: %.*s", (int) len, data);
1235 + fatal("PADO: Generic-Error: %.*s", (int) len, data);
1239 @@ -209,20 +202,14 @@
1240 PPPoEConnection *conn = (PPPoEConnection *) extra;
1242 case TAG_SERVICE_NAME:
1243 - syslog(LOG_DEBUG, "PADS: Service-Name: '%.*s'", (int) len, data);
1244 + dbglog("PADS: Service-Name: '%.*s'", (int) len, data);
1246 case TAG_SERVICE_NAME_ERROR:
1247 - syslog(LOG_ERR, "PADS: Service-Name-Error: %.*s", (int) len, data);
1248 - fprintf(stderr, "PADS: Service-Name-Error: %.*s\n", (int) len, data);
1250 + fatal("PADS: Service-Name-Error: %.*s", (int) len, data);
1251 case TAG_AC_SYSTEM_ERROR:
1252 - syslog(LOG_ERR, "PADS: System-Error: %.*s", (int) len, data);
1253 - fprintf(stderr, "PADS: System-Error: %.*s\n", (int) len, data);
1255 + fatal("PADS: System-Error: %.*s", (int) len, data);
1256 case TAG_GENERIC_ERROR:
1257 - syslog(LOG_ERR, "PADS: Generic-Error: %.*s", (int) len, data);
1258 - fprintf(stderr, "PADS: Generic-Error: %.*s\n", (int) len, data);
1260 + fatal("PADS: Generic-Error: %.*s", (int) len, data);
1261 case TAG_RELAY_SESSION_ID:
1262 conn->relayId.type = htons(type);
1263 conn->relayId.length = htons(len);
1265 if (r >= 0 || errno != EINTR) break;
1268 - fatalSys("select (waitForPADO)");
1269 + fatal("waitForPADO: select: %m");
1271 if (r == 0) return; /* Timed out */
1276 if (ntohs(packet.length) + HDR_SIZE > len) {
1277 - syslog(LOG_ERR, "Bogus PPPoE length field (%u)",
1278 - (unsigned int) ntohs(packet.length));
1279 + error("Bogus PPPoE length field (%u)", ntohs(packet.length));
1283 @@ -366,16 +352,16 @@
1285 if (packet.code == CODE_PADO) {
1286 if (BROADCAST(packet.ethHdr.h_source)) {
1287 - printErr("Ignoring PADO packet from broadcast MAC address");
1288 + error("Ignoring PADO packet from broadcast MAC address");
1291 parsePacket(&packet, parsePADOTags, &pc);
1292 if (!pc.seenACName) {
1293 - printErr("Ignoring PADO packet with no AC-Name tag");
1294 + error("Ignoring PADO packet with no AC-Name tag");
1297 if (!pc.seenServiceName) {
1298 - printErr("Ignoring PADO packet with no Service-Name tag");
1299 + error("Ignoring PADO packet with no Service-Name tag");
1304 if (r >= 0 || errno != EINTR) break;
1307 - fatalSys("select (waitForPADS)");
1308 + fatal("waitForPADS: select: %m");
1315 if (ntohs(packet.length) + HDR_SIZE > len) {
1316 - syslog(LOG_ERR, "Bogus PPPoE length field (%u)",
1317 - (unsigned int) ntohs(packet.length));
1318 + error("Bogus PPPoE length field (%u)", ntohs(packet.length));
1322 @@ -556,11 +541,12 @@
1323 /* Don't bother with ntohs; we'll just end up converting it back... */
1324 conn->session = packet.session;
1326 - syslog(LOG_INFO, "PPP session is %d", (int) ntohs(conn->session));
1327 + info("PPP session is %d", ntohs(conn->session));
1329 /* RFC 2516 says session id MUST NOT be zero or 0xFFFF */
1330 if (ntohs(conn->session) == 0 || ntohs(conn->session) == 0xFFFF) {
1331 - syslog(LOG_ERR, "Access concentrator used a session value of %x -- the AC is violating RFC 2516", (unsigned int) ntohs(conn->session));
1332 + error("Access concentrator used a session value of 0x%x"
1333 + " -- the AC is violating RFC 2516", ntohs(conn->session));
1339 /* If we're only printing access concentrator names, we're done */
1340 if (conn->printACNames) {
1345 timeout = PADI_TIMEOUT;
1346 diff -Naur ppp-2.4.4.orig/pppd/plugins/rp-pppoe/if.c ppp-2.4.4/pppd/plugins/rp-pppoe/if.c
1347 --- ppp-2.4.4.orig/pppd/plugins/rp-pppoe/if.c 2001-12-13 21:55:20.000000000 -0500
1348 +++ ppp-2.4.4/pppd/plugins/rp-pppoe/if.c 2009-05-07 17:01:46.000000000 -0400
1350 #include <sys/ioctl.h>
1353 -#ifdef HAVE_SYSLOG_H
1354 -#include <syslog.h>
1362 UINT16_t type = (UINT16_t) ntohs(packet->ethHdr.h_proto);
1363 if (type != Eth_PPPOE_Discovery && type != Eth_PPPOE_Session) {
1364 - syslog(LOG_ERR, "Invalid ether type 0x%x", type);
1365 + error("Invalid ethernet type 0x%x", type);
1370 ifc.ifc_len = sizeof(inbuf);
1371 ifc.ifc_buf = inbuf;
1372 if (ioctl(sock, SIOCGIFCONF, &ifc) < 0) {
1373 - fatalSys("SIOCGIFCONF");
1374 + fatal("SIOCGIFCONF: %m");
1377 ifreq.ifr_name[0] = '\0';
1379 (sdl->sdl_alen == ETH_ALEN) &&
1380 !strncmp(ifname, ifr->ifr_name, sizeof(ifr->ifr_name))) {
1383 - sprintf(buffer, "interface %.16s has more than one ethernet address", ifname);
1385 + fatal("interface %s has more than one ethernet address", ifname);
1388 memcpy(hwaddr, LLADDR(sdl), ETH_ALEN);
1394 - sprintf(buffer, "interface %.16s has no ethernet address", ifname);
1396 + fatal("interface %s has no ethernet address", ifname);
1402 /* Apply the filter */
1403 if (ioctl(fd, BIOCSETF, &bpfProgram) < 0) {
1404 - fatalSys("ioctl(BIOCSETF)");
1405 + fatal("ioctl(BIOCSETF): %m");
1409 @@ -298,42 +290,36 @@
1412 case EACCES: /* permission denied */
1415 - sprintf(buffer, "Cannot open %.32s -- pppoe must be run as root.", bpfName);
1418 + fatal("Cannot open %s -- pppoe must be run as root.", bpfName);
1421 case ENOENT: /* no such file */
1423 - rp_fatal("No /dev/bpf* devices (check your kernel configuration for BPF support)");
1424 + fatal("No /dev/bpf* devices (check your kernel configuration for BPF support)");
1426 - rp_fatal("All /dev/bpf* devices are in use");
1427 + fatal("All /dev/bpf* devices are in use");
1431 - fatalSys(bpfName);
1432 + fatal("%s: %m", bpfName);
1435 if ((sock = socket(AF_LOCAL, SOCK_DGRAM, 0)) < 0) {
1436 - fatalSys("socket");
1437 + fatal("socket: %m");
1440 /* Check that the interface is up */
1441 strncpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
1442 if (ioctl(sock, SIOCGIFFLAGS, &ifr) < 0) {
1443 - fatalSys("ioctl(SIOCGIFFLAGS)");
1444 + fatal("ioctl(SIOCGIFFLAGS): %m");
1446 if ((ifr.ifr_flags & IFF_UP) == 0) {
1448 - sprintf(buffer, "Interface %.16s is not up\n", ifname);
1450 + fatal("Interface %s is not up", ifname);
1453 /* Fill in hardware address and initialize the packet filter rules */
1454 if (hwaddr == NULL) {
1455 - rp_fatal("openInterface: no hwaddr arg.");
1456 + fatal("openInterface: no hwaddr arg.");
1458 getHWaddr(sock, ifname, hwaddr);
1459 initFilter(fd, type, hwaddr);
1460 @@ -342,58 +328,52 @@
1461 #if !defined(__OpenBSD__)
1462 strncpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
1463 if (ioctl(sock, SIOCGIFMTU, &ifr) < 0) {
1464 - fatalSys("ioctl(SIOCGIFMTU)");
1465 + fatal("ioctl(SIOCGIFMTU): %m");
1467 if (ifr.ifr_mtu < ETH_DATA_LEN) {
1469 - sprintf(buffer, "Interface %.16s has MTU of %d -- should be %d. You may have serious connection problems.",
1470 + error("Interface %s has MTU of %d -- should be %d."
1471 + " You may have serious connection problems.",
1472 ifname, ifr.ifr_mtu, ETH_DATA_LEN);
1477 /* done with the socket */
1478 if (close(sock) < 0) {
1479 - fatalSys("close");
1480 + fatal("close: %m");
1483 /* Check the BPF version number */
1484 if (ioctl(fd, BIOCVERSION, &bpf_ver) < 0) {
1485 - fatalSys("ioctl(BIOCVERSION)");
1486 + fatal("ioctl(BIOCVERSION): %m");
1488 if ((bpf_ver.bv_major != BPF_MAJOR_VERSION) ||
1489 (bpf_ver.bv_minor < BPF_MINOR_VERSION)) {
1491 - sprintf(buffer, "Unsupported BPF version: %d.%d (kernel: %d.%d)",
1492 + fatal("Unsupported BPF version: %d.%d (kernel: %d.%d)",
1493 BPF_MAJOR_VERSION, BPF_MINOR_VERSION,
1494 bpf_ver.bv_major, bpf_ver.bv_minor);
1498 /* allocate a receive packet buffer */
1499 if (ioctl(fd, BIOCGBLEN, &bpfLength) < 0) {
1500 - fatalSys("ioctl(BIOCGBLEN)");
1501 + fatal("ioctl(BIOCGBLEN): %m");
1503 if (!(bpfBuffer = (unsigned char *) malloc(bpfLength))) {
1504 - rp_fatal("malloc");
1508 /* reads should return as soon as there is a packet available */
1510 if (ioctl(fd, BIOCIMMEDIATE, &optval) < 0) {
1511 - fatalSys("ioctl(BIOCIMMEDIATE)");
1512 + fatal("ioctl(BIOCIMMEDIATE): %m");
1515 /* Bind the interface to the filter */
1516 strncpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
1517 if (ioctl(fd, BIOCSETIF, &ifr) < 0) {
1519 - sprintf(buffer, "ioctl(BIOCSETIF) can't select interface %.16s",
1522 + fatal("ioctl(BIOCSETIF) can't select interface %s: %m", ifname);
1525 - syslog(LOG_INFO, "Interface=%.16s HWaddr=%02X:%02X:%02X:%02X:%02X:%02X Device=%.32s Buffer size=%d",
1526 + info("Interface=%s HWaddr=%02X:%02X:%02X:%02X:%02X:%02X Device=%s Buffer size=%d",
1528 hwaddr[0], hwaddr[1], hwaddr[2],
1529 hwaddr[3], hwaddr[4], hwaddr[5],
1530 @@ -442,48 +422,41 @@
1531 if ((fd = socket(domain, stype, htons(type))) < 0) {
1532 /* Give a more helpful message for the common error case */
1533 if (errno == EPERM) {
1534 - rp_fatal("Cannot create raw socket -- pppoe must be run as root.");
1535 + fatal("Cannot create raw socket -- pppoe must be run as root.");
1537 - fatalSys("socket");
1538 + fatal("cannot create the raw socket: %m");
1541 if (setsockopt(fd, SOL_SOCKET, SO_BROADCAST, &optval, sizeof(optval)) < 0) {
1542 - fatalSys("setsockopt");
1543 + fatal("setsockopt(SOL_SOCKET, SO_BROADCAST): %m");
1546 /* Fill in hardware address */
1548 strncpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
1549 - if (ioctl(fd, SIOCGIFHWADDR, &ifr) < 0) {
1550 - fatalSys("ioctl(SIOCGIFHWADDR)");
1552 + if (ioctl(fd, SIOCGIFHWADDR, &ifr) < 0)
1553 + fatal("ioctl(SIOCGIFHWADDR): %m");
1554 memcpy(hwaddr, ifr.ifr_hwaddr.sa_data, ETH_ALEN);
1556 if (ifr.ifr_hwaddr.sa_family != ARPHRD_ETHER) {
1558 - sprintf(buffer, "Interface %.16s is not Ethernet", ifname);
1560 + fatal("Interface %s is not Ethernet", ifname);
1563 if (NOT_UNICAST(hwaddr)) {
1566 - "Interface %.16s has broadcast/multicast MAC address??",
1567 + fatal("Interface %s has broadcast/multicast MAC address",
1573 /* Sanity check on MTU */
1574 strncpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
1575 if (ioctl(fd, SIOCGIFMTU, &ifr) < 0) {
1576 - fatalSys("ioctl(SIOCGIFMTU)");
1577 + fatal("ioctl(SIOCGIFMTU): %m");
1579 if (ifr.ifr_mtu < ETH_DATA_LEN) {
1581 - sprintf(buffer, "Interface %.16s has MTU of %d -- should be %d. You may have serious connection problems.",
1582 + error("Interface %s has MTU of %d -- should be %d."
1583 + " You may have serious connection problems.",
1584 ifname, ifr.ifr_mtu, ETH_DATA_LEN);
1588 #ifdef HAVE_STRUCT_SOCKADDR_LL
1591 strncpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
1592 if (ioctl(fd, SIOCGIFINDEX, &ifr) < 0) {
1593 - fatalSys("ioctl(SIOCFIGINDEX): Could not get interface index");
1594 + fatal("ioctl(SIOCFIGINDEX): Could not get interface index: %m");
1596 sa.sll_ifindex = ifr.ifr_ifindex;
1600 /* We're only interested in packets on specified interface */
1601 if (bind(fd, (struct sockaddr *) &sa, sizeof(sa)) < 0) {
1603 + fatal("bind: %m");
1607 @@ -527,13 +500,11 @@
1609 #if defined(USE_BPF)
1610 if (write(sock, pkt, size) < 0) {
1611 - sysErr("write (sendPacket)");
1613 + fatal("sendPacket: write: %m");
1615 #elif defined(HAVE_STRUCT_SOCKADDR_LL)
1616 if (send(sock, pkt, size, 0) < 0) {
1617 - sysErr("send (sendPacket)");
1619 + fatal("sendPacket: send: %m");
1623 @@ -577,12 +548,11 @@
1627 - rp_fatal("relay and server not supported on Linux 2.0 kernels");
1628 + fatal("relay and server not supported on Linux 2.0 kernels");
1630 strcpy(sa.sa_data, conn->ifName);
1631 if (sendto(sock, pkt, size, 0, &sa, sizeof(sa)) < 0) {
1632 - sysErr("sendto (sendPacket)");
1634 + fatal("sendPacket: sendto: %m");
1638 @@ -632,26 +602,24 @@
1641 if ((bpfSize = read(sock, bpfBuffer, bpfLength)) < 0) {
1642 - sysErr("read (receivePacket)");
1644 + fatal("receivePacket: read: %m");
1647 if (bpfSize < sizeof(hdr)) {
1648 - syslog(LOG_ERR, "Truncated bpf packet header: len=%d", bpfSize);
1649 + error("Truncated bpf packet header: len=%d", bpfSize);
1650 clearPacketHeader(pkt); /* resets bpfSize and bpfOffset */
1653 memcpy(&hdr, bpfBuffer + bpfOffset, sizeof(hdr));
1654 if (hdr.bh_caplen != hdr.bh_datalen) {
1655 - syslog(LOG_ERR, "Truncated bpf packet: caplen=%d, datalen=%d",
1656 + error("Truncated bpf packet: caplen=%d, datalen=%d",
1657 hdr.bh_caplen, hdr.bh_datalen);
1658 clearPacketHeader(pkt); /* resets bpfSize and bpfOffset */
1661 seglen = hdr.bh_hdrlen + hdr.bh_caplen;
1662 if (seglen > bpfSize) {
1663 - syslog(LOG_ERR, "Truncated bpf packet: seglen=%d, bpfSize=%d",
1665 + error("Truncated bpf packet: seglen=%d, bpfSize=%d", seglen, bpfSize);
1666 clearPacketHeader(pkt); /* resets bpfSize and bpfOffset */
1669 @@ -676,16 +644,14 @@
1672 if ((retval = getmsg(sock, NULL, &data, &flags)) < 0) {
1673 - sysErr("read (receivePacket)");
1675 + fatal("receivePacket: getmsg: %m");
1681 if ((*size = recv(sock, pkt, sizeof(PPPoEPacket), 0)) < 0) {
1682 - sysErr("recv (receivePacket)");
1684 + fatal("receivePacket: recv: %m");
1691 if(strlen(ifname) > PATH_MAX) {
1692 - rp_fatal("socket: string to long");
1693 + fatal("openInterface: interface name too long");
1696 ppa = atoi(&ifname[strlen(ifname)-1]);
1698 if (( fd = open(base_dev, O_RDWR)) < 0) {
1699 /* Give a more helpful message for the common error case */
1700 if (errno == EPERM) {
1701 - rp_fatal("Cannot create raw socket -- pppoe must be run as root.");
1702 + fatal("Cannot create raw socket -- pppoe must be run as root.");
1704 - fatalSys("socket");
1705 + fatal("open(%s): %m", base_dev);
1708 /* rearranged order of DLPI code - delphys 20010803 */
1709 @@ -747,17 +713,18 @@
1710 dl_abssaplen = ABS(dlp->info_ack.dl_sap_length);
1711 dl_saplen = dlp->info_ack.dl_sap_length;
1712 if (ETHERADDRL != (dlp->info_ack.dl_addr_length - dl_abssaplen))
1713 - fatalSys("invalid destination physical address length");
1714 + fatal("invalid destination physical address length");
1715 dl_addrlen = dl_abssaplen + ETHERADDRL;
1717 /* ethernet address retrieved as part of DL_INFO_ACK - delphys 20010803 */
1718 memcpy(hwaddr, (u_char*)((char*)(dlp) + (int)(dlp->info_ack.dl_addr_offset)), ETHERADDRL);
1720 if ( strioctl(fd, DLIOCRAW, -1, 0, NULL) < 0 ) {
1721 - fatalSys("DLIOCRAW");
1722 + fatal("DLIOCRAW: %m");
1725 - if (ioctl(fd, I_FLUSH, FLUSHR) < 0) fatalSys("I_FLUSH");
1726 + if (ioctl(fd, I_FLUSH, FLUSHR) < 0)
1727 + fatal("I_FLUSH: %m");
1734 if (putmsg(fd, &ctl, (struct strbuf*) NULL, flags) < 0)
1735 - fatalSys("dlpromiscon: putmsg");
1736 + fatal("dlpromiscon: putmsg: %m");
1743 if (putmsg(fd, &ctl, (struct strbuf*) NULL, flags) < 0)
1744 - fatalSys("dlinforeq: putmsg");
1745 + fatal("dlinforeq: putmsg: %m");
1748 void dlunitdatareq(int fd, u_char *addrp, int addrlen, u_long minpri, u_long maxpri, u_char *datap, int datalen)
1750 data.buf = (char *) datap;
1752 if (putmsg(fd, &ctl, &data, 0) < 0)
1753 - fatalSys("dlunitdatareq: putmsg");
1754 + fatal("dlunitdatareq: putmsg: %m");
1757 void dlinfoack(int fd, char *bufp)
1758 @@ -847,18 +814,14 @@
1759 expecting(DL_INFO_ACK, dlp);
1761 if (ctl.len < sizeof (dl_info_ack_t)) {
1763 - sprintf(buffer, "dlinfoack: response ctl.len too short: %d", ctl.len);
1765 + fatal("dlinfoack: response ctl.len too short: %d", ctl.len);
1768 if (flags != RS_HIPRI)
1769 - rp_fatal("dlinfoack: DL_INFO_ACK was not M_PCPROTO");
1770 + fatal("dlinfoack: DL_INFO_ACK was not M_PCPROTO");
1772 if (ctl.len < sizeof (dl_info_ack_t)) {
1774 - sprintf(buffer, "dlinfoack: short response ctl.len: %d", ctl.len);
1776 + fatal("dlinfoack: short response ctl.len: %d", ctl.len);
1783 if (putmsg(fd, &ctl, (struct strbuf*) NULL, flags) < 0)
1784 - fatalSys("dlbindreq: putmsg");
1785 + fatal("dlbindreq: putmsg: %m");
1788 void dlattachreq(int fd, u_long ppa)
1792 if (putmsg(fd, &ctl, (struct strbuf*) NULL, flags) < 0)
1793 - fatalSys("dlattachreq: putmsg");
1794 + fatal("dlattachreq: putmsg: %m");
1797 void dlokack(int fd, char *bufp)
1798 @@ -921,18 +884,14 @@
1799 expecting(DL_OK_ACK, dlp);
1801 if (ctl.len < sizeof (dl_ok_ack_t)) {
1803 - sprintf(buffer, "dlokack: response ctl.len too short: %d", ctl.len);
1805 + fatal("dlokack: response ctl.len too short: %d", ctl.len);
1808 if (flags != RS_HIPRI)
1809 - rp_fatal("dlokack: DL_OK_ACK was not M_PCPROTO");
1810 + fatal("dlokack: DL_OK_ACK was not M_PCPROTO");
1812 if (ctl.len < sizeof (dl_ok_ack_t)) {
1814 - sprintf(buffer, "dlokack: short response ctl.len: %d", ctl.len);
1816 + fatal("dlokack: short response ctl.len: %d", ctl.len);
1820 @@ -953,12 +912,10 @@
1821 expecting(DL_BIND_ACK, dlp);
1823 if (flags != RS_HIPRI)
1824 - rp_fatal("dlbindack: DL_OK_ACK was not M_PCPROTO");
1825 + fatal("dlbindack: DL_OK_ACK was not M_PCPROTO");
1827 if (ctl.len < sizeof (dl_bind_ack_t)) {
1829 - sprintf(buffer, "dlbindack: short response ctl.len: %d", ctl.len);
1831 + fatal("dlbindack: short response ctl.len: %d", ctl.len);
1837 (void) signal(SIGALRM, sigalrm);
1838 if (alarm(MAXWAIT) < 0) {
1839 - (void) sprintf(errmsg, "%s: alarm", caller);
1841 + fatal("%s: alarm", caller);
1845 @@ -998,61 +954,48 @@
1848 if ((rc = getmsg(fd, ctlp, datap, flagsp)) < 0) {
1849 - (void) sprintf(errmsg, "%s: getmsg", caller);
1851 + fatal(errmsg, "%s: getmsg: %m", caller);
1858 - (void) sprintf(errmsg, "%s: alarm", caller);
1860 + fatal("%s: alarm", caller);
1864 * Check for MOREDATA and/or MORECTL.
1866 if ((rc & (MORECTL | MOREDATA)) == (MORECTL | MOREDATA)) {
1868 - sprintf(buffer, "%s: MORECTL|MOREDATA", caller);
1870 + fatal("%s: MORECTL|MOREDATA", caller);
1875 - sprintf(buffer, "%s: MORECTL", caller);
1877 + fatal("%s: MORECTL", caller);
1880 if (rc & MOREDATA) {
1882 - sprintf(buffer, "%s: MOREDATA", caller);
1884 + fatal("%s: MOREDATA", caller);
1888 * Check for at least sizeof (long) control data portion.
1890 if (ctlp->len < sizeof (long)) {
1892 - sprintf(buffer, "getmsg: control portion length < sizeof (long): %d", ctlp->len);
1894 + fatal("getmsg: control portion length < sizeof (long): %d", ctlp->len);
1898 void sigalrm(int sig)
1900 - (void) rp_fatal("sigalrm: TIMEOUT");
1901 + fatal("sigalrm: TIMEOUT");
1904 void expecting(int prim, union DL_primitives *dlp)
1906 if (dlp->dl_primitive != (u_long)prim) {
1908 - sprintf(buffer, "expected %s got %s", dlprim(prim), dlprim(dlp->dl_primitive));
1911 + fatal("expected %s got %s", dlprim(prim), dlprim(dlp->dl_primitive));
1915 diff -Naur ppp-2.4.4.orig/pppd/plugins/rp-pppoe/Makefile.linux ppp-2.4.4/pppd/plugins/rp-pppoe/Makefile.linux
1916 --- ppp-2.4.4.orig/pppd/plugins/rp-pppoe/Makefile.linux 2006-06-04 01:07:46.000000000 -0400
1917 +++ ppp-2.4.4/pppd/plugins/rp-pppoe/Makefile.linux 2009-05-07 17:01:46.000000000 -0400
1919 CFLAGS=$(COPTS) -I../../../include/linux
1920 all: rp-pppoe.so pppoe-discovery
1922 -pppoe-discovery: libplugin.a pppoe-discovery.o
1923 - $(CC) -o pppoe-discovery pppoe-discovery.o libplugin.a
1924 +pppoe-discovery: pppoe-discovery.o utils.o libplugin.a
1925 + $(CC) -o pppoe-discovery pppoe-discovery.o utils.o libplugin.a
1927 pppoe-discovery.o: pppoe-discovery.c
1928 $(CC) $(CFLAGS) '-DVERSION="$(VERSION)"' -c -o pppoe-discovery.o pppoe-discovery.c
1929 diff -Naur ppp-2.4.4.orig/pppd/plugins/rp-pppoe/plugin.c ppp-2.4.4/pppd/plugins/rp-pppoe/plugin.c
1930 --- ppp-2.4.4.orig/pppd/plugins/rp-pppoe/plugin.c 2006-05-29 19:29:16.000000000 -0400
1931 +++ ppp-2.4.4/pppd/plugins/rp-pppoe/plugin.c 2009-05-07 17:01:46.000000000 -0400
1933 #include "pppd/pathnames.h"
1935 #include <linux/types.h>
1936 -#include <syslog.h>
1937 #include <sys/ioctl.h>
1938 #include <sys/types.h>
1939 #include <sys/socket.h>
1940 @@ -173,10 +172,8 @@
1941 (unsigned) conn->peerEth[5]);
1943 if (connect(conn->sessionSocket, (struct sockaddr *) &sp,
1944 - sizeof(struct sockaddr_pppox)) < 0) {
1945 + sizeof(struct sockaddr_pppox)) < 0)
1946 fatal("Failed to connect PPPoE socket: %d %m", errno);
1950 return conn->sessionSocket;
1952 @@ -320,11 +317,9 @@
1955 add_options(Options);
1957 - info("RP-PPPoE plugin version %s compiled against pppd %s",
1958 - RP_VERSION, VERSION);
1962 /**********************************************************************
1963 *%FUNCTION: fatalSys
1971 void pppoe_check_options(void)
1973 diff -Naur ppp-2.4.4.orig/pppd/plugins/rp-pppoe/pppoe-discovery.c ppp-2.4.4/pppd/plugins/rp-pppoe/pppoe-discovery.c
1974 --- ppp-2.4.4.orig/pppd/plugins/rp-pppoe/pppoe-discovery.c 2004-11-13 07:12:05.000000000 -0500
1975 +++ ppp-2.4.4/pppd/plugins/rp-pppoe/pppoe-discovery.c 2009-05-07 17:01:46.000000000 -0400
1980 -char *xstrdup(const char *s);
1983 -void die(int status)
1988 int main(int argc, char *argv[])
1993 conn = malloc(sizeof(PPPoEConnection));
1995 - fatalSys("malloc");
1998 memset(conn, 0, sizeof(PPPoEConnection));
2000 while ((opt = getopt(argc, argv, "I:D:VUAS:C:h")) > 0) {
2003 - conn->serviceName = xstrdup(optarg);
2004 + conn->serviceName = strDup(optarg);
2007 - conn->acName = xstrdup(optarg);
2008 + conn->acName = strDup(optarg);
2011 conn->useHostUniq = 1;
2013 fprintf(conn->debugFile, "pppoe-discovery %s\n", VERSION);
2016 - conn->ifName = xstrdup(optarg);
2017 + conn->ifName = strDup(optarg);
2020 /* this is the default */
2023 /* default interface name */
2025 - conn->ifName = strdup("eth0");
2026 + conn->ifName = strDup("eth0");
2028 conn->discoverySocket = -1;
2029 conn->sessionSocket = -1;
2034 -void rp_fatal(char const *str)
2039 - sprintf(buf, "pppoe-discovery: %.256s", str);
2043 -void fatalSys(char const *str)
2048 - sprintf(buf, "%.256s: %.256s", str, strerror(i));
2050 - sprintf(buf, "pppoe-discovery: %.256s: %.256s", str, strerror(i));
2054 -void sysErr(char const *str)
2059 -char *xstrdup(const char *s)
2061 - register char *ret = strdup(s);
2069 fprintf(stderr, "Usage: pppoe-discovery [options]\n");
2070 diff -Naur ppp-2.4.4.orig/pppd/plugins/rp-pppoe/pppoe.h ppp-2.4.4/pppd/plugins/rp-pppoe/pppoe.h
2071 --- ppp-2.4.4.orig/pppd/plugins/rp-pppoe/pppoe.h 2004-11-04 05:07:37.000000000 -0500
2072 +++ ppp-2.4.4/pppd/plugins/rp-pppoe/pppoe.h 2009-05-07 17:01:46.000000000 -0400
2073 @@ -307,12 +307,18 @@
2074 unsigned char *findTag(PPPoEPacket *packet, UINT16_t tagType,
2077 +void dbglog(char *, ...); /* log a debug message */
2078 +void info(char *, ...); /* log an informational message */
2079 +void warn(char *, ...); /* log a warning message */
2080 +void error(char *, ...); /* log an error message */
2081 +void fatal(char *, ...); /* log an error message and die(1) */
2083 #define SET_STRING(var, val) do { if (var) free(var); var = strDup(val); } while(0);
2085 #define CHECK_ROOM(cursor, start, len) \
2087 if (((cursor)-(start))+(len) > MAX_PPPOE_PAYLOAD) { \
2088 - syslog(LOG_ERR, "Would create too-long packet"); \
2089 + error("Would create too-long packet"); \
2093 diff -Naur ppp-2.4.4.orig/pppd/plugins/rp-pppoe/utils.c ppp-2.4.4/pppd/plugins/rp-pppoe/utils.c
2094 --- ppp-2.4.4.orig/pppd/plugins/rp-pppoe/utils.c 1969-12-31 19:00:00.000000000 -0500
2095 +++ ppp-2.4.4/pppd/plugins/rp-pppoe/utils.c 2009-05-07 17:01:46.000000000 -0400
2098 +#include <stdlib.h>
2099 +#include <unistd.h>
2100 +#include <stdarg.h>
2101 +#include <syslog.h>
2103 +void dbglog(const char *fmt, ...)
2107 + va_start(ap, fmt);
2108 + vsyslog(LOG_DEBUG, fmt, ap);
2109 + vfprintf(stderr, fmt, ap);
2110 + fputs("\n", stderr);
2114 +void info(const char *fmt, ...)
2118 + va_start(ap, fmt);
2119 + vsyslog(LOG_INFO, fmt, ap);
2120 + vfprintf(stderr, fmt, ap);
2121 + fputs("\n", stderr);
2125 +void warn(const char *fmt, ...)
2129 + va_start(ap, fmt);
2130 + vsyslog(LOG_WARNING, fmt, ap);
2131 + vfprintf(stderr, fmt, ap);
2132 + fputs("\n", stderr);
2136 +void error(const char *fmt, ...)
2140 + va_start(ap, fmt);
2141 + vsyslog(LOG_ERR, fmt, ap);
2142 + vfprintf(stderr, fmt, ap);
2143 + fputs("\n", stderr);
2147 +void fatal(const char *fmt, ...)
2151 + va_start(ap, fmt);
2152 + vsyslog(LOG_ERR, fmt, ap);
2153 + vfprintf(stderr, fmt, ap);
2154 + fputs("\n", stderr);