[package] ppp: convert dos line endings in 20-atm-modem hotplug handler to unix format
[openwrt.git] / package / ppp / patches / 109-debian_pppoe_cleanup.patch
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[] =
4  
5  #include "pppoe.h"
6  
7 -#ifdef HAVE_SYSLOG_H
8 -#include <syslog.h>
9 -#endif
10 -
11  #include <string.h>
12  #include <errno.h>
13  #include <stdlib.h>
14 @@ -50,17 +46,17 @@ parsePacket(PPPoEPacket *packet, ParseFu
15      UINT16_t tagType, tagLen;
16  
17      if (packet->ver != 1) {
18 -       syslog(LOG_ERR, "Invalid PPPoE version (%d)", (int) packet->ver);
19 +       error("Invalid PPPoE version (%u)", packet->ver);
20         return -1;
21      }
22      if (packet->type != 1) {
23 -       syslog(LOG_ERR, "Invalid PPPoE type (%d)", (int) packet->type);
24 +       error("Invalid PPPoE type (%u)", packet->type);
25         return -1;
26      }
27  
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);
32         return -1;
33      }
34  
35 @@ -76,7 +72,7 @@ parsePacket(PPPoEPacket *packet, ParseFu
36             return 0;
37         }
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);
41             return -1;
42         }
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;
46  
47      if (packet->ver != 1) {
48 -       syslog(LOG_ERR, "Invalid PPPoE version (%d)", (int) packet->ver);
49 +       error("Invalid PPPoE version (%u)", packet->ver);
50         return NULL;
51      }
52      if (packet->type != 1) {
53 -       syslog(LOG_ERR, "Invalid PPPoE type (%d)", (int) packet->type);
54 +       error("Invalid PPPoE type (%u)", packet->type);
55         return NULL;
56      }
57  
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);
62         return NULL;
63      }
64  
65 @@ -131,7 +127,7 @@ findTag(PPPoEPacket *packet, UINT16_t ty
66             return NULL;
67         }
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);
71             return NULL;
72         }
73         if (tagType == type) {
74 @@ -143,6 +139,7 @@ findTag(PPPoEPacket *packet, UINT16_t ty
75      return NULL;
76  }
77  
78 +#ifdef unused
79  /**********************************************************************
80  *%FUNCTION: printErr
81  *%ARGUMENTS:
82 @@ -158,6 +155,7 @@ printErr(char const *str)
83      fprintf(stderr, "pppoe: %s\n", str);
84      syslog(LOG_ERR, "%s", str);
85  }
86 +#endif
87  
88  
89  /**********************************************************************
90 @@ -172,7 +170,7 @@ strDup(char const *str)
91  {
92      char *copy = malloc(strlen(str)+1);
93      if (!copy) {
94 -       rp_fatal("strdup failed");
95 +       fatal("strdup failed");
96      }
97      strcpy(copy, str);
98      return copy;
99 @@ -467,9 +465,10 @@ sendPADT(PPPoEConnection *conn, char con
100         fprintf(conn->debugFile, "\n");
101         fflush(conn->debugFile);
102      }
103 -    syslog(LOG_INFO,"Sent PADT");
104 +    info("Sent PADT");
105  }
106  
107 +#ifdef unused
108  /**********************************************************************
109  *%FUNCTION: parseLogErrs
110  *%ARGUMENTS:
111 @@ -501,4 +500,5 @@ parseLogErrs(UINT16_t type, UINT16_t len
112         break;
113      }
114  }
115 +#endif
116  
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[] =
120  
121  #include "pppoe.h"
122  
123 -#ifdef HAVE_SYSLOG_H
124 -#include <syslog.h>
125 -#endif
126 -
127  #include <string.h>
128  #include <stdlib.h>
129  #include <errno.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);
133         } else {
134 -           syslog(LOG_ERR, "PADO: Service-Name-Error: %.*s", (int) len, data);
135 -           exit(1);
136 +           fatal("PADO: Service-Name-Error: %.*s", (int) len, data);
137         }
138         break;
139      case TAG_AC_SYSTEM_ERROR:
140         if (conn->printACNames) {
141             printf("Got a System-Error tag: %.*s\n", (int) len, data);
142         } else {
143 -           syslog(LOG_ERR, "PADO: System-Error: %.*s", (int) len, data);
144 -           exit(1);
145 +           fatal("PADO: System-Error: %.*s", (int) len, data);
146         }
147         break;
148      case TAG_GENERIC_ERROR:
149         if (conn->printACNames) {
150             printf("Got a Generic-Error tag: %.*s\n", (int) len, data);
151         } else {
152 -           syslog(LOG_ERR, "PADO: Generic-Error: %.*s", (int) len, data);
153 -           exit(1);
154 +           fatal("PADO: Generic-Error: %.*s", (int) len, data);
155         }
156         break;
157      }
158 @@ -209,20 +202,14 @@ parsePADSTags(UINT16_t type, UINT16_t le
159      PPPoEConnection *conn = (PPPoEConnection *) extra;
160      switch(type) {
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);
164         break;
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);
168 -       exit(1);
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);
173 -       exit(1);
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);
178 -       exit(1);
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;
185             }
186             if (r < 0) {
187 -               fatalSys("select (waitForPADO)");
188 +               fatal("waitForPADO: select: %m");
189             }
190             if (r == 0) return;        /* Timed out */
191         }
192 @@ -346,8 +333,7 @@ waitForPADO(PPPoEConnection *conn, int t
193  
194         /* Check length */
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));
199             continue;
200         }
201  
202 @@ -366,16 +352,16 @@ waitForPADO(PPPoEConnection *conn, int t
203  
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");
208                 continue;
209             }
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");
214                 continue;
215             }
216             if (!pc.seenServiceName) {
217 -               printErr("Ignoring PADO packet with no Service-Name tag");
218 +               error("Ignoring PADO packet with no Service-Name tag");
219                 continue;
220             }
221             conn->numPADOs++;
222 @@ -513,7 +499,7 @@ waitForPADS(PPPoEConnection *conn, int t
223                 if (r >= 0 || errno != EINTR) break;
224             }
225             if (r < 0) {
226 -               fatalSys("select (waitForPADS)");
227 +               fatal("waitForPADS: select: %m");
228             }
229             if (r == 0) return;
230         }
231 @@ -523,8 +509,7 @@ waitForPADS(PPPoEConnection *conn, int t
232  
233         /* Check length */
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));
238             continue;
239         }
240  
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;
244  
245 -    syslog(LOG_INFO, "PPP session is %d", (int) ntohs(conn->session));
246 +    info("PPP session is %d", ntohs(conn->session));
247  
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));
253      }
254  }
255  
256 @@ -620,7 +606,7 @@ discovery(PPPoEConnection *conn)
257  
258      /* If we're only printing access concentrator names, we're done */
259      if (conn->printACNames) {
260 -       die(0);
261 +       exit(0);
262      }
263  
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>
269  #endif
270  
271 -#ifdef HAVE_SYSLOG_H
272 -#include <syslog.h>
273 -#endif
274 -
275  #include <errno.h>
276  #include <stdlib.h>
277  #include <string.h>
278 @@ -127,7 +123,7 @@ etherType(PPPoEPacket *packet)
279  {
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);
284      }
285      return type;
286  }
287 @@ -156,7 +152,7 @@ getHWaddr(int sock, char const *ifname, 
288      ifc.ifc_len = sizeof(inbuf);
289      ifc.ifc_buf = inbuf;
290      if (ioctl(sock, SIOCGIFCONF, &ifc) < 0) {
291 -       fatalSys("SIOCGIFCONF");
292 +       fatal("SIOCGIFCONF: %m");
293      }
294      ifr = ifc.ifc_req;
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))) {
299                 if (found) {
300 -                   char buffer[256];
301 -                   sprintf(buffer, "interface %.16s has more than one ethernet address", ifname);
302 -                   rp_fatal(buffer);
303 +                   fatal("interface %s has more than one ethernet address", ifname);
304                 } else {
305                     found = 1;
306                     memcpy(hwaddr, LLADDR(sdl), ETH_ALEN);
307 @@ -183,9 +177,7 @@ getHWaddr(int sock, char const *ifname, 
308         }
309      }
310      if (!found) {
311 -       char buffer[256];
312 -        sprintf(buffer, "interface %.16s has no ethernet address", ifname);
313 -       rp_fatal(buffer);
314 +        fatal("interface %s has no ethernet address", ifname);
315      }
316  }
317  
318 @@ -252,7 +244,7 @@ initFilter(int fd, UINT16_t type, unsign
319        
320        /* Apply the filter */
321        if (ioctl(fd, BIOCSETF, &bpfProgram) < 0) {
322 -       fatalSys("ioctl(BIOCSETF)");
323 +       fatal("ioctl(BIOCSETF): %m");
324        }
325      }
326  }
327 @@ -298,42 +290,36 @@ openInterface(char const *ifname, UINT16
328      if (fd < 0) {
329         switch (errno) {
330         case EACCES:            /* permission denied */
331 -           {
332 -               char buffer[256];
333 -               sprintf(buffer, "Cannot open %.32s -- pppoe must be run as root.", bpfName);
334 -               rp_fatal(buffer);
335 -           }
336 +           fatal("Cannot open %s -- pppoe must be run as root.", bpfName);
337             break;
338         case EBUSY:
339         case ENOENT:            /* no such file */
340             if (i == 0) {
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)");
343             } else {
344 -               rp_fatal("All /dev/bpf* devices are in use");
345 +               fatal("All /dev/bpf* devices are in use");
346             }
347             break;
348         }
349 -       fatalSys(bpfName);
350 +       fatal("%s: %m", bpfName);
351      }
352  
353      if ((sock = socket(AF_LOCAL, SOCK_DGRAM, 0)) < 0) {
354 -       fatalSys("socket");
355 +       fatal("socket: %m");
356      }
357  
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");
363      }
364      if ((ifr.ifr_flags & IFF_UP) == 0) {
365 -       char buffer[256];
366 -       sprintf(buffer, "Interface %.16s is not up\n", ifname);
367 -       rp_fatal(buffer);
368 +       fatal("Interface %s is not up", ifname);
369      }
370  
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.");
375      }
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");
384      }
385      if (ifr.ifr_mtu < ETH_DATA_LEN) {
386 -       char buffer[256];
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);
391 -       printErr(buffer);
392      }
393  #endif
394  
395      /* done with the socket */
396      if (close(sock) < 0) {
397 -       fatalSys("close");
398 +       fatal("close: %m");
399      }
400  
401      /* Check the BPF version number */
402      if (ioctl(fd, BIOCVERSION, &bpf_ver) < 0) {
403 -       fatalSys("ioctl(BIOCVERSION)");
404 +       fatal("ioctl(BIOCVERSION): %m");
405      }
406      if ((bpf_ver.bv_major != BPF_MAJOR_VERSION) ||
407          (bpf_ver.bv_minor < BPF_MINOR_VERSION)) {
408 -       char buffer[256];
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);
413 -       rp_fatal(buffer);
414      }
415  
416      /* allocate a receive packet buffer */
417      if (ioctl(fd, BIOCGBLEN, &bpfLength) < 0) {
418 -       fatalSys("ioctl(BIOCGBLEN)");
419 +       fatal("ioctl(BIOCGBLEN): %m");
420      }
421      if (!(bpfBuffer = (unsigned char *) malloc(bpfLength))) {
422 -       rp_fatal("malloc");
423 +       fatal("malloc");
424      }
425  
426      /* reads should return as soon as there is a packet available */
427      optval = 1;
428      if (ioctl(fd, BIOCIMMEDIATE, &optval) < 0) {
429 -       fatalSys("ioctl(BIOCIMMEDIATE)");
430 +       fatal("ioctl(BIOCIMMEDIATE): %m");
431      }
432  
433      /* Bind the interface to the filter */
434      strncpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
435      if (ioctl(fd, BIOCSETIF, &ifr) < 0) {
436 -       char buffer[256];
437 -       sprintf(buffer, "ioctl(BIOCSETIF) can't select interface %.16s",
438 -               ifname);
439 -       rp_fatal(buffer);
440 +       fatal("ioctl(BIOCSETIF) can't select interface %s: %m", ifname);
441      }
442  
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",
445            ifname, 
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.");
454         }
455 -       fatalSys("socket");
456 +       fatal("cannot create the raw socket: %m");
457      }
458  
459      if (setsockopt(fd, SOL_SOCKET, SO_BROADCAST, &optval, sizeof(optval)) < 0) {
460 -       fatalSys("setsockopt");
461 +       fatal("setsockopt(SOL_SOCKET, SO_BROADCAST): %m");
462      }
463  
464      /* Fill in hardware address */
465      if (hwaddr) {
466         strncpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
467 -       if (ioctl(fd, SIOCGIFHWADDR, &ifr) < 0) {
468 -           fatalSys("ioctl(SIOCGIFHWADDR)");
469 -       }
470 +       if (ioctl(fd, SIOCGIFHWADDR, &ifr) < 0)
471 +           fatal("ioctl(SIOCGIFHWADDR): %m");
472         memcpy(hwaddr, ifr.ifr_hwaddr.sa_data, ETH_ALEN);
473  #ifdef ARPHRD_ETHER
474         if (ifr.ifr_hwaddr.sa_family != ARPHRD_ETHER) {
475 -           char buffer[256];
476 -           sprintf(buffer, "Interface %.16s is not Ethernet", ifname);
477 -           rp_fatal(buffer);
478 +           fatal("Interface %s is not Ethernet", ifname);
479         }
480  #endif
481         if (NOT_UNICAST(hwaddr)) {
482 -           char buffer[256];
483 -           sprintf(buffer,
484 -                   "Interface %.16s has broadcast/multicast MAC address??",
485 +           fatal("Interface %s has broadcast/multicast MAC address",
486                     ifname);
487 -           rp_fatal(buffer);
488         }
489      }
490  
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");
496      }
497      if (ifr.ifr_mtu < ETH_DATA_LEN) {
498 -       char buffer[256];
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);
503 -       printErr(buffer);
504      }
505  
506  #ifdef HAVE_STRUCT_SOCKADDR_LL
507 @@ -493,7 +466,7 @@ openInterface(char const *ifname, UINT16
508  
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");
513      }
514      sa.sll_ifindex = ifr.ifr_ifindex;
515  
516 @@ -503,7 +476,7 @@ openInterface(char const *ifname, UINT16
517  
518      /* We're only interested in packets on specified interface */
519      if (bind(fd, (struct sockaddr *) &sa, sizeof(sa)) < 0) {
520 -       fatalSys("bind");
521 +       fatal("bind: %m");
522      }
523  
524      return fd;
525 @@ -527,13 +500,11 @@ sendPacket(PPPoEConnection *conn, int so
526  {
527  #if defined(USE_BPF)
528      if (write(sock, pkt, size) < 0) {
529 -       sysErr("write (sendPacket)");
530 -       return -1;
531 +       fatal("sendPacket: write: %m");
532      }
533  #elif defined(HAVE_STRUCT_SOCKADDR_LL)
534      if (send(sock, pkt, size, 0) < 0) {
535 -       sysErr("send (sendPacket)");
536 -       return -1;
537 +       fatal("sendPacket: send: %m");
538      }
539  #else
540  #ifdef USE_DLPI
541 @@ -577,12 +548,11 @@ sendPacket(PPPoEConnection *conn, int so
542      struct sockaddr sa;
543  
544      if (!conn) {
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");
547      }
548      strcpy(sa.sa_data, conn->ifName);
549      if (sendto(sock, pkt, size, 0, &sa, sizeof(sa)) < 0) {
550 -       sysErr("sendto (sendPacket)");
551 -       return -1;
552 +       fatal("sendPacket: sendto: %m");
553      }
554  #endif
555  #endif
556 @@ -632,26 +602,24 @@ receivePacket(int sock, PPPoEPacket *pkt
557      if (bpfSize <= 0) {
558         bpfOffset = 0;
559         if ((bpfSize = read(sock, bpfBuffer, bpfLength)) < 0) {
560 -           sysErr("read (receivePacket)");
561 -           return -1;
562 +           fatal("receivePacket: read: %m");
563         }
564      }
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 */
569         return 0;
570      }
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 */
577         return 0;
578      }
579      seglen = hdr.bh_hdrlen + hdr.bh_caplen;
580      if (seglen > bpfSize) {
581 -       syslog(LOG_ERR, "Truncated bpf packet: seglen=%d, bpfSize=%d",
582 -              seglen, bpfSize);
583 +       error("Truncated bpf packet: seglen=%d, bpfSize=%d", seglen, bpfSize);
584         clearPacketHeader(pkt);         /* resets bpfSize and bpfOffset */
585         return 0;
586      }
587 @@ -676,16 +644,14 @@ receivePacket(int sock, PPPoEPacket *pkt
588         data.len = 0; 
589         
590         if ((retval = getmsg(sock, NULL, &data, &flags)) < 0) {
591 -           sysErr("read (receivePacket)");
592 -           return -1;
593 +           fatal("receivePacket: getmsg: %m");
594         }
595  
596         *size = data.len; 
597  
598  #else
599      if ((*size = recv(sock, pkt, sizeof(PPPoEPacket), 0)) < 0) {
600 -       sysErr("recv (receivePacket)");
601 -       return -1;
602 +       fatal("receivePacket: recv: %m");
603      }
604  #endif
605  #endif
606 @@ -716,7 +682,7 @@ openInterface(char const *ifname, UINT16
607      int ppa; 
608  
609      if(strlen(ifname) > PATH_MAX) {
610 -       rp_fatal("socket: string to long"); 
611 +       fatal("openInterface: interface name too long");
612      }
613  
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.");
621         }
622 -       fatalSys("socket");
623 +       fatal("open(%s): %m", base_dev);
624      }
625  
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;
634  
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);
637  
638      if ( strioctl(fd, DLIOCRAW, -1, 0, NULL) < 0 ) { 
639 -       fatalSys("DLIOCRAW"); 
640 +       fatal("DLIOCRAW: %m");
641      }
642  
643 -    if (ioctl(fd, I_FLUSH, FLUSHR) < 0) fatalSys("I_FLUSH");
644 +    if (ioctl(fd, I_FLUSH, FLUSHR) < 0)
645 +       fatal("I_FLUSH: %m");
646  
647      return fd;
648  }
649 @@ -780,7 +747,7 @@ void dlpromisconreq(int fd, u_long level
650          flags = 0;
651  
652          if (putmsg(fd, &ctl, (struct strbuf*) NULL, flags) < 0)
653 -                fatalSys("dlpromiscon:  putmsg");
654 +                fatal("dlpromiscon: putmsg: %m");
655  
656  }
657  
658 @@ -799,7 +766,7 @@ void dlinforeq(int fd)
659          flags = RS_HIPRI;
660  
661          if (putmsg(fd, &ctl, (struct strbuf*) NULL, flags) < 0)
662 -                fatalSys("dlinforeq:  putmsg");
663 +                fatal("dlinforeq: putmsg: %m");
664  }
665  
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;
669  
670          if (putmsg(fd, &ctl, &data, 0) < 0)
671 -                fatalSys("dlunitdatareq:  putmsg");
672 +                fatal("dlunitdatareq: putmsg: %m");
673  }
674  
675  void dlinfoack(int fd, char *bufp)
676 @@ -847,18 +814,14 @@ void dlinfoack(int fd, char *bufp)
677          expecting(DL_INFO_ACK, dlp);
678  
679          if (ctl.len < sizeof (dl_info_ack_t)) {
680 -               char buffer[256];
681 -               sprintf(buffer, "dlinfoack:  response ctl.len too short:  %d", ctl.len); 
682 -                rp_fatal(buffer); 
683 +               fatal("dlinfoack: response ctl.len too short: %d", ctl.len);
684         }
685  
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");
689  
690          if (ctl.len < sizeof (dl_info_ack_t)) {
691 -               char buffer[256];
692 -               sprintf(buffer, "dlinfoack:  short response ctl.len:  %d", ctl.len); 
693 -               rp_fatal(buffer); 
694 +               fatal("dlinfoack: short response ctl.len: %d", ctl.len);
695         }
696  }
697  
698 @@ -882,7 +845,7 @@ void dlbindreq(int fd, u_long sap, u_lon
699          flags = 0;
700  
701          if (putmsg(fd, &ctl, (struct strbuf*) NULL, flags) < 0)
702 -                fatalSys("dlbindreq:  putmsg");
703 +                fatal("dlbindreq: putmsg: %m");
704  }
705  
706  void dlattachreq(int fd, u_long ppa)
707 @@ -901,7 +864,7 @@ void dlattachreq(int fd, u_long ppa)
708          flags = 0;
709  
710          if (putmsg(fd, &ctl, (struct strbuf*) NULL, flags) < 0)
711 -                fatalSys("dlattachreq:  putmsg");
712 +                fatal("dlattachreq: putmsg: %m");
713  }
714  
715  void dlokack(int fd, char *bufp)
716 @@ -921,18 +884,14 @@ void dlokack(int fd, char *bufp)
717          expecting(DL_OK_ACK, dlp);
718  
719          if (ctl.len < sizeof (dl_ok_ack_t)) { 
720 -               char buffer[256];
721 -               sprintf(buffer, "dlokack:  response ctl.len too short:  %d", ctl.len);
722 -               rp_fatal(buffer); 
723 +               fatal("dlokack: response ctl.len too short: %d", ctl.len);
724         }
725  
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");
729  
730          if (ctl.len < sizeof (dl_ok_ack_t)) {
731 -               char buffer[256]; 
732 -               sprintf(buffer, "dlokack:  short response ctl.len:  %d", ctl.len);
733 -               rp_fatal(buffer); 
734 +               fatal("dlokack: short response ctl.len: %d", ctl.len);
735         }
736  }
737  
738 @@ -953,12 +912,10 @@ void dlbindack(int fd, char *bufp)
739          expecting(DL_BIND_ACK, dlp);
740  
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");
744  
745          if (ctl.len < sizeof (dl_bind_ack_t)) {
746 -               char buffer[256];
747 -               sprintf(buffer, "dlbindack:  short response ctl.len:  %d", ctl.len);
748 -               rp_fatal(buffer); 
749 +               fatal("dlbindack: short response ctl.len: %d", ctl.len);
750         }
751  }
752  
753 @@ -989,8 +946,7 @@ void strgetmsg(int fd, struct strbuf *ct
754           */
755          (void) signal(SIGALRM, sigalrm);
756          if (alarm(MAXWAIT) < 0) {
757 -                (void) sprintf(errmsg, "%s:  alarm", caller);
758 -                fatalSys(errmsg);
759 +                fatal("%s: alarm", caller);
760          }
761  
762          /*
763 @@ -998,61 +954,48 @@ void strgetmsg(int fd, struct strbuf *ct
764           */
765          *flagsp = 0;
766          if ((rc = getmsg(fd, ctlp, datap, flagsp)) < 0) {
767 -                (void) sprintf(errmsg, "%s:  getmsg", caller);
768 -                fatalSys(errmsg);
769 +                fatal(errmsg, "%s: getmsg: %m", caller);
770          }
771  
772          /*
773           * Stop timer.
774           */
775          if (alarm(0) < 0) {
776 -                (void) sprintf(errmsg, "%s:  alarm", caller);
777 -                fatalSys(errmsg);
778 +                fatal("%s: alarm", caller);
779          }
780  
781          /*
782           * Check for MOREDATA and/or MORECTL.
783           */
784          if ((rc & (MORECTL | MOREDATA)) == (MORECTL | MOREDATA)) {
785 -               char buffer[256]; 
786 -               sprintf(buffer, "%s:  MORECTL|MOREDATA", caller);
787 -               rp_fatal(buffer);
788 +               fatal("%s: MORECTL|MOREDATA", caller);
789         }
790                  
791          if (rc & MORECTL) {
792 -               char buffer[256];
793 -               sprintf(buffer, "%s:  MORECTL", caller);
794 -               rp_fatal(buffer); 
795 +               fatal("%s: MORECTL", caller);
796         }
797          
798          if (rc & MOREDATA) {
799 -               char buffer[256]; 
800 -               sprintf(buffer, "%s:  MOREDATA", caller);
801 -               rp_fatal(buffer);
802 +               fatal("%s: MOREDATA", caller);
803         }
804  
805          /*
806           * Check for at least sizeof (long) control data portion.
807           */
808          if (ctlp->len < sizeof (long)) {
809 -               char buffer[256]; 
810 -               sprintf(buffer, "getmsg:  control portion length < sizeof (long):  %d", ctlp->len);
811 -               rp_fatal(buffer); 
812 +               fatal("getmsg: control portion length < sizeof (long): %d", ctlp->len);
813         }
814  }
815  
816  void sigalrm(int sig)
817  {
818 -        (void) rp_fatal("sigalrm:  TIMEOUT");
819 +        fatal("sigalrm: TIMEOUT");
820  }
821  
822  void expecting(int prim, union DL_primitives *dlp)
823  {
824          if (dlp->dl_primitive != (u_long)prim) {
825 -               char buffer[256]; 
826 -               sprintf(buffer, "expected %s got %s", dlprim(prim), dlprim(dlp->dl_primitive));
827 -               rp_fatal(buffer); 
828 -               exit(1); 
829 +               fatal("expected %s got %s", dlprim(prim), dlprim(dlp->dl_primitive));
830         }
831  }
832  
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
838  
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
843  
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"
850  
851  #include <linux/types.h>
852 -#include <syslog.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]);
858  
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);
863 -       return -1;
864 -    }
865  
866      return conn->sessionSocket;
867  }
868 @@ -320,11 +317,9 @@ plugin_init(void)
869      }
870  
871      add_options(Options);
872 -
873 -    info("RP-PPPoE plugin version %s compiled against pppd %s",
874 -        RP_VERSION, VERSION);
875  }
876  
877 +#ifdef unused
878  /**********************************************************************
879  *%FUNCTION: fatalSys
880  *%ARGUMENTS:
881 @@ -378,6 +373,7 @@ sysErr(char const *str)
882  {
883      rp_fatal(str);
884  }
885 +#endif
886  
887  void pppoe_check_options(void)
888  {
889 --- a/pppd/plugins/rp-pppoe/pppoe-discovery.c
890 +++ b/pppd/plugins/rp-pppoe/pppoe-discovery.c
891 @@ -17,14 +17,8 @@
892  
893  #include "pppoe.h"
894  
895 -char *xstrdup(const char *s);
896  void usage(void);
897  
898 -void die(int status)
899 -{
900 -       exit(status);
901 -}
902 -
903  int main(int argc, char *argv[])
904  {
905      int opt;
906 @@ -32,17 +26,17 @@ int main(int argc, char *argv[])
907  
908      conn = malloc(sizeof(PPPoEConnection));
909      if (!conn)
910 -       fatalSys("malloc");
911 +       fatal("malloc");
912  
913      memset(conn, 0, sizeof(PPPoEConnection));
914  
915      while ((opt = getopt(argc, argv, "I:D:VUAS:C:h")) > 0) {
916         switch(opt) {
917         case 'S':
918 -           conn->serviceName = xstrdup(optarg);
919 +           conn->serviceName = strDup(optarg);
920             break;
921         case 'C':
922 -           conn->acName = xstrdup(optarg);
923 +           conn->acName = strDup(optarg);
924             break;
925         case 'U':
926             conn->useHostUniq = 1;
927 @@ -57,7 +51,7 @@ int main(int argc, char *argv[])
928             fprintf(conn->debugFile, "pppoe-discovery %s\n", VERSION);
929             break;
930         case 'I':
931 -           conn->ifName = xstrdup(optarg);
932 +           conn->ifName = strDup(optarg);
933             break;
934         case 'A':
935             /* this is the default */
936 @@ -74,7 +68,7 @@ int main(int argc, char *argv[])
937  
938      /* default interface name */
939      if (!conn->ifName)
940 -       conn->ifName = strdup("eth0");
941 +       conn->ifName = strDup("eth0");
942  
943      conn->discoverySocket = -1;
944      conn->sessionSocket = -1;
945 @@ -84,39 +78,6 @@ int main(int argc, char *argv[])
946      exit(0);
947  }
948  
949 -void rp_fatal(char const *str)
950 -{
951 -    char buf[1024];
952 -
953 -    printErr(str);
954 -    sprintf(buf, "pppoe-discovery: %.256s", str);
955 -    exit(1);
956 -}
957 -
958 -void fatalSys(char const *str)
959 -{
960 -    char buf[1024];
961 -    int i = errno;
962 -
963 -    sprintf(buf, "%.256s: %.256s", str, strerror(i));
964 -    printErr(buf);
965 -    sprintf(buf, "pppoe-discovery: %.256s: %.256s", str, strerror(i));
966 -    exit(1);
967 -}
968 -
969 -void sysErr(char const *str)
970 -{
971 -    rp_fatal(str);
972 -}
973 -
974 -char *xstrdup(const char *s)
975 -{
976 -    register char *ret = strdup(s);
977 -    if (!ret)
978 -       sysErr("strdup");
979 -    return ret;
980 -}
981 -
982  void usage(void)
983  {
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,
989                        PPPoETag *tag);
990  
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) */
996 +
997  #define SET_STRING(var, val) do { if (var) free(var); var = strDup(val); } while(0);
998  
999  #define CHECK_ROOM(cursor, start, len) \
1000  do {\
1001      if (((cursor)-(start))+(len) > MAX_PPPOE_PAYLOAD) { \
1002 -        syslog(LOG_ERR, "Would create too-long packet"); \
1003 +        error("Would create too-long packet"); \
1004          return; \
1005      } \
1006  } while(0)
1007 --- /dev/null
1008 +++ b/pppd/plugins/rp-pppoe/utils.c
1009 @@ -0,0 +1,62 @@
1010 +#include <stdio.h>
1011 +#include <stdlib.h>
1012 +#include <unistd.h>
1013 +#include <stdarg.h>
1014 +#include <syslog.h>
1015 +
1016 +void dbglog(const char *fmt, ...)
1017 +{
1018 +    va_list ap;
1019 +
1020 +    va_start(ap, fmt);
1021 +    vsyslog(LOG_DEBUG, fmt, ap);
1022 +    vfprintf(stderr, fmt, ap);
1023 +    fputs("\n", stderr);
1024 +    va_end(ap);
1025 +}
1026 +
1027 +void info(const char *fmt, ...)
1028 +{
1029 +    va_list ap;
1030 +
1031 +    va_start(ap, fmt);
1032 +    vsyslog(LOG_INFO, fmt, ap);
1033 +    vfprintf(stderr, fmt, ap);
1034 +    fputs("\n", stderr);
1035 +    va_end(ap);
1036 +}
1037 +
1038 +void warn(const char *fmt, ...)
1039 +{
1040 +    va_list ap;
1041 +
1042 +    va_start(ap, fmt);
1043 +    vsyslog(LOG_WARNING, fmt, ap);
1044 +    vfprintf(stderr, fmt, ap);
1045 +    fputs("\n", stderr);
1046 +    va_end(ap);
1047 +}
1048 +
1049 +void error(const char *fmt, ...)
1050 +{
1051 +    va_list ap;
1052 +
1053 +    va_start(ap, fmt);
1054 +    vsyslog(LOG_ERR, fmt, ap);
1055 +    vfprintf(stderr, fmt, ap);
1056 +    fputs("\n", stderr);
1057 +    va_end(ap);
1058 +}
1059 +
1060 +void fatal(const char *fmt, ...)
1061 +{
1062 +    va_list ap;
1063 +
1064 +    va_start(ap, fmt);
1065 +    vsyslog(LOG_ERR, fmt, ap);
1066 +    vfprintf(stderr, fmt, ap);
1067 +    fputs("\n", stderr);
1068 +    va_end(ap);
1069 +    exit(1);
1070 +}
1071 +