9fb0ebe71ee499610f7e0c177ff5e37f8bb541f0
[openwrt/openwrt.git] / package / ppp / patches / 109-debian_pppoe_cleanup.patch
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
4 @@ -18,10 +18,6 @@
5
6 #include "pppoe.h"
7
8 -#ifdef HAVE_SYSLOG_H
9 -#include <syslog.h>
10 -#endif
11 -
12 #include <string.h>
13 #include <errno.h>
14 #include <stdlib.h>
15 @@ -50,17 +46,17 @@
16 UINT16_t tagType, tagLen;
17
18 if (packet->ver != 1) {
19 - syslog(LOG_ERR, "Invalid PPPoE version (%d)", (int) packet->ver);
20 + error("Invalid PPPoE version (%u)", packet->ver);
21 return -1;
22 }
23 if (packet->type != 1) {
24 - syslog(LOG_ERR, "Invalid PPPoE type (%d)", (int) packet->type);
25 + error("Invalid PPPoE type (%u)", packet->type);
26 return -1;
27 }
28
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);
33 return -1;
34 }
35
36 @@ -76,7 +72,7 @@
37 return 0;
38 }
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);
42 return -1;
43 }
44 func(tagType, tagLen, curTag+TAG_HDR_SIZE, extra);
45 @@ -105,17 +101,17 @@
46 UINT16_t tagType, tagLen;
47
48 if (packet->ver != 1) {
49 - syslog(LOG_ERR, "Invalid PPPoE version (%d)", (int) packet->ver);
50 + error("Invalid PPPoE version (%u)", packet->ver);
51 return NULL;
52 }
53 if (packet->type != 1) {
54 - syslog(LOG_ERR, "Invalid PPPoE type (%d)", (int) packet->type);
55 + error("Invalid PPPoE type (%u)", packet->type);
56 return NULL;
57 }
58
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);
63 return NULL;
64 }
65
66 @@ -131,7 +127,7 @@
67 return NULL;
68 }
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);
72 return NULL;
73 }
74 if (tagType == type) {
75 @@ -143,6 +139,7 @@
76 return NULL;
77 }
78
79 +#ifdef unused
80 /**********************************************************************
81 *%FUNCTION: printErr
82 *%ARGUMENTS:
83 @@ -158,6 +155,7 @@
84 fprintf(stderr, "pppoe: %s\n", str);
85 syslog(LOG_ERR, "%s", str);
86 }
87 +#endif
88
89
90 /**********************************************************************
91 @@ -172,7 +170,7 @@
92 {
93 char *copy = malloc(strlen(str)+1);
94 if (!copy) {
95 - rp_fatal("strdup failed");
96 + fatal("strdup failed");
97 }
98 strcpy(copy, str);
99 return copy;
100 @@ -467,9 +465,10 @@
101 fprintf(conn->debugFile, "\n");
102 fflush(conn->debugFile);
103 }
104 - syslog(LOG_INFO,"Sent PADT");
105 + info("Sent PADT");
106 }
107
108 +#ifdef unused
109 /**********************************************************************
110 *%FUNCTION: parseLogErrs
111 *%ARGUMENTS:
112 @@ -501,4 +500,5 @@
113 break;
114 }
115 }
116 +#endif
117
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
121 @@ -13,10 +13,6 @@
122
123 #include "pppoe.h"
124
125 -#ifdef HAVE_SYSLOG_H
126 -#include <syslog.h>
127 -#endif
128 -
129 #include <string.h>
130 #include <stdlib.h>
131 #include <errno.h>
132 @@ -167,24 +163,21 @@
133 if (conn->printACNames) {
134 printf("Got a Service-Name-Error tag: %.*s\n", (int) len, data);
135 } else {
136 - syslog(LOG_ERR, "PADO: Service-Name-Error: %.*s", (int) len, data);
137 - exit(1);
138 + fatal("PADO: Service-Name-Error: %.*s", (int) len, data);
139 }
140 break;
141 case TAG_AC_SYSTEM_ERROR:
142 if (conn->printACNames) {
143 printf("Got a System-Error tag: %.*s\n", (int) len, data);
144 } else {
145 - syslog(LOG_ERR, "PADO: System-Error: %.*s", (int) len, data);
146 - exit(1);
147 + fatal("PADO: System-Error: %.*s", (int) len, data);
148 }
149 break;
150 case TAG_GENERIC_ERROR:
151 if (conn->printACNames) {
152 printf("Got a Generic-Error tag: %.*s\n", (int) len, data);
153 } else {
154 - syslog(LOG_ERR, "PADO: Generic-Error: %.*s", (int) len, data);
155 - exit(1);
156 + fatal("PADO: Generic-Error: %.*s", (int) len, data);
157 }
158 break;
159 }
160 @@ -209,20 +202,14 @@
161 PPPoEConnection *conn = (PPPoEConnection *) extra;
162 switch(type) {
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);
166 break;
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);
170 - exit(1);
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);
175 - exit(1);
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);
180 - exit(1);
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);
185 @@ -336,7 +323,7 @@
186 if (r >= 0 || errno != EINTR) break;
187 }
188 if (r < 0) {
189 - fatalSys("select (waitForPADO)");
190 + fatal("waitForPADO: select: %m");
191 }
192 if (r == 0) return; /* Timed out */
193 }
194 @@ -346,8 +333,7 @@
195
196 /* Check length */
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));
201 continue;
202 }
203
204 @@ -366,16 +352,16 @@
205
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");
210 continue;
211 }
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");
216 continue;
217 }
218 if (!pc.seenServiceName) {
219 - printErr("Ignoring PADO packet with no Service-Name tag");
220 + error("Ignoring PADO packet with no Service-Name tag");
221 continue;
222 }
223 conn->numPADOs++;
224 @@ -513,7 +499,7 @@
225 if (r >= 0 || errno != EINTR) break;
226 }
227 if (r < 0) {
228 - fatalSys("select (waitForPADS)");
229 + fatal("waitForPADS: select: %m");
230 }
231 if (r == 0) return;
232 }
233 @@ -523,8 +509,7 @@
234
235 /* Check length */
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));
240 continue;
241 }
242
243 @@ -556,11 +541,12 @@
244 /* Don't bother with ntohs; we'll just end up converting it back... */
245 conn->session = packet.session;
246
247 - syslog(LOG_INFO, "PPP session is %d", (int) ntohs(conn->session));
248 + info("PPP session is %d", ntohs(conn->session));
249
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));
255 }
256 }
257
258 @@ -620,7 +606,7 @@
259
260 /* If we're only printing access concentrator names, we're done */
261 if (conn->printACNames) {
262 - die(0);
263 + exit(0);
264 }
265
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
270 @@ -40,10 +40,6 @@
271 #include <sys/ioctl.h>
272 #endif
273
274 -#ifdef HAVE_SYSLOG_H
275 -#include <syslog.h>
276 -#endif
277 -
278 #include <errno.h>
279 #include <stdlib.h>
280 #include <string.h>
281 @@ -127,7 +123,7 @@
282 {
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);
287 }
288 return type;
289 }
290 @@ -156,7 +152,7 @@
291 ifc.ifc_len = sizeof(inbuf);
292 ifc.ifc_buf = inbuf;
293 if (ioctl(sock, SIOCGIFCONF, &ifc) < 0) {
294 - fatalSys("SIOCGIFCONF");
295 + fatal("SIOCGIFCONF: %m");
296 }
297 ifr = ifc.ifc_req;
298 ifreq.ifr_name[0] = '\0';
299 @@ -172,9 +168,7 @@
300 (sdl->sdl_alen == ETH_ALEN) &&
301 !strncmp(ifname, ifr->ifr_name, sizeof(ifr->ifr_name))) {
302 if (found) {
303 - char buffer[256];
304 - sprintf(buffer, "interface %.16s has more than one ethernet address", ifname);
305 - rp_fatal(buffer);
306 + fatal("interface %s has more than one ethernet address", ifname);
307 } else {
308 found = 1;
309 memcpy(hwaddr, LLADDR(sdl), ETH_ALEN);
310 @@ -183,9 +177,7 @@
311 }
312 }
313 if (!found) {
314 - char buffer[256];
315 - sprintf(buffer, "interface %.16s has no ethernet address", ifname);
316 - rp_fatal(buffer);
317 + fatal("interface %s has no ethernet address", ifname);
318 }
319 }
320
321 @@ -252,7 +244,7 @@
322
323 /* Apply the filter */
324 if (ioctl(fd, BIOCSETF, &bpfProgram) < 0) {
325 - fatalSys("ioctl(BIOCSETF)");
326 + fatal("ioctl(BIOCSETF): %m");
327 }
328 }
329 }
330 @@ -298,42 +290,36 @@
331 if (fd < 0) {
332 switch (errno) {
333 case EACCES: /* permission denied */
334 - {
335 - char buffer[256];
336 - sprintf(buffer, "Cannot open %.32s -- pppoe must be run as root.", bpfName);
337 - rp_fatal(buffer);
338 - }
339 + fatal("Cannot open %s -- pppoe must be run as root.", bpfName);
340 break;
341 case EBUSY:
342 case ENOENT: /* no such file */
343 if (i == 0) {
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)");
346 } else {
347 - rp_fatal("All /dev/bpf* devices are in use");
348 + fatal("All /dev/bpf* devices are in use");
349 }
350 break;
351 }
352 - fatalSys(bpfName);
353 + fatal("%s: %m", bpfName);
354 }
355
356 if ((sock = socket(AF_LOCAL, SOCK_DGRAM, 0)) < 0) {
357 - fatalSys("socket");
358 + fatal("socket: %m");
359 }
360
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");
366 }
367 if ((ifr.ifr_flags & IFF_UP) == 0) {
368 - char buffer[256];
369 - sprintf(buffer, "Interface %.16s is not up\n", ifname);
370 - rp_fatal(buffer);
371 + fatal("Interface %s is not up", ifname);
372 }
373
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.");
378 }
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");
387 }
388 if (ifr.ifr_mtu < ETH_DATA_LEN) {
389 - char buffer[256];
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);
394 - printErr(buffer);
395 }
396 #endif
397
398 /* done with the socket */
399 if (close(sock) < 0) {
400 - fatalSys("close");
401 + fatal("close: %m");
402 }
403
404 /* Check the BPF version number */
405 if (ioctl(fd, BIOCVERSION, &bpf_ver) < 0) {
406 - fatalSys("ioctl(BIOCVERSION)");
407 + fatal("ioctl(BIOCVERSION): %m");
408 }
409 if ((bpf_ver.bv_major != BPF_MAJOR_VERSION) ||
410 (bpf_ver.bv_minor < BPF_MINOR_VERSION)) {
411 - char buffer[256];
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);
416 - rp_fatal(buffer);
417 }
418
419 /* allocate a receive packet buffer */
420 if (ioctl(fd, BIOCGBLEN, &bpfLength) < 0) {
421 - fatalSys("ioctl(BIOCGBLEN)");
422 + fatal("ioctl(BIOCGBLEN): %m");
423 }
424 if (!(bpfBuffer = (unsigned char *) malloc(bpfLength))) {
425 - rp_fatal("malloc");
426 + fatal("malloc");
427 }
428
429 /* reads should return as soon as there is a packet available */
430 optval = 1;
431 if (ioctl(fd, BIOCIMMEDIATE, &optval) < 0) {
432 - fatalSys("ioctl(BIOCIMMEDIATE)");
433 + fatal("ioctl(BIOCIMMEDIATE): %m");
434 }
435
436 /* Bind the interface to the filter */
437 strncpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
438 if (ioctl(fd, BIOCSETIF, &ifr) < 0) {
439 - char buffer[256];
440 - sprintf(buffer, "ioctl(BIOCSETIF) can't select interface %.16s",
441 - ifname);
442 - rp_fatal(buffer);
443 + fatal("ioctl(BIOCSETIF) can't select interface %s: %m", ifname);
444 }
445
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",
448 ifname,
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.");
457 }
458 - fatalSys("socket");
459 + fatal("cannot create the raw socket: %m");
460 }
461
462 if (setsockopt(fd, SOL_SOCKET, SO_BROADCAST, &optval, sizeof(optval)) < 0) {
463 - fatalSys("setsockopt");
464 + fatal("setsockopt(SOL_SOCKET, SO_BROADCAST): %m");
465 }
466
467 /* Fill in hardware address */
468 if (hwaddr) {
469 strncpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
470 - if (ioctl(fd, SIOCGIFHWADDR, &ifr) < 0) {
471 - fatalSys("ioctl(SIOCGIFHWADDR)");
472 - }
473 + if (ioctl(fd, SIOCGIFHWADDR, &ifr) < 0)
474 + fatal("ioctl(SIOCGIFHWADDR): %m");
475 memcpy(hwaddr, ifr.ifr_hwaddr.sa_data, ETH_ALEN);
476 #ifdef ARPHRD_ETHER
477 if (ifr.ifr_hwaddr.sa_family != ARPHRD_ETHER) {
478 - char buffer[256];
479 - sprintf(buffer, "Interface %.16s is not Ethernet", ifname);
480 - rp_fatal(buffer);
481 + fatal("Interface %s is not Ethernet", ifname);
482 }
483 #endif
484 if (NOT_UNICAST(hwaddr)) {
485 - char buffer[256];
486 - sprintf(buffer,
487 - "Interface %.16s has broadcast/multicast MAC address??",
488 + fatal("Interface %s has broadcast/multicast MAC address",
489 ifname);
490 - rp_fatal(buffer);
491 }
492 }
493
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");
499 }
500 if (ifr.ifr_mtu < ETH_DATA_LEN) {
501 - char buffer[256];
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);
506 - printErr(buffer);
507 }
508
509 #ifdef HAVE_STRUCT_SOCKADDR_LL
510 @@ -493,7 +466,7 @@
511
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");
516 }
517 sa.sll_ifindex = ifr.ifr_ifindex;
518
519 @@ -503,7 +476,7 @@
520
521 /* We're only interested in packets on specified interface */
522 if (bind(fd, (struct sockaddr *) &sa, sizeof(sa)) < 0) {
523 - fatalSys("bind");
524 + fatal("bind: %m");
525 }
526
527 return fd;
528 @@ -527,13 +500,11 @@
529 {
530 #if defined(USE_BPF)
531 if (write(sock, pkt, size) < 0) {
532 - sysErr("write (sendPacket)");
533 - return -1;
534 + fatal("sendPacket: write: %m");
535 }
536 #elif defined(HAVE_STRUCT_SOCKADDR_LL)
537 if (send(sock, pkt, size, 0) < 0) {
538 - sysErr("send (sendPacket)");
539 - return -1;
540 + fatal("sendPacket: send: %m");
541 }
542 #else
543 #ifdef USE_DLPI
544 @@ -577,12 +548,11 @@
545 struct sockaddr sa;
546
547 if (!conn) {
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");
550 }
551 strcpy(sa.sa_data, conn->ifName);
552 if (sendto(sock, pkt, size, 0, &sa, sizeof(sa)) < 0) {
553 - sysErr("sendto (sendPacket)");
554 - return -1;
555 + fatal("sendPacket: sendto: %m");
556 }
557 #endif
558 #endif
559 @@ -632,26 +602,24 @@
560 if (bpfSize <= 0) {
561 bpfOffset = 0;
562 if ((bpfSize = read(sock, bpfBuffer, bpfLength)) < 0) {
563 - sysErr("read (receivePacket)");
564 - return -1;
565 + fatal("receivePacket: read: %m");
566 }
567 }
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 */
572 return 0;
573 }
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 */
580 return 0;
581 }
582 seglen = hdr.bh_hdrlen + hdr.bh_caplen;
583 if (seglen > bpfSize) {
584 - syslog(LOG_ERR, "Truncated bpf packet: seglen=%d, bpfSize=%d",
585 - seglen, bpfSize);
586 + error("Truncated bpf packet: seglen=%d, bpfSize=%d", seglen, bpfSize);
587 clearPacketHeader(pkt); /* resets bpfSize and bpfOffset */
588 return 0;
589 }
590 @@ -676,16 +644,14 @@
591 data.len = 0;
592
593 if ((retval = getmsg(sock, NULL, &data, &flags)) < 0) {
594 - sysErr("read (receivePacket)");
595 - return -1;
596 + fatal("receivePacket: getmsg: %m");
597 }
598
599 *size = data.len;
600
601 #else
602 if ((*size = recv(sock, pkt, sizeof(PPPoEPacket), 0)) < 0) {
603 - sysErr("recv (receivePacket)");
604 - return -1;
605 + fatal("receivePacket: recv: %m");
606 }
607 #endif
608 #endif
609 @@ -716,7 +682,7 @@
610 int ppa;
611
612 if(strlen(ifname) > PATH_MAX) {
613 - rp_fatal("socket: string to long");
614 + fatal("openInterface: interface name too long");
615 }
616
617 ppa = atoi(&ifname[strlen(ifname)-1]);
618 @@ -729,9 +695,9 @@
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.");
624 }
625 - fatalSys("socket");
626 + fatal("open(%s): %m", base_dev);
627 }
628
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;
637
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);
640
641 if ( strioctl(fd, DLIOCRAW, -1, 0, NULL) < 0 ) {
642 - fatalSys("DLIOCRAW");
643 + fatal("DLIOCRAW: %m");
644 }
645
646 - if (ioctl(fd, I_FLUSH, FLUSHR) < 0) fatalSys("I_FLUSH");
647 + if (ioctl(fd, I_FLUSH, FLUSHR) < 0)
648 + fatal("I_FLUSH: %m");
649
650 return fd;
651 }
652 @@ -780,7 +747,7 @@
653 flags = 0;
654
655 if (putmsg(fd, &ctl, (struct strbuf*) NULL, flags) < 0)
656 - fatalSys("dlpromiscon: putmsg");
657 + fatal("dlpromiscon: putmsg: %m");
658
659 }
660
661 @@ -799,7 +766,7 @@
662 flags = RS_HIPRI;
663
664 if (putmsg(fd, &ctl, (struct strbuf*) NULL, flags) < 0)
665 - fatalSys("dlinforeq: putmsg");
666 + fatal("dlinforeq: putmsg: %m");
667 }
668
669 void dlunitdatareq(int fd, u_char *addrp, int addrlen, u_long minpri, u_long maxpri, u_char *datap, int datalen)
670 @@ -827,7 +794,7 @@
671 data.buf = (char *) datap;
672
673 if (putmsg(fd, &ctl, &data, 0) < 0)
674 - fatalSys("dlunitdatareq: putmsg");
675 + fatal("dlunitdatareq: putmsg: %m");
676 }
677
678 void dlinfoack(int fd, char *bufp)
679 @@ -847,18 +814,14 @@
680 expecting(DL_INFO_ACK, dlp);
681
682 if (ctl.len < sizeof (dl_info_ack_t)) {
683 - char buffer[256];
684 - sprintf(buffer, "dlinfoack: response ctl.len too short: %d", ctl.len);
685 - rp_fatal(buffer);
686 + fatal("dlinfoack: response ctl.len too short: %d", ctl.len);
687 }
688
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");
692
693 if (ctl.len < sizeof (dl_info_ack_t)) {
694 - char buffer[256];
695 - sprintf(buffer, "dlinfoack: short response ctl.len: %d", ctl.len);
696 - rp_fatal(buffer);
697 + fatal("dlinfoack: short response ctl.len: %d", ctl.len);
698 }
699 }
700
701 @@ -882,7 +845,7 @@
702 flags = 0;
703
704 if (putmsg(fd, &ctl, (struct strbuf*) NULL, flags) < 0)
705 - fatalSys("dlbindreq: putmsg");
706 + fatal("dlbindreq: putmsg: %m");
707 }
708
709 void dlattachreq(int fd, u_long ppa)
710 @@ -901,7 +864,7 @@
711 flags = 0;
712
713 if (putmsg(fd, &ctl, (struct strbuf*) NULL, flags) < 0)
714 - fatalSys("dlattachreq: putmsg");
715 + fatal("dlattachreq: putmsg: %m");
716 }
717
718 void dlokack(int fd, char *bufp)
719 @@ -921,18 +884,14 @@
720 expecting(DL_OK_ACK, dlp);
721
722 if (ctl.len < sizeof (dl_ok_ack_t)) {
723 - char buffer[256];
724 - sprintf(buffer, "dlokack: response ctl.len too short: %d", ctl.len);
725 - rp_fatal(buffer);
726 + fatal("dlokack: response ctl.len too short: %d", ctl.len);
727 }
728
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");
732
733 if (ctl.len < sizeof (dl_ok_ack_t)) {
734 - char buffer[256];
735 - sprintf(buffer, "dlokack: short response ctl.len: %d", ctl.len);
736 - rp_fatal(buffer);
737 + fatal("dlokack: short response ctl.len: %d", ctl.len);
738 }
739 }
740
741 @@ -953,12 +912,10 @@
742 expecting(DL_BIND_ACK, dlp);
743
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");
747
748 if (ctl.len < sizeof (dl_bind_ack_t)) {
749 - char buffer[256];
750 - sprintf(buffer, "dlbindack: short response ctl.len: %d", ctl.len);
751 - rp_fatal(buffer);
752 + fatal("dlbindack: short response ctl.len: %d", ctl.len);
753 }
754 }
755
756 @@ -989,8 +946,7 @@
757 */
758 (void) signal(SIGALRM, sigalrm);
759 if (alarm(MAXWAIT) < 0) {
760 - (void) sprintf(errmsg, "%s: alarm", caller);
761 - fatalSys(errmsg);
762 + fatal("%s: alarm", caller);
763 }
764
765 /*
766 @@ -998,61 +954,48 @@
767 */
768 *flagsp = 0;
769 if ((rc = getmsg(fd, ctlp, datap, flagsp)) < 0) {
770 - (void) sprintf(errmsg, "%s: getmsg", caller);
771 - fatalSys(errmsg);
772 + fatal(errmsg, "%s: getmsg: %m", caller);
773 }
774
775 /*
776 * Stop timer.
777 */
778 if (alarm(0) < 0) {
779 - (void) sprintf(errmsg, "%s: alarm", caller);
780 - fatalSys(errmsg);
781 + fatal("%s: alarm", caller);
782 }
783
784 /*
785 * Check for MOREDATA and/or MORECTL.
786 */
787 if ((rc & (MORECTL | MOREDATA)) == (MORECTL | MOREDATA)) {
788 - char buffer[256];
789 - sprintf(buffer, "%s: MORECTL|MOREDATA", caller);
790 - rp_fatal(buffer);
791 + fatal("%s: MORECTL|MOREDATA", caller);
792 }
793
794 if (rc & MORECTL) {
795 - char buffer[256];
796 - sprintf(buffer, "%s: MORECTL", caller);
797 - rp_fatal(buffer);
798 + fatal("%s: MORECTL", caller);
799 }
800
801 if (rc & MOREDATA) {
802 - char buffer[256];
803 - sprintf(buffer, "%s: MOREDATA", caller);
804 - rp_fatal(buffer);
805 + fatal("%s: MOREDATA", caller);
806 }
807
808 /*
809 * Check for at least sizeof (long) control data portion.
810 */
811 if (ctlp->len < sizeof (long)) {
812 - char buffer[256];
813 - sprintf(buffer, "getmsg: control portion length < sizeof (long): %d", ctlp->len);
814 - rp_fatal(buffer);
815 + fatal("getmsg: control portion length < sizeof (long): %d", ctlp->len);
816 }
817 }
818
819 void sigalrm(int sig)
820 {
821 - (void) rp_fatal("sigalrm: TIMEOUT");
822 + fatal("sigalrm: TIMEOUT");
823 }
824
825 void expecting(int prim, union DL_primitives *dlp)
826 {
827 if (dlp->dl_primitive != (u_long)prim) {
828 - char buffer[256];
829 - sprintf(buffer, "expected %s got %s", dlprim(prim), dlprim(dlp->dl_primitive));
830 - rp_fatal(buffer);
831 - exit(1);
832 + fatal("expected %s got %s", dlprim(prim), dlprim(dlp->dl_primitive));
833 }
834 }
835
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
839 @@ -28,8 +28,8 @@
840 CFLAGS=$(COPTS) -I../../../include/linux
841 all: rp-pppoe.so pppoe-discovery
842
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
847
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
853 @@ -35,7 +35,6 @@
854 #include "pppd/pathnames.h"
855
856 #include <linux/types.h>
857 -#include <syslog.h>
858 #include <sys/ioctl.h>
859 #include <sys/types.h>
860 #include <sys/socket.h>
861 @@ -173,10 +172,8 @@
862 (unsigned) conn->peerEth[5]);
863
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);
868 - return -1;
869 - }
870
871 return conn->sessionSocket;
872 }
873 @@ -320,11 +317,9 @@
874 }
875
876 add_options(Options);
877 -
878 - info("RP-PPPoE plugin version %s compiled against pppd %s",
879 - RP_VERSION, VERSION);
880 }
881
882 +#ifdef unused
883 /**********************************************************************
884 *%FUNCTION: fatalSys
885 *%ARGUMENTS:
886 @@ -378,6 +373,7 @@
887 {
888 rp_fatal(str);
889 }
890 +#endif
891
892 void pppoe_check_options(void)
893 {
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
897 @@ -17,14 +17,8 @@
898
899 #include "pppoe.h"
900
901 -char *xstrdup(const char *s);
902 void usage(void);
903
904 -void die(int status)
905 -{
906 - exit(status);
907 -}
908 -
909 int main(int argc, char *argv[])
910 {
911 int opt;
912 @@ -32,17 +26,17 @@
913
914 conn = malloc(sizeof(PPPoEConnection));
915 if (!conn)
916 - fatalSys("malloc");
917 + fatal("malloc");
918
919 memset(conn, 0, sizeof(PPPoEConnection));
920
921 while ((opt = getopt(argc, argv, "I:D:VUAS:C:h")) > 0) {
922 switch(opt) {
923 case 'S':
924 - conn->serviceName = xstrdup(optarg);
925 + conn->serviceName = strDup(optarg);
926 break;
927 case 'C':
928 - conn->acName = xstrdup(optarg);
929 + conn->acName = strDup(optarg);
930 break;
931 case 'U':
932 conn->useHostUniq = 1;
933 @@ -57,7 +51,7 @@
934 fprintf(conn->debugFile, "pppoe-discovery %s\n", VERSION);
935 break;
936 case 'I':
937 - conn->ifName = xstrdup(optarg);
938 + conn->ifName = strDup(optarg);
939 break;
940 case 'A':
941 /* this is the default */
942 @@ -74,7 +68,7 @@
943
944 /* default interface name */
945 if (!conn->ifName)
946 - conn->ifName = strdup("eth0");
947 + conn->ifName = strDup("eth0");
948
949 conn->discoverySocket = -1;
950 conn->sessionSocket = -1;
951 @@ -84,39 +78,6 @@
952 exit(0);
953 }
954
955 -void rp_fatal(char const *str)
956 -{
957 - char buf[1024];
958 -
959 - printErr(str);
960 - sprintf(buf, "pppoe-discovery: %.256s", str);
961 - exit(1);
962 -}
963 -
964 -void fatalSys(char const *str)
965 -{
966 - char buf[1024];
967 - int i = errno;
968 -
969 - sprintf(buf, "%.256s: %.256s", str, strerror(i));
970 - printErr(buf);
971 - sprintf(buf, "pppoe-discovery: %.256s: %.256s", str, strerror(i));
972 - exit(1);
973 -}
974 -
975 -void sysErr(char const *str)
976 -{
977 - rp_fatal(str);
978 -}
979 -
980 -char *xstrdup(const char *s)
981 -{
982 - register char *ret = strdup(s);
983 - if (!ret)
984 - sysErr("strdup");
985 - return ret;
986 -}
987 -
988 void usage(void)
989 {
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,
996 PPPoETag *tag);
997
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) */
1003 +
1004 #define SET_STRING(var, val) do { if (var) free(var); var = strDup(val); } while(0);
1005
1006 #define CHECK_ROOM(cursor, start, len) \
1007 do {\
1008 if (((cursor)-(start))+(len) > MAX_PPPOE_PAYLOAD) { \
1009 - syslog(LOG_ERR, "Would create too-long packet"); \
1010 + error("Would create too-long packet"); \
1011 return; \
1012 } \
1013 } while(0)
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
1017 @@ -0,0 +1,62 @@
1018 +#include <stdio.h>
1019 +#include <stdlib.h>
1020 +#include <unistd.h>
1021 +#include <stdarg.h>
1022 +#include <syslog.h>
1023 +
1024 +void dbglog(const char *fmt, ...)
1025 +{
1026 + va_list ap;
1027 +
1028 + va_start(ap, fmt);
1029 + vsyslog(LOG_DEBUG, fmt, ap);
1030 + vfprintf(stderr, fmt, ap);
1031 + fputs("\n", stderr);
1032 + va_end(ap);
1033 +}
1034 +
1035 +void info(const char *fmt, ...)
1036 +{
1037 + va_list ap;
1038 +
1039 + va_start(ap, fmt);
1040 + vsyslog(LOG_INFO, fmt, ap);
1041 + vfprintf(stderr, fmt, ap);
1042 + fputs("\n", stderr);
1043 + va_end(ap);
1044 +}
1045 +
1046 +void warn(const char *fmt, ...)
1047 +{
1048 + va_list ap;
1049 +
1050 + va_start(ap, fmt);
1051 + vsyslog(LOG_WARNING, fmt, ap);
1052 + vfprintf(stderr, fmt, ap);
1053 + fputs("\n", stderr);
1054 + va_end(ap);
1055 +}
1056 +
1057 +void error(const char *fmt, ...)
1058 +{
1059 + va_list ap;
1060 +
1061 + va_start(ap, fmt);
1062 + vsyslog(LOG_ERR, fmt, ap);
1063 + vfprintf(stderr, fmt, ap);
1064 + fputs("\n", stderr);
1065 + va_end(ap);
1066 +}
1067 +
1068 +void fatal(const char *fmt, ...)
1069 +{
1070 + va_list ap;
1071 +
1072 + va_start(ap, fmt);
1073 + vsyslog(LOG_ERR, fmt, ap);
1074 + vfprintf(stderr, fmt, ap);
1075 + fputs("\n", stderr);
1076 + va_end(ap);
1077 + exit(1);
1078 +}
1079 +
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
1083 @@ -18,10 +18,6 @@
1084
1085 #include "pppoe.h"
1086
1087 -#ifdef HAVE_SYSLOG_H
1088 -#include <syslog.h>
1089 -#endif
1090 -
1091 #include <string.h>
1092 #include <errno.h>
1093 #include <stdlib.h>
1094 @@ -50,17 +46,17 @@
1095 UINT16_t tagType, tagLen;
1096
1097 if (packet->ver != 1) {
1098 - syslog(LOG_ERR, "Invalid PPPoE version (%d)", (int) packet->ver);
1099 + error("Invalid PPPoE version (%u)", packet->ver);
1100 return -1;
1101 }
1102 if (packet->type != 1) {
1103 - syslog(LOG_ERR, "Invalid PPPoE type (%d)", (int) packet->type);
1104 + error("Invalid PPPoE type (%u)", packet->type);
1105 return -1;
1106 }
1107
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);
1112 return -1;
1113 }
1114
1115 @@ -76,7 +72,7 @@
1116 return 0;
1117 }
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);
1121 return -1;
1122 }
1123 func(tagType, tagLen, curTag+TAG_HDR_SIZE, extra);
1124 @@ -105,17 +101,17 @@
1125 UINT16_t tagType, tagLen;
1126
1127 if (packet->ver != 1) {
1128 - syslog(LOG_ERR, "Invalid PPPoE version (%d)", (int) packet->ver);
1129 + error("Invalid PPPoE version (%u)", packet->ver);
1130 return NULL;
1131 }
1132 if (packet->type != 1) {
1133 - syslog(LOG_ERR, "Invalid PPPoE type (%d)", (int) packet->type);
1134 + error("Invalid PPPoE type (%u)", packet->type);
1135 return NULL;
1136 }
1137
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);
1142 return NULL;
1143 }
1144
1145 @@ -131,7 +127,7 @@
1146 return NULL;
1147 }
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);
1151 return NULL;
1152 }
1153 if (tagType == type) {
1154 @@ -143,6 +139,7 @@
1155 return NULL;
1156 }
1157
1158 +#ifdef unused
1159 /**********************************************************************
1160 *%FUNCTION: printErr
1161 *%ARGUMENTS:
1162 @@ -158,6 +155,7 @@
1163 fprintf(stderr, "pppoe: %s\n", str);
1164 syslog(LOG_ERR, "%s", str);
1165 }
1166 +#endif
1167
1168
1169 /**********************************************************************
1170 @@ -172,7 +170,7 @@
1171 {
1172 char *copy = malloc(strlen(str)+1);
1173 if (!copy) {
1174 - rp_fatal("strdup failed");
1175 + fatal("strdup failed");
1176 }
1177 strcpy(copy, str);
1178 return copy;
1179 @@ -467,9 +465,10 @@
1180 fprintf(conn->debugFile, "\n");
1181 fflush(conn->debugFile);
1182 }
1183 - syslog(LOG_INFO,"Sent PADT");
1184 + info("Sent PADT");
1185 }
1186
1187 +#ifdef unused
1188 /**********************************************************************
1189 *%FUNCTION: parseLogErrs
1190 *%ARGUMENTS:
1191 @@ -501,4 +500,5 @@
1192 break;
1193 }
1194 }
1195 +#endif
1196
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
1200 @@ -13,10 +13,6 @@
1201
1202 #include "pppoe.h"
1203
1204 -#ifdef HAVE_SYSLOG_H
1205 -#include <syslog.h>
1206 -#endif
1207 -
1208 #include <string.h>
1209 #include <stdlib.h>
1210 #include <errno.h>
1211 @@ -167,24 +163,21 @@
1212 if (conn->printACNames) {
1213 printf("Got a Service-Name-Error tag: %.*s\n", (int) len, data);
1214 } else {
1215 - syslog(LOG_ERR, "PADO: Service-Name-Error: %.*s", (int) len, data);
1216 - exit(1);
1217 + fatal("PADO: Service-Name-Error: %.*s", (int) len, data);
1218 }
1219 break;
1220 case TAG_AC_SYSTEM_ERROR:
1221 if (conn->printACNames) {
1222 printf("Got a System-Error tag: %.*s\n", (int) len, data);
1223 } else {
1224 - syslog(LOG_ERR, "PADO: System-Error: %.*s", (int) len, data);
1225 - exit(1);
1226 + fatal("PADO: System-Error: %.*s", (int) len, data);
1227 }
1228 break;
1229 case TAG_GENERIC_ERROR:
1230 if (conn->printACNames) {
1231 printf("Got a Generic-Error tag: %.*s\n", (int) len, data);
1232 } else {
1233 - syslog(LOG_ERR, "PADO: Generic-Error: %.*s", (int) len, data);
1234 - exit(1);
1235 + fatal("PADO: Generic-Error: %.*s", (int) len, data);
1236 }
1237 break;
1238 }
1239 @@ -209,20 +202,14 @@
1240 PPPoEConnection *conn = (PPPoEConnection *) extra;
1241 switch(type) {
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);
1245 break;
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);
1249 - exit(1);
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);
1254 - exit(1);
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);
1259 - exit(1);
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);
1264 @@ -336,7 +323,7 @@
1265 if (r >= 0 || errno != EINTR) break;
1266 }
1267 if (r < 0) {
1268 - fatalSys("select (waitForPADO)");
1269 + fatal("waitForPADO: select: %m");
1270 }
1271 if (r == 0) return; /* Timed out */
1272 }
1273 @@ -346,8 +333,7 @@
1274
1275 /* Check length */
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));
1280 continue;
1281 }
1282
1283 @@ -366,16 +352,16 @@
1284
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");
1289 continue;
1290 }
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");
1295 continue;
1296 }
1297 if (!pc.seenServiceName) {
1298 - printErr("Ignoring PADO packet with no Service-Name tag");
1299 + error("Ignoring PADO packet with no Service-Name tag");
1300 continue;
1301 }
1302 conn->numPADOs++;
1303 @@ -513,7 +499,7 @@
1304 if (r >= 0 || errno != EINTR) break;
1305 }
1306 if (r < 0) {
1307 - fatalSys("select (waitForPADS)");
1308 + fatal("waitForPADS: select: %m");
1309 }
1310 if (r == 0) return;
1311 }
1312 @@ -523,8 +509,7 @@
1313
1314 /* Check length */
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));
1319 continue;
1320 }
1321
1322 @@ -556,11 +541,12 @@
1323 /* Don't bother with ntohs; we'll just end up converting it back... */
1324 conn->session = packet.session;
1325
1326 - syslog(LOG_INFO, "PPP session is %d", (int) ntohs(conn->session));
1327 + info("PPP session is %d", ntohs(conn->session));
1328
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));
1334 }
1335 }
1336
1337 @@ -620,7 +606,7 @@
1338
1339 /* If we're only printing access concentrator names, we're done */
1340 if (conn->printACNames) {
1341 - die(0);
1342 + exit(0);
1343 }
1344
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
1349 @@ -40,10 +40,6 @@
1350 #include <sys/ioctl.h>
1351 #endif
1352
1353 -#ifdef HAVE_SYSLOG_H
1354 -#include <syslog.h>
1355 -#endif
1356 -
1357 #include <errno.h>
1358 #include <stdlib.h>
1359 #include <string.h>
1360 @@ -127,7 +123,7 @@
1361 {
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);
1366 }
1367 return type;
1368 }
1369 @@ -156,7 +152,7 @@
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");
1375 }
1376 ifr = ifc.ifc_req;
1377 ifreq.ifr_name[0] = '\0';
1378 @@ -172,9 +168,7 @@
1379 (sdl->sdl_alen == ETH_ALEN) &&
1380 !strncmp(ifname, ifr->ifr_name, sizeof(ifr->ifr_name))) {
1381 if (found) {
1382 - char buffer[256];
1383 - sprintf(buffer, "interface %.16s has more than one ethernet address", ifname);
1384 - rp_fatal(buffer);
1385 + fatal("interface %s has more than one ethernet address", ifname);
1386 } else {
1387 found = 1;
1388 memcpy(hwaddr, LLADDR(sdl), ETH_ALEN);
1389 @@ -183,9 +177,7 @@
1390 }
1391 }
1392 if (!found) {
1393 - char buffer[256];
1394 - sprintf(buffer, "interface %.16s has no ethernet address", ifname);
1395 - rp_fatal(buffer);
1396 + fatal("interface %s has no ethernet address", ifname);
1397 }
1398 }
1399
1400 @@ -252,7 +244,7 @@
1401
1402 /* Apply the filter */
1403 if (ioctl(fd, BIOCSETF, &bpfProgram) < 0) {
1404 - fatalSys("ioctl(BIOCSETF)");
1405 + fatal("ioctl(BIOCSETF): %m");
1406 }
1407 }
1408 }
1409 @@ -298,42 +290,36 @@
1410 if (fd < 0) {
1411 switch (errno) {
1412 case EACCES: /* permission denied */
1413 - {
1414 - char buffer[256];
1415 - sprintf(buffer, "Cannot open %.32s -- pppoe must be run as root.", bpfName);
1416 - rp_fatal(buffer);
1417 - }
1418 + fatal("Cannot open %s -- pppoe must be run as root.", bpfName);
1419 break;
1420 case EBUSY:
1421 case ENOENT: /* no such file */
1422 if (i == 0) {
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)");
1425 } else {
1426 - rp_fatal("All /dev/bpf* devices are in use");
1427 + fatal("All /dev/bpf* devices are in use");
1428 }
1429 break;
1430 }
1431 - fatalSys(bpfName);
1432 + fatal("%s: %m", bpfName);
1433 }
1434
1435 if ((sock = socket(AF_LOCAL, SOCK_DGRAM, 0)) < 0) {
1436 - fatalSys("socket");
1437 + fatal("socket: %m");
1438 }
1439
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");
1445 }
1446 if ((ifr.ifr_flags & IFF_UP) == 0) {
1447 - char buffer[256];
1448 - sprintf(buffer, "Interface %.16s is not up\n", ifname);
1449 - rp_fatal(buffer);
1450 + fatal("Interface %s is not up", ifname);
1451 }
1452
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.");
1457 }
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");
1466 }
1467 if (ifr.ifr_mtu < ETH_DATA_LEN) {
1468 - char buffer[256];
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);
1473 - printErr(buffer);
1474 }
1475 #endif
1476
1477 /* done with the socket */
1478 if (close(sock) < 0) {
1479 - fatalSys("close");
1480 + fatal("close: %m");
1481 }
1482
1483 /* Check the BPF version number */
1484 if (ioctl(fd, BIOCVERSION, &bpf_ver) < 0) {
1485 - fatalSys("ioctl(BIOCVERSION)");
1486 + fatal("ioctl(BIOCVERSION): %m");
1487 }
1488 if ((bpf_ver.bv_major != BPF_MAJOR_VERSION) ||
1489 (bpf_ver.bv_minor < BPF_MINOR_VERSION)) {
1490 - char buffer[256];
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);
1495 - rp_fatal(buffer);
1496 }
1497
1498 /* allocate a receive packet buffer */
1499 if (ioctl(fd, BIOCGBLEN, &bpfLength) < 0) {
1500 - fatalSys("ioctl(BIOCGBLEN)");
1501 + fatal("ioctl(BIOCGBLEN): %m");
1502 }
1503 if (!(bpfBuffer = (unsigned char *) malloc(bpfLength))) {
1504 - rp_fatal("malloc");
1505 + fatal("malloc");
1506 }
1507
1508 /* reads should return as soon as there is a packet available */
1509 optval = 1;
1510 if (ioctl(fd, BIOCIMMEDIATE, &optval) < 0) {
1511 - fatalSys("ioctl(BIOCIMMEDIATE)");
1512 + fatal("ioctl(BIOCIMMEDIATE): %m");
1513 }
1514
1515 /* Bind the interface to the filter */
1516 strncpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
1517 if (ioctl(fd, BIOCSETIF, &ifr) < 0) {
1518 - char buffer[256];
1519 - sprintf(buffer, "ioctl(BIOCSETIF) can't select interface %.16s",
1520 - ifname);
1521 - rp_fatal(buffer);
1522 + fatal("ioctl(BIOCSETIF) can't select interface %s: %m", ifname);
1523 }
1524
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",
1527 ifname,
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.");
1536 }
1537 - fatalSys("socket");
1538 + fatal("cannot create the raw socket: %m");
1539 }
1540
1541 if (setsockopt(fd, SOL_SOCKET, SO_BROADCAST, &optval, sizeof(optval)) < 0) {
1542 - fatalSys("setsockopt");
1543 + fatal("setsockopt(SOL_SOCKET, SO_BROADCAST): %m");
1544 }
1545
1546 /* Fill in hardware address */
1547 if (hwaddr) {
1548 strncpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
1549 - if (ioctl(fd, SIOCGIFHWADDR, &ifr) < 0) {
1550 - fatalSys("ioctl(SIOCGIFHWADDR)");
1551 - }
1552 + if (ioctl(fd, SIOCGIFHWADDR, &ifr) < 0)
1553 + fatal("ioctl(SIOCGIFHWADDR): %m");
1554 memcpy(hwaddr, ifr.ifr_hwaddr.sa_data, ETH_ALEN);
1555 #ifdef ARPHRD_ETHER
1556 if (ifr.ifr_hwaddr.sa_family != ARPHRD_ETHER) {
1557 - char buffer[256];
1558 - sprintf(buffer, "Interface %.16s is not Ethernet", ifname);
1559 - rp_fatal(buffer);
1560 + fatal("Interface %s is not Ethernet", ifname);
1561 }
1562 #endif
1563 if (NOT_UNICAST(hwaddr)) {
1564 - char buffer[256];
1565 - sprintf(buffer,
1566 - "Interface %.16s has broadcast/multicast MAC address??",
1567 + fatal("Interface %s has broadcast/multicast MAC address",
1568 ifname);
1569 - rp_fatal(buffer);
1570 }
1571 }
1572
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");
1578 }
1579 if (ifr.ifr_mtu < ETH_DATA_LEN) {
1580 - char buffer[256];
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);
1585 - printErr(buffer);
1586 }
1587
1588 #ifdef HAVE_STRUCT_SOCKADDR_LL
1589 @@ -493,7 +466,7 @@
1590
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");
1595 }
1596 sa.sll_ifindex = ifr.ifr_ifindex;
1597
1598 @@ -503,7 +476,7 @@
1599
1600 /* We're only interested in packets on specified interface */
1601 if (bind(fd, (struct sockaddr *) &sa, sizeof(sa)) < 0) {
1602 - fatalSys("bind");
1603 + fatal("bind: %m");
1604 }
1605
1606 return fd;
1607 @@ -527,13 +500,11 @@
1608 {
1609 #if defined(USE_BPF)
1610 if (write(sock, pkt, size) < 0) {
1611 - sysErr("write (sendPacket)");
1612 - return -1;
1613 + fatal("sendPacket: write: %m");
1614 }
1615 #elif defined(HAVE_STRUCT_SOCKADDR_LL)
1616 if (send(sock, pkt, size, 0) < 0) {
1617 - sysErr("send (sendPacket)");
1618 - return -1;
1619 + fatal("sendPacket: send: %m");
1620 }
1621 #else
1622 #ifdef USE_DLPI
1623 @@ -577,12 +548,11 @@
1624 struct sockaddr sa;
1625
1626 if (!conn) {
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");
1629 }
1630 strcpy(sa.sa_data, conn->ifName);
1631 if (sendto(sock, pkt, size, 0, &sa, sizeof(sa)) < 0) {
1632 - sysErr("sendto (sendPacket)");
1633 - return -1;
1634 + fatal("sendPacket: sendto: %m");
1635 }
1636 #endif
1637 #endif
1638 @@ -632,26 +602,24 @@
1639 if (bpfSize <= 0) {
1640 bpfOffset = 0;
1641 if ((bpfSize = read(sock, bpfBuffer, bpfLength)) < 0) {
1642 - sysErr("read (receivePacket)");
1643 - return -1;
1644 + fatal("receivePacket: read: %m");
1645 }
1646 }
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 */
1651 return 0;
1652 }
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 */
1659 return 0;
1660 }
1661 seglen = hdr.bh_hdrlen + hdr.bh_caplen;
1662 if (seglen > bpfSize) {
1663 - syslog(LOG_ERR, "Truncated bpf packet: seglen=%d, bpfSize=%d",
1664 - seglen, bpfSize);
1665 + error("Truncated bpf packet: seglen=%d, bpfSize=%d", seglen, bpfSize);
1666 clearPacketHeader(pkt); /* resets bpfSize and bpfOffset */
1667 return 0;
1668 }
1669 @@ -676,16 +644,14 @@
1670 data.len = 0;
1671
1672 if ((retval = getmsg(sock, NULL, &data, &flags)) < 0) {
1673 - sysErr("read (receivePacket)");
1674 - return -1;
1675 + fatal("receivePacket: getmsg: %m");
1676 }
1677
1678 *size = data.len;
1679
1680 #else
1681 if ((*size = recv(sock, pkt, sizeof(PPPoEPacket), 0)) < 0) {
1682 - sysErr("recv (receivePacket)");
1683 - return -1;
1684 + fatal("receivePacket: recv: %m");
1685 }
1686 #endif
1687 #endif
1688 @@ -716,7 +682,7 @@
1689 int ppa;
1690
1691 if(strlen(ifname) > PATH_MAX) {
1692 - rp_fatal("socket: string to long");
1693 + fatal("openInterface: interface name too long");
1694 }
1695
1696 ppa = atoi(&ifname[strlen(ifname)-1]);
1697 @@ -729,9 +695,9 @@
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.");
1703 }
1704 - fatalSys("socket");
1705 + fatal("open(%s): %m", base_dev);
1706 }
1707
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;
1716
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);
1719
1720 if ( strioctl(fd, DLIOCRAW, -1, 0, NULL) < 0 ) {
1721 - fatalSys("DLIOCRAW");
1722 + fatal("DLIOCRAW: %m");
1723 }
1724
1725 - if (ioctl(fd, I_FLUSH, FLUSHR) < 0) fatalSys("I_FLUSH");
1726 + if (ioctl(fd, I_FLUSH, FLUSHR) < 0)
1727 + fatal("I_FLUSH: %m");
1728
1729 return fd;
1730 }
1731 @@ -780,7 +747,7 @@
1732 flags = 0;
1733
1734 if (putmsg(fd, &ctl, (struct strbuf*) NULL, flags) < 0)
1735 - fatalSys("dlpromiscon: putmsg");
1736 + fatal("dlpromiscon: putmsg: %m");
1737
1738 }
1739
1740 @@ -799,7 +766,7 @@
1741 flags = RS_HIPRI;
1742
1743 if (putmsg(fd, &ctl, (struct strbuf*) NULL, flags) < 0)
1744 - fatalSys("dlinforeq: putmsg");
1745 + fatal("dlinforeq: putmsg: %m");
1746 }
1747
1748 void dlunitdatareq(int fd, u_char *addrp, int addrlen, u_long minpri, u_long maxpri, u_char *datap, int datalen)
1749 @@ -827,7 +794,7 @@
1750 data.buf = (char *) datap;
1751
1752 if (putmsg(fd, &ctl, &data, 0) < 0)
1753 - fatalSys("dlunitdatareq: putmsg");
1754 + fatal("dlunitdatareq: putmsg: %m");
1755 }
1756
1757 void dlinfoack(int fd, char *bufp)
1758 @@ -847,18 +814,14 @@
1759 expecting(DL_INFO_ACK, dlp);
1760
1761 if (ctl.len < sizeof (dl_info_ack_t)) {
1762 - char buffer[256];
1763 - sprintf(buffer, "dlinfoack: response ctl.len too short: %d", ctl.len);
1764 - rp_fatal(buffer);
1765 + fatal("dlinfoack: response ctl.len too short: %d", ctl.len);
1766 }
1767
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");
1771
1772 if (ctl.len < sizeof (dl_info_ack_t)) {
1773 - char buffer[256];
1774 - sprintf(buffer, "dlinfoack: short response ctl.len: %d", ctl.len);
1775 - rp_fatal(buffer);
1776 + fatal("dlinfoack: short response ctl.len: %d", ctl.len);
1777 }
1778 }
1779
1780 @@ -882,7 +845,7 @@
1781 flags = 0;
1782
1783 if (putmsg(fd, &ctl, (struct strbuf*) NULL, flags) < 0)
1784 - fatalSys("dlbindreq: putmsg");
1785 + fatal("dlbindreq: putmsg: %m");
1786 }
1787
1788 void dlattachreq(int fd, u_long ppa)
1789 @@ -901,7 +864,7 @@
1790 flags = 0;
1791
1792 if (putmsg(fd, &ctl, (struct strbuf*) NULL, flags) < 0)
1793 - fatalSys("dlattachreq: putmsg");
1794 + fatal("dlattachreq: putmsg: %m");
1795 }
1796
1797 void dlokack(int fd, char *bufp)
1798 @@ -921,18 +884,14 @@
1799 expecting(DL_OK_ACK, dlp);
1800
1801 if (ctl.len < sizeof (dl_ok_ack_t)) {
1802 - char buffer[256];
1803 - sprintf(buffer, "dlokack: response ctl.len too short: %d", ctl.len);
1804 - rp_fatal(buffer);
1805 + fatal("dlokack: response ctl.len too short: %d", ctl.len);
1806 }
1807
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");
1811
1812 if (ctl.len < sizeof (dl_ok_ack_t)) {
1813 - char buffer[256];
1814 - sprintf(buffer, "dlokack: short response ctl.len: %d", ctl.len);
1815 - rp_fatal(buffer);
1816 + fatal("dlokack: short response ctl.len: %d", ctl.len);
1817 }
1818 }
1819
1820 @@ -953,12 +912,10 @@
1821 expecting(DL_BIND_ACK, dlp);
1822
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");
1826
1827 if (ctl.len < sizeof (dl_bind_ack_t)) {
1828 - char buffer[256];
1829 - sprintf(buffer, "dlbindack: short response ctl.len: %d", ctl.len);
1830 - rp_fatal(buffer);
1831 + fatal("dlbindack: short response ctl.len: %d", ctl.len);
1832 }
1833 }
1834
1835 @@ -989,8 +946,7 @@
1836 */
1837 (void) signal(SIGALRM, sigalrm);
1838 if (alarm(MAXWAIT) < 0) {
1839 - (void) sprintf(errmsg, "%s: alarm", caller);
1840 - fatalSys(errmsg);
1841 + fatal("%s: alarm", caller);
1842 }
1843
1844 /*
1845 @@ -998,61 +954,48 @@
1846 */
1847 *flagsp = 0;
1848 if ((rc = getmsg(fd, ctlp, datap, flagsp)) < 0) {
1849 - (void) sprintf(errmsg, "%s: getmsg", caller);
1850 - fatalSys(errmsg);
1851 + fatal(errmsg, "%s: getmsg: %m", caller);
1852 }
1853
1854 /*
1855 * Stop timer.
1856 */
1857 if (alarm(0) < 0) {
1858 - (void) sprintf(errmsg, "%s: alarm", caller);
1859 - fatalSys(errmsg);
1860 + fatal("%s: alarm", caller);
1861 }
1862
1863 /*
1864 * Check for MOREDATA and/or MORECTL.
1865 */
1866 if ((rc & (MORECTL | MOREDATA)) == (MORECTL | MOREDATA)) {
1867 - char buffer[256];
1868 - sprintf(buffer, "%s: MORECTL|MOREDATA", caller);
1869 - rp_fatal(buffer);
1870 + fatal("%s: MORECTL|MOREDATA", caller);
1871 }
1872
1873 if (rc & MORECTL) {
1874 - char buffer[256];
1875 - sprintf(buffer, "%s: MORECTL", caller);
1876 - rp_fatal(buffer);
1877 + fatal("%s: MORECTL", caller);
1878 }
1879
1880 if (rc & MOREDATA) {
1881 - char buffer[256];
1882 - sprintf(buffer, "%s: MOREDATA", caller);
1883 - rp_fatal(buffer);
1884 + fatal("%s: MOREDATA", caller);
1885 }
1886
1887 /*
1888 * Check for at least sizeof (long) control data portion.
1889 */
1890 if (ctlp->len < sizeof (long)) {
1891 - char buffer[256];
1892 - sprintf(buffer, "getmsg: control portion length < sizeof (long): %d", ctlp->len);
1893 - rp_fatal(buffer);
1894 + fatal("getmsg: control portion length < sizeof (long): %d", ctlp->len);
1895 }
1896 }
1897
1898 void sigalrm(int sig)
1899 {
1900 - (void) rp_fatal("sigalrm: TIMEOUT");
1901 + fatal("sigalrm: TIMEOUT");
1902 }
1903
1904 void expecting(int prim, union DL_primitives *dlp)
1905 {
1906 if (dlp->dl_primitive != (u_long)prim) {
1907 - char buffer[256];
1908 - sprintf(buffer, "expected %s got %s", dlprim(prim), dlprim(dlp->dl_primitive));
1909 - rp_fatal(buffer);
1910 - exit(1);
1911 + fatal("expected %s got %s", dlprim(prim), dlprim(dlp->dl_primitive));
1912 }
1913 }
1914
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
1918 @@ -28,8 +28,8 @@
1919 CFLAGS=$(COPTS) -I../../../include/linux
1920 all: rp-pppoe.so pppoe-discovery
1921
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
1926
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
1932 @@ -35,7 +35,6 @@
1933 #include "pppd/pathnames.h"
1934
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]);
1942
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);
1947 - return -1;
1948 - }
1949
1950 return conn->sessionSocket;
1951 }
1952 @@ -320,11 +317,9 @@
1953 }
1954
1955 add_options(Options);
1956 -
1957 - info("RP-PPPoE plugin version %s compiled against pppd %s",
1958 - RP_VERSION, VERSION);
1959 }
1960
1961 +#ifdef unused
1962 /**********************************************************************
1963 *%FUNCTION: fatalSys
1964 *%ARGUMENTS:
1965 @@ -378,6 +373,7 @@
1966 {
1967 rp_fatal(str);
1968 }
1969 +#endif
1970
1971 void pppoe_check_options(void)
1972 {
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
1976 @@ -17,14 +17,8 @@
1977
1978 #include "pppoe.h"
1979
1980 -char *xstrdup(const char *s);
1981 void usage(void);
1982
1983 -void die(int status)
1984 -{
1985 - exit(status);
1986 -}
1987 -
1988 int main(int argc, char *argv[])
1989 {
1990 int opt;
1991 @@ -32,17 +26,17 @@
1992
1993 conn = malloc(sizeof(PPPoEConnection));
1994 if (!conn)
1995 - fatalSys("malloc");
1996 + fatal("malloc");
1997
1998 memset(conn, 0, sizeof(PPPoEConnection));
1999
2000 while ((opt = getopt(argc, argv, "I:D:VUAS:C:h")) > 0) {
2001 switch(opt) {
2002 case 'S':
2003 - conn->serviceName = xstrdup(optarg);
2004 + conn->serviceName = strDup(optarg);
2005 break;
2006 case 'C':
2007 - conn->acName = xstrdup(optarg);
2008 + conn->acName = strDup(optarg);
2009 break;
2010 case 'U':
2011 conn->useHostUniq = 1;
2012 @@ -57,7 +51,7 @@
2013 fprintf(conn->debugFile, "pppoe-discovery %s\n", VERSION);
2014 break;
2015 case 'I':
2016 - conn->ifName = xstrdup(optarg);
2017 + conn->ifName = strDup(optarg);
2018 break;
2019 case 'A':
2020 /* this is the default */
2021 @@ -74,7 +68,7 @@
2022
2023 /* default interface name */
2024 if (!conn->ifName)
2025 - conn->ifName = strdup("eth0");
2026 + conn->ifName = strDup("eth0");
2027
2028 conn->discoverySocket = -1;
2029 conn->sessionSocket = -1;
2030 @@ -84,39 +78,6 @@
2031 exit(0);
2032 }
2033
2034 -void rp_fatal(char const *str)
2035 -{
2036 - char buf[1024];
2037 -
2038 - printErr(str);
2039 - sprintf(buf, "pppoe-discovery: %.256s", str);
2040 - exit(1);
2041 -}
2042 -
2043 -void fatalSys(char const *str)
2044 -{
2045 - char buf[1024];
2046 - int i = errno;
2047 -
2048 - sprintf(buf, "%.256s: %.256s", str, strerror(i));
2049 - printErr(buf);
2050 - sprintf(buf, "pppoe-discovery: %.256s: %.256s", str, strerror(i));
2051 - exit(1);
2052 -}
2053 -
2054 -void sysErr(char const *str)
2055 -{
2056 - rp_fatal(str);
2057 -}
2058 -
2059 -char *xstrdup(const char *s)
2060 -{
2061 - register char *ret = strdup(s);
2062 - if (!ret)
2063 - sysErr("strdup");
2064 - return ret;
2065 -}
2066 -
2067 void usage(void)
2068 {
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,
2075 PPPoETag *tag);
2076
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) */
2082 +
2083 #define SET_STRING(var, val) do { if (var) free(var); var = strDup(val); } while(0);
2084
2085 #define CHECK_ROOM(cursor, start, len) \
2086 do {\
2087 if (((cursor)-(start))+(len) > MAX_PPPOE_PAYLOAD) { \
2088 - syslog(LOG_ERR, "Would create too-long packet"); \
2089 + error("Would create too-long packet"); \
2090 return; \
2091 } \
2092 } while(0)
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
2096 @@ -0,0 +1,62 @@
2097 +#include <stdio.h>
2098 +#include <stdlib.h>
2099 +#include <unistd.h>
2100 +#include <stdarg.h>
2101 +#include <syslog.h>
2102 +
2103 +void dbglog(const char *fmt, ...)
2104 +{
2105 + va_list ap;
2106 +
2107 + va_start(ap, fmt);
2108 + vsyslog(LOG_DEBUG, fmt, ap);
2109 + vfprintf(stderr, fmt, ap);
2110 + fputs("\n", stderr);
2111 + va_end(ap);
2112 +}
2113 +
2114 +void info(const char *fmt, ...)
2115 +{
2116 + va_list ap;
2117 +
2118 + va_start(ap, fmt);
2119 + vsyslog(LOG_INFO, fmt, ap);
2120 + vfprintf(stderr, fmt, ap);
2121 + fputs("\n", stderr);
2122 + va_end(ap);
2123 +}
2124 +
2125 +void warn(const char *fmt, ...)
2126 +{
2127 + va_list ap;
2128 +
2129 + va_start(ap, fmt);
2130 + vsyslog(LOG_WARNING, fmt, ap);
2131 + vfprintf(stderr, fmt, ap);
2132 + fputs("\n", stderr);
2133 + va_end(ap);
2134 +}
2135 +
2136 +void error(const char *fmt, ...)
2137 +{
2138 + va_list ap;
2139 +
2140 + va_start(ap, fmt);
2141 + vsyslog(LOG_ERR, fmt, ap);
2142 + vfprintf(stderr, fmt, ap);
2143 + fputs("\n", stderr);
2144 + va_end(ap);
2145 +}
2146 +
2147 +void fatal(const char *fmt, ...)
2148 +{
2149 + va_list ap;
2150 +
2151 + va_start(ap, fmt);
2152 + vsyslog(LOG_ERR, fmt, ap);
2153 + vfprintf(stderr, fmt, ap);
2154 + fputs("\n", stderr);
2155 + va_end(ap);
2156 + exit(1);
2157 +}
2158 +