finally move buildroot-ng to trunk
[openwrt/staging/jogo.git] / package / ppp / patches / 103-debian_pppoe_cleanup.patch
1 diff -ruNp ppp-2.4.3.orig/pppd/plugins/rp-pppoe/common.c ppp-2.4.3/pppd/plugins/rp-pppoe/common.c
2 --- ppp-2.4.3.orig/pppd/plugins/rp-pppoe/common.c 2004-02-02 04:36:46.000000000 +0100
3 +++ ppp-2.4.3/pppd/plugins/rp-pppoe/common.c 2005-03-11 02:09:19.000000000 +0100
4 @@ -18,10 +18,6 @@ static char const RCSID[] =
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 @@ parsePacket(PPPoEPacket *packet, ParseFu
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 @@ parsePacket(PPPoEPacket *packet, ParseFu
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 @@ findTag(PPPoEPacket *packet, UINT16_t ty
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 @@ findTag(PPPoEPacket *packet, UINT16_t ty
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 @@ findTag(PPPoEPacket *packet, UINT16_t ty
76 return NULL;
77 }
78
79 +#ifdef unused
80 /**********************************************************************
81 *%FUNCTION: printErr
82 *%ARGUMENTS:
83 @@ -158,6 +155,7 @@ printErr(char const *str)
84 fprintf(stderr, "pppoe: %s\n", str);
85 syslog(LOG_ERR, "%s", str);
86 }
87 +#endif
88
89
90 /**********************************************************************
91 @@ -172,7 +170,7 @@ strDup(char const *str)
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 @@ sendPADT(PPPoEConnection *conn, char con
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 @@ parseLogErrs(UINT16_t type, UINT16_t len
113 break;
114 }
115 }
116 +#endif
117
118 diff -ruNp ppp-2.4.3.orig/pppd/plugins/rp-pppoe/discovery.c ppp-2.4.3/pppd/plugins/rp-pppoe/discovery.c
119 --- ppp-2.4.3.orig/pppd/plugins/rp-pppoe/discovery.c 2005-03-11 02:12:52.000000000 +0100
120 +++ ppp-2.4.3/pppd/plugins/rp-pppoe/discovery.c 2005-03-10 12:24:19.000000000 +0100
121 @@ -13,10 +13,6 @@ static char const RCSID[] =
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 @@ parsePADOTags(UINT16_t type, UINT16_t le
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 @@ parsePADSTags(UINT16_t type, UINT16_t le
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 @@ waitForPADO(PPPoEConnection *conn, int t
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 @@ waitForPADO(PPPoEConnection *conn, int t
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 @@ waitForPADO(PPPoEConnection *conn, int t
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 @@ waitForPADS(PPPoEConnection *conn, int t
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 @@ waitForPADS(PPPoEConnection *conn, int t
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 @@ waitForPADS(PPPoEConnection *conn, int t
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 @@ discovery(PPPoEConnection *conn)
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 -ruNp ppp-2.4.3.orig/pppd/plugins/rp-pppoe/if.c ppp-2.4.3/pppd/plugins/rp-pppoe/if.c
268 --- ppp-2.4.3.orig/pppd/plugins/rp-pppoe/if.c 2001-12-14 03:55:20.000000000 +0100
269 +++ ppp-2.4.3/pppd/plugins/rp-pppoe/if.c 2005-03-10 13:32:43.000000000 +0100
270 @@ -40,10 +40,6 @@ static char const RCSID[] =
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 @@ etherType(PPPoEPacket *packet)
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 @@ getHWaddr(int sock, char const *ifname,
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 @@ getHWaddr(int sock, char const *ifname,
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 @@ getHWaddr(int sock, char const *ifname,
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 @@ initFilter(int fd, UINT16_t type, unsign
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 @@ openInterface(char const *ifname, UINT16
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 @@ openInterface(char const *ifname, UINT16
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 @@ openInterface(char const *ifname, UINT16
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 @@ openInterface(char const *ifname, UINT16
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 @@ openInterface(char const *ifname, UINT16
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 @@ sendPacket(PPPoEConnection *conn, int so
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 @@ sendPacket(PPPoEConnection *conn, int so
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 @@ receivePacket(int sock, PPPoEPacket *pkt
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 @@ receivePacket(int sock, PPPoEPacket *pkt
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 @@ openInterface(char const *ifname, UINT16
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 @@ openInterface(char const *ifname, UINT16
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 @@ openInterface(char const *ifname, UINT16
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 @@ void dlpromisconreq(int fd, u_long level
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 @@ void dlinforeq(int fd)
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 @@ void dlunitdatareq(int fd, u_char *addrp
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 @@ void dlinfoack(int fd, char *bufp)
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 @@ void dlbindreq(int fd, u_long sap, u_lon
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 @@ void dlattachreq(int fd, u_long ppa)
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 @@ void dlokack(int fd, char *bufp)
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 @@ void dlbindack(int fd, char *bufp)
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 @@ void strgetmsg(int fd, struct strbuf *ct
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 @@ void strgetmsg(int fd, struct strbuf *ct
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 -ruNp ppp-2.4.3.orig/pppd/plugins/rp-pppoe/Makefile.linux ppp-2.4.3/pppd/plugins/rp-pppoe/Makefile.linux
837 --- ppp-2.4.3.orig/pppd/plugins/rp-pppoe/Makefile.linux 2004-11-14 08:58:37.000000000 +0100
838 +++ ppp-2.4.3/pppd/plugins/rp-pppoe/Makefile.linux 2005-03-11 01:48:27.000000000 +0100
839 @@ -28,8 +28,8 @@ COPTS=-O2 -g
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 -ruNp ppp-2.4.3.orig/pppd/plugins/rp-pppoe/plugin.c ppp-2.4.3/pppd/plugins/rp-pppoe/plugin.c
851 --- ppp-2.4.3.orig/pppd/plugins/rp-pppoe/plugin.c 2004-11-04 11:07:37.000000000 +0100
852 +++ ppp-2.4.3/pppd/plugins/rp-pppoe/plugin.c 2005-03-11 02:12:39.000000000 +0100
853 @@ -35,7 +35,6 @@ static char const RCSID[] =
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 @@ PPPOEConnectDevice(void)
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 @@ -365,11 +362,9 @@ plugin_init(void)
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 @@ -423,6 +418,7 @@ sysErr(char const *str)
887 {
888 rp_fatal(str);
889 }
890 +#endif
891
892
893 struct channel pppoe_channel = {
894 diff -ruNp ppp-2.4.3.orig/pppd/plugins/rp-pppoe/pppoe-discovery.c ppp-2.4.3/pppd/plugins/rp-pppoe/pppoe-discovery.c
895 --- ppp-2.4.3.orig/pppd/plugins/rp-pppoe/pppoe-discovery.c 2004-11-13 13:12:05.000000000 +0100
896 +++ ppp-2.4.3/pppd/plugins/rp-pppoe/pppoe-discovery.c 2005-03-11 02:06:13.000000000 +0100
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 @@ int main(int argc, char *argv[])
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 @@ int main(int argc, char *argv[])
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 @@ int main(int argc, char *argv[])
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 @@ int main(int argc, char *argv[])
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 -ruNp ppp-2.4.3.orig/pppd/plugins/rp-pppoe/pppoe.h ppp-2.4.3/pppd/plugins/rp-pppoe/pppoe.h
992 --- ppp-2.4.3.orig/pppd/plugins/rp-pppoe/pppoe.h 2004-11-04 11:07:37.000000000 +0100
993 +++ ppp-2.4.3/pppd/plugins/rp-pppoe/pppoe.h 2005-03-11 02:08:00.000000000 +0100
994 @@ -307,12 +307,18 @@ void discovery(PPPoEConnection *conn);
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 -ruNp ppp-2.4.3.orig/pppd/plugins/rp-pppoe/utils.c ppp-2.4.3/pppd/plugins/rp-pppoe/utils.c
1015 --- ppp-2.4.3.orig/pppd/plugins/rp-pppoe/utils.c 1970-01-01 01:00:00.000000000 +0100
1016 +++ ppp-2.4.3/pppd/plugins/rp-pppoe/utils.c 2005-03-11 02:07:57.000000000 +0100
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 +