1 --- a/pppd/plugins/rp-pppoe/common.c
2 +++ b/pppd/plugins/rp-pppoe/common.c
3 @@ -18,10 +18,6 @@ static char const RCSID[] =
14 @@ -50,17 +46,17 @@ parsePacket(PPPoEPacket *packet, ParseFu
15 UINT16_t tagType, tagLen;
17 if (packet->ver != 1) {
18 - syslog(LOG_ERR, "Invalid PPPoE version (%d)", (int) packet->ver);
19 + error("Invalid PPPoE version (%u)", packet->ver);
22 if (packet->type != 1) {
23 - syslog(LOG_ERR, "Invalid PPPoE type (%d)", (int) packet->type);
24 + error("Invalid PPPoE type (%u)", packet->type);
28 /* Do some sanity checks on packet */
29 if (len > ETH_DATA_LEN - 6) { /* 6-byte overhead for PPPoE header */
30 - syslog(LOG_ERR, "Invalid PPPoE packet length (%u)", len);
31 + error("Invalid PPPoE packet length (%u)", len);
35 @@ -76,7 +72,7 @@ parsePacket(PPPoEPacket *packet, ParseFu
38 if ((curTag - packet->payload) + tagLen + TAG_HDR_SIZE > len) {
39 - syslog(LOG_ERR, "Invalid PPPoE tag length (%u)", tagLen);
40 + error("Invalid PPPoE tag length (%u)", tagLen);
43 func(tagType, tagLen, curTag+TAG_HDR_SIZE, extra);
44 @@ -105,17 +101,17 @@ findTag(PPPoEPacket *packet, UINT16_t ty
45 UINT16_t tagType, tagLen;
47 if (packet->ver != 1) {
48 - syslog(LOG_ERR, "Invalid PPPoE version (%d)", (int) packet->ver);
49 + error("Invalid PPPoE version (%u)", packet->ver);
52 if (packet->type != 1) {
53 - syslog(LOG_ERR, "Invalid PPPoE type (%d)", (int) packet->type);
54 + error("Invalid PPPoE type (%u)", packet->type);
58 /* Do some sanity checks on packet */
59 if (len > ETH_DATA_LEN - 6) { /* 6-byte overhead for PPPoE header */
60 - syslog(LOG_ERR, "Invalid PPPoE packet length (%u)", len);
61 + error("Invalid PPPoE packet length (%u)", len);
65 @@ -131,7 +127,7 @@ findTag(PPPoEPacket *packet, UINT16_t ty
68 if ((curTag - packet->payload) + tagLen + TAG_HDR_SIZE > len) {
69 - syslog(LOG_ERR, "Invalid PPPoE tag length (%u)", tagLen);
70 + error("Invalid PPPoE tag length (%u)", tagLen);
73 if (tagType == type) {
74 @@ -143,6 +139,7 @@ findTag(PPPoEPacket *packet, UINT16_t ty
79 /**********************************************************************
82 @@ -158,6 +155,7 @@ printErr(char const *str)
83 fprintf(stderr, "pppoe: %s\n", str);
84 syslog(LOG_ERR, "%s", str);
89 /**********************************************************************
90 @@ -172,7 +170,7 @@ strDup(char const *str)
92 char *copy = malloc(strlen(str)+1);
94 - rp_fatal("strdup failed");
95 + fatal("strdup failed");
99 @@ -467,9 +465,10 @@ sendPADT(PPPoEConnection *conn, char con
100 fprintf(conn->debugFile, "\n");
101 fflush(conn->debugFile);
103 - syslog(LOG_INFO,"Sent PADT");
108 /**********************************************************************
109 *%FUNCTION: parseLogErrs
111 @@ -501,4 +500,5 @@ parseLogErrs(UINT16_t type, UINT16_t len
117 --- a/pppd/plugins/rp-pppoe/discovery.c
118 +++ b/pppd/plugins/rp-pppoe/discovery.c
119 @@ -13,10 +13,6 @@ static char const RCSID[] =
123 -#ifdef HAVE_SYSLOG_H
130 @@ -167,24 +163,21 @@ parsePADOTags(UINT16_t type, UINT16_t le
131 if (conn->printACNames) {
132 printf("Got a Service-Name-Error tag: %.*s\n", (int) len, data);
134 - syslog(LOG_ERR, "PADO: Service-Name-Error: %.*s", (int) len, data);
136 + fatal("PADO: Service-Name-Error: %.*s", (int) len, data);
139 case TAG_AC_SYSTEM_ERROR:
140 if (conn->printACNames) {
141 printf("Got a System-Error tag: %.*s\n", (int) len, data);
143 - syslog(LOG_ERR, "PADO: System-Error: %.*s", (int) len, data);
145 + fatal("PADO: System-Error: %.*s", (int) len, data);
148 case TAG_GENERIC_ERROR:
149 if (conn->printACNames) {
150 printf("Got a Generic-Error tag: %.*s\n", (int) len, data);
152 - syslog(LOG_ERR, "PADO: Generic-Error: %.*s", (int) len, data);
154 + fatal("PADO: Generic-Error: %.*s", (int) len, data);
158 @@ -209,20 +202,14 @@ parsePADSTags(UINT16_t type, UINT16_t le
159 PPPoEConnection *conn = (PPPoEConnection *) extra;
161 case TAG_SERVICE_NAME:
162 - syslog(LOG_DEBUG, "PADS: Service-Name: '%.*s'", (int) len, data);
163 + dbglog("PADS: Service-Name: '%.*s'", (int) len, data);
165 case TAG_SERVICE_NAME_ERROR:
166 - syslog(LOG_ERR, "PADS: Service-Name-Error: %.*s", (int) len, data);
167 - fprintf(stderr, "PADS: Service-Name-Error: %.*s\n", (int) len, data);
169 + fatal("PADS: Service-Name-Error: %.*s", (int) len, data);
170 case TAG_AC_SYSTEM_ERROR:
171 - syslog(LOG_ERR, "PADS: System-Error: %.*s", (int) len, data);
172 - fprintf(stderr, "PADS: System-Error: %.*s\n", (int) len, data);
174 + fatal("PADS: System-Error: %.*s", (int) len, data);
175 case TAG_GENERIC_ERROR:
176 - syslog(LOG_ERR, "PADS: Generic-Error: %.*s", (int) len, data);
177 - fprintf(stderr, "PADS: Generic-Error: %.*s\n", (int) len, data);
179 + fatal("PADS: Generic-Error: %.*s", (int) len, data);
180 case TAG_RELAY_SESSION_ID:
181 conn->relayId.type = htons(type);
182 conn->relayId.length = htons(len);
183 @@ -336,7 +323,7 @@ waitForPADO(PPPoEConnection *conn, int t
184 if (r >= 0 || errno != EINTR) break;
187 - fatalSys("select (waitForPADO)");
188 + fatal("waitForPADO: select: %m");
190 if (r == 0) return; /* Timed out */
192 @@ -346,8 +333,7 @@ waitForPADO(PPPoEConnection *conn, int t
195 if (ntohs(packet.length) + HDR_SIZE > len) {
196 - syslog(LOG_ERR, "Bogus PPPoE length field (%u)",
197 - (unsigned int) ntohs(packet.length));
198 + error("Bogus PPPoE length field (%u)", ntohs(packet.length));
202 @@ -366,16 +352,16 @@ waitForPADO(PPPoEConnection *conn, int t
204 if (packet.code == CODE_PADO) {
205 if (BROADCAST(packet.ethHdr.h_source)) {
206 - printErr("Ignoring PADO packet from broadcast MAC address");
207 + error("Ignoring PADO packet from broadcast MAC address");
210 parsePacket(&packet, parsePADOTags, &pc);
211 if (!pc.seenACName) {
212 - printErr("Ignoring PADO packet with no AC-Name tag");
213 + error("Ignoring PADO packet with no AC-Name tag");
216 if (!pc.seenServiceName) {
217 - printErr("Ignoring PADO packet with no Service-Name tag");
218 + error("Ignoring PADO packet with no Service-Name tag");
222 @@ -513,7 +499,7 @@ waitForPADS(PPPoEConnection *conn, int t
223 if (r >= 0 || errno != EINTR) break;
226 - fatalSys("select (waitForPADS)");
227 + fatal("waitForPADS: select: %m");
231 @@ -523,8 +509,7 @@ waitForPADS(PPPoEConnection *conn, int t
234 if (ntohs(packet.length) + HDR_SIZE > len) {
235 - syslog(LOG_ERR, "Bogus PPPoE length field (%u)",
236 - (unsigned int) ntohs(packet.length));
237 + error("Bogus PPPoE length field (%u)", ntohs(packet.length));
241 @@ -556,11 +541,12 @@ waitForPADS(PPPoEConnection *conn, int t
242 /* Don't bother with ntohs; we'll just end up converting it back... */
243 conn->session = packet.session;
245 - syslog(LOG_INFO, "PPP session is %d", (int) ntohs(conn->session));
246 + info("PPP session is %d", ntohs(conn->session));
248 /* RFC 2516 says session id MUST NOT be zero or 0xFFFF */
249 if (ntohs(conn->session) == 0 || ntohs(conn->session) == 0xFFFF) {
250 - syslog(LOG_ERR, "Access concentrator used a session value of %x -- the AC is violating RFC 2516", (unsigned int) ntohs(conn->session));
251 + error("Access concentrator used a session value of 0x%x"
252 + " -- the AC is violating RFC 2516", ntohs(conn->session));
256 @@ -620,7 +606,7 @@ discovery(PPPoEConnection *conn)
258 /* If we're only printing access concentrator names, we're done */
259 if (conn->printACNames) {
264 timeout = PADI_TIMEOUT;
265 --- a/pppd/plugins/rp-pppoe/if.c
266 +++ b/pppd/plugins/rp-pppoe/if.c
267 @@ -40,10 +40,6 @@ static char const RCSID[] =
268 #include <sys/ioctl.h>
271 -#ifdef HAVE_SYSLOG_H
278 @@ -127,7 +123,7 @@ etherType(PPPoEPacket *packet)
280 UINT16_t type = (UINT16_t) ntohs(packet->ethHdr.h_proto);
281 if (type != Eth_PPPOE_Discovery && type != Eth_PPPOE_Session) {
282 - syslog(LOG_ERR, "Invalid ether type 0x%x", type);
283 + error("Invalid ethernet type 0x%x", type);
287 @@ -156,7 +152,7 @@ getHWaddr(int sock, char const *ifname,
288 ifc.ifc_len = sizeof(inbuf);
290 if (ioctl(sock, SIOCGIFCONF, &ifc) < 0) {
291 - fatalSys("SIOCGIFCONF");
292 + fatal("SIOCGIFCONF: %m");
295 ifreq.ifr_name[0] = '\0';
296 @@ -172,9 +168,7 @@ getHWaddr(int sock, char const *ifname,
297 (sdl->sdl_alen == ETH_ALEN) &&
298 !strncmp(ifname, ifr->ifr_name, sizeof(ifr->ifr_name))) {
301 - sprintf(buffer, "interface %.16s has more than one ethernet address", ifname);
303 + fatal("interface %s has more than one ethernet address", ifname);
306 memcpy(hwaddr, LLADDR(sdl), ETH_ALEN);
307 @@ -183,9 +177,7 @@ getHWaddr(int sock, char const *ifname,
312 - sprintf(buffer, "interface %.16s has no ethernet address", ifname);
314 + fatal("interface %s has no ethernet address", ifname);
318 @@ -252,7 +244,7 @@ initFilter(int fd, UINT16_t type, unsign
320 /* Apply the filter */
321 if (ioctl(fd, BIOCSETF, &bpfProgram) < 0) {
322 - fatalSys("ioctl(BIOCSETF)");
323 + fatal("ioctl(BIOCSETF): %m");
327 @@ -298,42 +290,36 @@ openInterface(char const *ifname, UINT16
330 case EACCES: /* permission denied */
333 - sprintf(buffer, "Cannot open %.32s -- pppoe must be run as root.", bpfName);
336 + fatal("Cannot open %s -- pppoe must be run as root.", bpfName);
339 case ENOENT: /* no such file */
341 - rp_fatal("No /dev/bpf* devices (check your kernel configuration for BPF support)");
342 + fatal("No /dev/bpf* devices (check your kernel configuration for BPF support)");
344 - rp_fatal("All /dev/bpf* devices are in use");
345 + fatal("All /dev/bpf* devices are in use");
350 + fatal("%s: %m", bpfName);
353 if ((sock = socket(AF_LOCAL, SOCK_DGRAM, 0)) < 0) {
354 - fatalSys("socket");
355 + fatal("socket: %m");
358 /* Check that the interface is up */
359 strncpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
360 if (ioctl(sock, SIOCGIFFLAGS, &ifr) < 0) {
361 - fatalSys("ioctl(SIOCGIFFLAGS)");
362 + fatal("ioctl(SIOCGIFFLAGS): %m");
364 if ((ifr.ifr_flags & IFF_UP) == 0) {
366 - sprintf(buffer, "Interface %.16s is not up\n", ifname);
368 + fatal("Interface %s is not up", ifname);
371 /* Fill in hardware address and initialize the packet filter rules */
372 if (hwaddr == NULL) {
373 - rp_fatal("openInterface: no hwaddr arg.");
374 + fatal("openInterface: no hwaddr arg.");
376 getHWaddr(sock, ifname, hwaddr);
377 initFilter(fd, type, hwaddr);
378 @@ -342,58 +328,52 @@ openInterface(char const *ifname, UINT16
379 #if !defined(__OpenBSD__)
380 strncpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
381 if (ioctl(sock, SIOCGIFMTU, &ifr) < 0) {
382 - fatalSys("ioctl(SIOCGIFMTU)");
383 + fatal("ioctl(SIOCGIFMTU): %m");
385 if (ifr.ifr_mtu < ETH_DATA_LEN) {
387 - sprintf(buffer, "Interface %.16s has MTU of %d -- should be %d. You may have serious connection problems.",
388 + error("Interface %s has MTU of %d -- should be %d."
389 + " You may have serious connection problems.",
390 ifname, ifr.ifr_mtu, ETH_DATA_LEN);
395 /* done with the socket */
396 if (close(sock) < 0) {
398 + fatal("close: %m");
401 /* Check the BPF version number */
402 if (ioctl(fd, BIOCVERSION, &bpf_ver) < 0) {
403 - fatalSys("ioctl(BIOCVERSION)");
404 + fatal("ioctl(BIOCVERSION): %m");
406 if ((bpf_ver.bv_major != BPF_MAJOR_VERSION) ||
407 (bpf_ver.bv_minor < BPF_MINOR_VERSION)) {
409 - sprintf(buffer, "Unsupported BPF version: %d.%d (kernel: %d.%d)",
410 + fatal("Unsupported BPF version: %d.%d (kernel: %d.%d)",
411 BPF_MAJOR_VERSION, BPF_MINOR_VERSION,
412 bpf_ver.bv_major, bpf_ver.bv_minor);
416 /* allocate a receive packet buffer */
417 if (ioctl(fd, BIOCGBLEN, &bpfLength) < 0) {
418 - fatalSys("ioctl(BIOCGBLEN)");
419 + fatal("ioctl(BIOCGBLEN): %m");
421 if (!(bpfBuffer = (unsigned char *) malloc(bpfLength))) {
422 - rp_fatal("malloc");
426 /* reads should return as soon as there is a packet available */
428 if (ioctl(fd, BIOCIMMEDIATE, &optval) < 0) {
429 - fatalSys("ioctl(BIOCIMMEDIATE)");
430 + fatal("ioctl(BIOCIMMEDIATE): %m");
433 /* Bind the interface to the filter */
434 strncpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
435 if (ioctl(fd, BIOCSETIF, &ifr) < 0) {
437 - sprintf(buffer, "ioctl(BIOCSETIF) can't select interface %.16s",
440 + fatal("ioctl(BIOCSETIF) can't select interface %s: %m", ifname);
443 - syslog(LOG_INFO, "Interface=%.16s HWaddr=%02X:%02X:%02X:%02X:%02X:%02X Device=%.32s Buffer size=%d",
444 + info("Interface=%s HWaddr=%02X:%02X:%02X:%02X:%02X:%02X Device=%s Buffer size=%d",
446 hwaddr[0], hwaddr[1], hwaddr[2],
447 hwaddr[3], hwaddr[4], hwaddr[5],
448 @@ -442,48 +422,41 @@ openInterface(char const *ifname, UINT16
449 if ((fd = socket(domain, stype, htons(type))) < 0) {
450 /* Give a more helpful message for the common error case */
451 if (errno == EPERM) {
452 - rp_fatal("Cannot create raw socket -- pppoe must be run as root.");
453 + fatal("Cannot create raw socket -- pppoe must be run as root.");
455 - fatalSys("socket");
456 + fatal("cannot create the raw socket: %m");
459 if (setsockopt(fd, SOL_SOCKET, SO_BROADCAST, &optval, sizeof(optval)) < 0) {
460 - fatalSys("setsockopt");
461 + fatal("setsockopt(SOL_SOCKET, SO_BROADCAST): %m");
464 /* Fill in hardware address */
466 strncpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
467 - if (ioctl(fd, SIOCGIFHWADDR, &ifr) < 0) {
468 - fatalSys("ioctl(SIOCGIFHWADDR)");
470 + if (ioctl(fd, SIOCGIFHWADDR, &ifr) < 0)
471 + fatal("ioctl(SIOCGIFHWADDR): %m");
472 memcpy(hwaddr, ifr.ifr_hwaddr.sa_data, ETH_ALEN);
474 if (ifr.ifr_hwaddr.sa_family != ARPHRD_ETHER) {
476 - sprintf(buffer, "Interface %.16s is not Ethernet", ifname);
478 + fatal("Interface %s is not Ethernet", ifname);
481 if (NOT_UNICAST(hwaddr)) {
484 - "Interface %.16s has broadcast/multicast MAC address??",
485 + fatal("Interface %s has broadcast/multicast MAC address",
491 /* Sanity check on MTU */
492 strncpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
493 if (ioctl(fd, SIOCGIFMTU, &ifr) < 0) {
494 - fatalSys("ioctl(SIOCGIFMTU)");
495 + fatal("ioctl(SIOCGIFMTU): %m");
497 if (ifr.ifr_mtu < ETH_DATA_LEN) {
499 - sprintf(buffer, "Interface %.16s has MTU of %d -- should be %d. You may have serious connection problems.",
500 + error("Interface %s has MTU of %d -- should be %d."
501 + " You may have serious connection problems.",
502 ifname, ifr.ifr_mtu, ETH_DATA_LEN);
506 #ifdef HAVE_STRUCT_SOCKADDR_LL
507 @@ -493,7 +466,7 @@ openInterface(char const *ifname, UINT16
509 strncpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
510 if (ioctl(fd, SIOCGIFINDEX, &ifr) < 0) {
511 - fatalSys("ioctl(SIOCFIGINDEX): Could not get interface index");
512 + fatal("ioctl(SIOCFIGINDEX): Could not get interface index: %m");
514 sa.sll_ifindex = ifr.ifr_ifindex;
516 @@ -503,7 +476,7 @@ openInterface(char const *ifname, UINT16
518 /* We're only interested in packets on specified interface */
519 if (bind(fd, (struct sockaddr *) &sa, sizeof(sa)) < 0) {
525 @@ -527,13 +500,11 @@ sendPacket(PPPoEConnection *conn, int so
528 if (write(sock, pkt, size) < 0) {
529 - sysErr("write (sendPacket)");
531 + fatal("sendPacket: write: %m");
533 #elif defined(HAVE_STRUCT_SOCKADDR_LL)
534 if (send(sock, pkt, size, 0) < 0) {
535 - sysErr("send (sendPacket)");
537 + fatal("sendPacket: send: %m");
541 @@ -577,12 +548,11 @@ sendPacket(PPPoEConnection *conn, int so
545 - rp_fatal("relay and server not supported on Linux 2.0 kernels");
546 + fatal("relay and server not supported on Linux 2.0 kernels");
548 strcpy(sa.sa_data, conn->ifName);
549 if (sendto(sock, pkt, size, 0, &sa, sizeof(sa)) < 0) {
550 - sysErr("sendto (sendPacket)");
552 + fatal("sendPacket: sendto: %m");
556 @@ -632,26 +602,24 @@ receivePacket(int sock, PPPoEPacket *pkt
559 if ((bpfSize = read(sock, bpfBuffer, bpfLength)) < 0) {
560 - sysErr("read (receivePacket)");
562 + fatal("receivePacket: read: %m");
565 if (bpfSize < sizeof(hdr)) {
566 - syslog(LOG_ERR, "Truncated bpf packet header: len=%d", bpfSize);
567 + error("Truncated bpf packet header: len=%d", bpfSize);
568 clearPacketHeader(pkt); /* resets bpfSize and bpfOffset */
571 memcpy(&hdr, bpfBuffer + bpfOffset, sizeof(hdr));
572 if (hdr.bh_caplen != hdr.bh_datalen) {
573 - syslog(LOG_ERR, "Truncated bpf packet: caplen=%d, datalen=%d",
574 + error("Truncated bpf packet: caplen=%d, datalen=%d",
575 hdr.bh_caplen, hdr.bh_datalen);
576 clearPacketHeader(pkt); /* resets bpfSize and bpfOffset */
579 seglen = hdr.bh_hdrlen + hdr.bh_caplen;
580 if (seglen > bpfSize) {
581 - syslog(LOG_ERR, "Truncated bpf packet: seglen=%d, bpfSize=%d",
583 + error("Truncated bpf packet: seglen=%d, bpfSize=%d", seglen, bpfSize);
584 clearPacketHeader(pkt); /* resets bpfSize and bpfOffset */
587 @@ -676,16 +644,14 @@ receivePacket(int sock, PPPoEPacket *pkt
590 if ((retval = getmsg(sock, NULL, &data, &flags)) < 0) {
591 - sysErr("read (receivePacket)");
593 + fatal("receivePacket: getmsg: %m");
599 if ((*size = recv(sock, pkt, sizeof(PPPoEPacket), 0)) < 0) {
600 - sysErr("recv (receivePacket)");
602 + fatal("receivePacket: recv: %m");
606 @@ -716,7 +682,7 @@ openInterface(char const *ifname, UINT16
609 if(strlen(ifname) > PATH_MAX) {
610 - rp_fatal("socket: string to long");
611 + fatal("openInterface: interface name too long");
614 ppa = atoi(&ifname[strlen(ifname)-1]);
615 @@ -729,9 +695,9 @@ openInterface(char const *ifname, UINT16
616 if (( fd = open(base_dev, O_RDWR)) < 0) {
617 /* Give a more helpful message for the common error case */
618 if (errno == EPERM) {
619 - rp_fatal("Cannot create raw socket -- pppoe must be run as root.");
620 + fatal("Cannot create raw socket -- pppoe must be run as root.");
622 - fatalSys("socket");
623 + fatal("open(%s): %m", base_dev);
626 /* rearranged order of DLPI code - delphys 20010803 */
627 @@ -747,17 +713,18 @@ openInterface(char const *ifname, UINT16
628 dl_abssaplen = ABS(dlp->info_ack.dl_sap_length);
629 dl_saplen = dlp->info_ack.dl_sap_length;
630 if (ETHERADDRL != (dlp->info_ack.dl_addr_length - dl_abssaplen))
631 - fatalSys("invalid destination physical address length");
632 + fatal("invalid destination physical address length");
633 dl_addrlen = dl_abssaplen + ETHERADDRL;
635 /* ethernet address retrieved as part of DL_INFO_ACK - delphys 20010803 */
636 memcpy(hwaddr, (u_char*)((char*)(dlp) + (int)(dlp->info_ack.dl_addr_offset)), ETHERADDRL);
638 if ( strioctl(fd, DLIOCRAW, -1, 0, NULL) < 0 ) {
639 - fatalSys("DLIOCRAW");
640 + fatal("DLIOCRAW: %m");
643 - if (ioctl(fd, I_FLUSH, FLUSHR) < 0) fatalSys("I_FLUSH");
644 + if (ioctl(fd, I_FLUSH, FLUSHR) < 0)
645 + fatal("I_FLUSH: %m");
649 @@ -780,7 +747,7 @@ void dlpromisconreq(int fd, u_long level
652 if (putmsg(fd, &ctl, (struct strbuf*) NULL, flags) < 0)
653 - fatalSys("dlpromiscon: putmsg");
654 + fatal("dlpromiscon: putmsg: %m");
658 @@ -799,7 +766,7 @@ void dlinforeq(int fd)
661 if (putmsg(fd, &ctl, (struct strbuf*) NULL, flags) < 0)
662 - fatalSys("dlinforeq: putmsg");
663 + fatal("dlinforeq: putmsg: %m");
666 void dlunitdatareq(int fd, u_char *addrp, int addrlen, u_long minpri, u_long maxpri, u_char *datap, int datalen)
667 @@ -827,7 +794,7 @@ void dlunitdatareq(int fd, u_char *addrp
668 data.buf = (char *) datap;
670 if (putmsg(fd, &ctl, &data, 0) < 0)
671 - fatalSys("dlunitdatareq: putmsg");
672 + fatal("dlunitdatareq: putmsg: %m");
675 void dlinfoack(int fd, char *bufp)
676 @@ -847,18 +814,14 @@ void dlinfoack(int fd, char *bufp)
677 expecting(DL_INFO_ACK, dlp);
679 if (ctl.len < sizeof (dl_info_ack_t)) {
681 - sprintf(buffer, "dlinfoack: response ctl.len too short: %d", ctl.len);
683 + fatal("dlinfoack: response ctl.len too short: %d", ctl.len);
686 if (flags != RS_HIPRI)
687 - rp_fatal("dlinfoack: DL_INFO_ACK was not M_PCPROTO");
688 + fatal("dlinfoack: DL_INFO_ACK was not M_PCPROTO");
690 if (ctl.len < sizeof (dl_info_ack_t)) {
692 - sprintf(buffer, "dlinfoack: short response ctl.len: %d", ctl.len);
694 + fatal("dlinfoack: short response ctl.len: %d", ctl.len);
698 @@ -882,7 +845,7 @@ void dlbindreq(int fd, u_long sap, u_lon
701 if (putmsg(fd, &ctl, (struct strbuf*) NULL, flags) < 0)
702 - fatalSys("dlbindreq: putmsg");
703 + fatal("dlbindreq: putmsg: %m");
706 void dlattachreq(int fd, u_long ppa)
707 @@ -901,7 +864,7 @@ void dlattachreq(int fd, u_long ppa)
710 if (putmsg(fd, &ctl, (struct strbuf*) NULL, flags) < 0)
711 - fatalSys("dlattachreq: putmsg");
712 + fatal("dlattachreq: putmsg: %m");
715 void dlokack(int fd, char *bufp)
716 @@ -921,18 +884,14 @@ void dlokack(int fd, char *bufp)
717 expecting(DL_OK_ACK, dlp);
719 if (ctl.len < sizeof (dl_ok_ack_t)) {
721 - sprintf(buffer, "dlokack: response ctl.len too short: %d", ctl.len);
723 + fatal("dlokack: response ctl.len too short: %d", ctl.len);
726 if (flags != RS_HIPRI)
727 - rp_fatal("dlokack: DL_OK_ACK was not M_PCPROTO");
728 + fatal("dlokack: DL_OK_ACK was not M_PCPROTO");
730 if (ctl.len < sizeof (dl_ok_ack_t)) {
732 - sprintf(buffer, "dlokack: short response ctl.len: %d", ctl.len);
734 + fatal("dlokack: short response ctl.len: %d", ctl.len);
738 @@ -953,12 +912,10 @@ void dlbindack(int fd, char *bufp)
739 expecting(DL_BIND_ACK, dlp);
741 if (flags != RS_HIPRI)
742 - rp_fatal("dlbindack: DL_OK_ACK was not M_PCPROTO");
743 + fatal("dlbindack: DL_OK_ACK was not M_PCPROTO");
745 if (ctl.len < sizeof (dl_bind_ack_t)) {
747 - sprintf(buffer, "dlbindack: short response ctl.len: %d", ctl.len);
749 + fatal("dlbindack: short response ctl.len: %d", ctl.len);
753 @@ -989,8 +946,7 @@ void strgetmsg(int fd, struct strbuf *ct
755 (void) signal(SIGALRM, sigalrm);
756 if (alarm(MAXWAIT) < 0) {
757 - (void) sprintf(errmsg, "%s: alarm", caller);
759 + fatal("%s: alarm", caller);
763 @@ -998,61 +954,48 @@ void strgetmsg(int fd, struct strbuf *ct
766 if ((rc = getmsg(fd, ctlp, datap, flagsp)) < 0) {
767 - (void) sprintf(errmsg, "%s: getmsg", caller);
769 + fatal(errmsg, "%s: getmsg: %m", caller);
776 - (void) sprintf(errmsg, "%s: alarm", caller);
778 + fatal("%s: alarm", caller);
782 * Check for MOREDATA and/or MORECTL.
784 if ((rc & (MORECTL | MOREDATA)) == (MORECTL | MOREDATA)) {
786 - sprintf(buffer, "%s: MORECTL|MOREDATA", caller);
788 + fatal("%s: MORECTL|MOREDATA", caller);
793 - sprintf(buffer, "%s: MORECTL", caller);
795 + fatal("%s: MORECTL", caller);
800 - sprintf(buffer, "%s: MOREDATA", caller);
802 + fatal("%s: MOREDATA", caller);
806 * Check for at least sizeof (long) control data portion.
808 if (ctlp->len < sizeof (long)) {
810 - sprintf(buffer, "getmsg: control portion length < sizeof (long): %d", ctlp->len);
812 + fatal("getmsg: control portion length < sizeof (long): %d", ctlp->len);
816 void sigalrm(int sig)
818 - (void) rp_fatal("sigalrm: TIMEOUT");
819 + fatal("sigalrm: TIMEOUT");
822 void expecting(int prim, union DL_primitives *dlp)
824 if (dlp->dl_primitive != (u_long)prim) {
826 - sprintf(buffer, "expected %s got %s", dlprim(prim), dlprim(dlp->dl_primitive));
829 + fatal("expected %s got %s", dlprim(prim), dlprim(dlp->dl_primitive));
833 --- a/pppd/plugins/rp-pppoe/Makefile.linux
834 +++ b/pppd/plugins/rp-pppoe/Makefile.linux
835 @@ -28,8 +28,8 @@ COPTS=-O2 -g
836 CFLAGS=$(COPTS) -I../../../include/linux
837 all: rp-pppoe.so pppoe-discovery
839 -pppoe-discovery: libplugin.a pppoe-discovery.o
840 - $(CC) -o pppoe-discovery pppoe-discovery.o libplugin.a
841 +pppoe-discovery: pppoe-discovery.o utils.o libplugin.a
842 + $(CC) -o pppoe-discovery pppoe-discovery.o utils.o libplugin.a
844 pppoe-discovery.o: pppoe-discovery.c
845 $(CC) $(CFLAGS) '-DVERSION="$(VERSION)"' -c -o pppoe-discovery.o pppoe-discovery.c
846 --- a/pppd/plugins/rp-pppoe/plugin.c
847 +++ b/pppd/plugins/rp-pppoe/plugin.c
848 @@ -35,7 +35,6 @@ static char const RCSID[] =
849 #include "pppd/pathnames.h"
851 #include <linux/types.h>
853 #include <sys/ioctl.h>
854 #include <sys/types.h>
855 #include <sys/socket.h>
856 @@ -173,10 +172,8 @@ PPPOEConnectDevice(void)
857 (unsigned) conn->peerEth[5]);
859 if (connect(conn->sessionSocket, (struct sockaddr *) &sp,
860 - sizeof(struct sockaddr_pppox)) < 0) {
861 + sizeof(struct sockaddr_pppox)) < 0)
862 fatal("Failed to connect PPPoE socket: %d %m", errno);
866 return conn->sessionSocket;
868 @@ -320,11 +317,9 @@ plugin_init(void)
871 add_options(Options);
873 - info("RP-PPPoE plugin version %s compiled against pppd %s",
874 - RP_VERSION, VERSION);
878 /**********************************************************************
881 @@ -378,6 +373,7 @@ sysErr(char const *str)
887 void pppoe_check_options(void)
889 --- a/pppd/plugins/rp-pppoe/pppoe-discovery.c
890 +++ b/pppd/plugins/rp-pppoe/pppoe-discovery.c
895 -char *xstrdup(const char *s);
898 -void die(int status)
903 int main(int argc, char *argv[])
906 @@ -32,17 +26,17 @@ int main(int argc, char *argv[])
908 conn = malloc(sizeof(PPPoEConnection));
910 - fatalSys("malloc");
913 memset(conn, 0, sizeof(PPPoEConnection));
915 while ((opt = getopt(argc, argv, "I:D:VUAS:C:h")) > 0) {
918 - conn->serviceName = xstrdup(optarg);
919 + conn->serviceName = strDup(optarg);
922 - conn->acName = xstrdup(optarg);
923 + conn->acName = strDup(optarg);
926 conn->useHostUniq = 1;
927 @@ -57,7 +51,7 @@ int main(int argc, char *argv[])
928 fprintf(conn->debugFile, "pppoe-discovery %s\n", VERSION);
931 - conn->ifName = xstrdup(optarg);
932 + conn->ifName = strDup(optarg);
935 /* this is the default */
936 @@ -74,7 +68,7 @@ int main(int argc, char *argv[])
938 /* default interface name */
940 - conn->ifName = strdup("eth0");
941 + conn->ifName = strDup("eth0");
943 conn->discoverySocket = -1;
944 conn->sessionSocket = -1;
945 @@ -84,39 +78,6 @@ int main(int argc, char *argv[])
949 -void rp_fatal(char const *str)
954 - sprintf(buf, "pppoe-discovery: %.256s", str);
958 -void fatalSys(char const *str)
963 - sprintf(buf, "%.256s: %.256s", str, strerror(i));
965 - sprintf(buf, "pppoe-discovery: %.256s: %.256s", str, strerror(i));
969 -void sysErr(char const *str)
974 -char *xstrdup(const char *s)
976 - register char *ret = strdup(s);
984 fprintf(stderr, "Usage: pppoe-discovery [options]\n");
985 --- a/pppd/plugins/rp-pppoe/pppoe.h
986 +++ b/pppd/plugins/rp-pppoe/pppoe.h
987 @@ -307,12 +307,18 @@ void discovery(PPPoEConnection *conn);
988 unsigned char *findTag(PPPoEPacket *packet, UINT16_t tagType,
991 +void dbglog(char *, ...); /* log a debug message */
992 +void info(char *, ...); /* log an informational message */
993 +void warn(char *, ...); /* log a warning message */
994 +void error(char *, ...); /* log an error message */
995 +void fatal(char *, ...); /* log an error message and die(1) */
997 #define SET_STRING(var, val) do { if (var) free(var); var = strDup(val); } while(0);
999 #define CHECK_ROOM(cursor, start, len) \
1001 if (((cursor)-(start))+(len) > MAX_PPPOE_PAYLOAD) { \
1002 - syslog(LOG_ERR, "Would create too-long packet"); \
1003 + error("Would create too-long packet"); \
1008 +++ b/pppd/plugins/rp-pppoe/utils.c
1011 +#include <stdlib.h>
1012 +#include <unistd.h>
1013 +#include <stdarg.h>
1014 +#include <syslog.h>
1016 +void dbglog(const char *fmt, ...)
1020 + va_start(ap, fmt);
1021 + vsyslog(LOG_DEBUG, fmt, ap);
1022 + vfprintf(stderr, fmt, ap);
1023 + fputs("\n", stderr);
1027 +void info(const char *fmt, ...)
1031 + va_start(ap, fmt);
1032 + vsyslog(LOG_INFO, fmt, ap);
1033 + vfprintf(stderr, fmt, ap);
1034 + fputs("\n", stderr);
1038 +void warn(const char *fmt, ...)
1042 + va_start(ap, fmt);
1043 + vsyslog(LOG_WARNING, fmt, ap);
1044 + vfprintf(stderr, fmt, ap);
1045 + fputs("\n", stderr);
1049 +void error(const char *fmt, ...)
1053 + va_start(ap, fmt);
1054 + vsyslog(LOG_ERR, fmt, ap);
1055 + vfprintf(stderr, fmt, ap);
1056 + fputs("\n", stderr);
1060 +void fatal(const char *fmt, ...)
1064 + va_start(ap, fmt);
1065 + vsyslog(LOG_ERR, fmt, ap);
1066 + vfprintf(stderr, fmt, ap);
1067 + fputs("\n", stderr);