fix make clean for unconfigured build trees
[openwrt.git] / package / ppp / patches / 103-debian_pppoe_cleanup.patch
1 Index: ppp-2.4.3/pppd/plugins/rp-pppoe/common.c
2 ===================================================================
3 --- ppp-2.4.3.orig/pppd/plugins/rp-pppoe/common.c 2007-06-04 13:22:08.391579568 +0200
4 +++ ppp-2.4.3/pppd/plugins/rp-pppoe/common.c 2007-06-04 13:22:09.414424072 +0200
5 @@ -18,10 +18,6 @@
6
7 #include "pppoe.h"
8
9 -#ifdef HAVE_SYSLOG_H
10 -#include <syslog.h>
11 -#endif
12 -
13 #include <string.h>
14 #include <errno.h>
15 #include <stdlib.h>
16 @@ -50,17 +46,17 @@
17 UINT16_t tagType, tagLen;
18
19 if (packet->ver != 1) {
20 - syslog(LOG_ERR, "Invalid PPPoE version (%d)", (int) packet->ver);
21 + error("Invalid PPPoE version (%u)", packet->ver);
22 return -1;
23 }
24 if (packet->type != 1) {
25 - syslog(LOG_ERR, "Invalid PPPoE type (%d)", (int) packet->type);
26 + error("Invalid PPPoE type (%u)", packet->type);
27 return -1;
28 }
29
30 /* Do some sanity checks on packet */
31 if (len > ETH_DATA_LEN - 6) { /* 6-byte overhead for PPPoE header */
32 - syslog(LOG_ERR, "Invalid PPPoE packet length (%u)", len);
33 + error("Invalid PPPoE packet length (%u)", len);
34 return -1;
35 }
36
37 @@ -76,7 +72,7 @@
38 return 0;
39 }
40 if ((curTag - packet->payload) + tagLen + TAG_HDR_SIZE > len) {
41 - syslog(LOG_ERR, "Invalid PPPoE tag length (%u)", tagLen);
42 + error("Invalid PPPoE tag length (%u)", tagLen);
43 return -1;
44 }
45 func(tagType, tagLen, curTag+TAG_HDR_SIZE, extra);
46 @@ -105,17 +101,17 @@
47 UINT16_t tagType, tagLen;
48
49 if (packet->ver != 1) {
50 - syslog(LOG_ERR, "Invalid PPPoE version (%d)", (int) packet->ver);
51 + error("Invalid PPPoE version (%u)", packet->ver);
52 return NULL;
53 }
54 if (packet->type != 1) {
55 - syslog(LOG_ERR, "Invalid PPPoE type (%d)", (int) packet->type);
56 + error("Invalid PPPoE type (%u)", packet->type);
57 return NULL;
58 }
59
60 /* Do some sanity checks on packet */
61 if (len > ETH_DATA_LEN - 6) { /* 6-byte overhead for PPPoE header */
62 - syslog(LOG_ERR, "Invalid PPPoE packet length (%u)", len);
63 + error("Invalid PPPoE packet length (%u)", len);
64 return NULL;
65 }
66
67 @@ -131,7 +127,7 @@
68 return NULL;
69 }
70 if ((curTag - packet->payload) + tagLen + TAG_HDR_SIZE > len) {
71 - syslog(LOG_ERR, "Invalid PPPoE tag length (%u)", tagLen);
72 + error("Invalid PPPoE tag length (%u)", tagLen);
73 return NULL;
74 }
75 if (tagType == type) {
76 @@ -143,6 +139,7 @@
77 return NULL;
78 }
79
80 +#ifdef unused
81 /**********************************************************************
82 *%FUNCTION: printErr
83 *%ARGUMENTS:
84 @@ -158,6 +155,7 @@
85 fprintf(stderr, "pppoe: %s\n", str);
86 syslog(LOG_ERR, "%s", str);
87 }
88 +#endif
89
90
91 /**********************************************************************
92 @@ -172,7 +170,7 @@
93 {
94 char *copy = malloc(strlen(str)+1);
95 if (!copy) {
96 - rp_fatal("strdup failed");
97 + fatal("strdup failed");
98 }
99 strcpy(copy, str);
100 return copy;
101 @@ -467,9 +465,10 @@
102 fprintf(conn->debugFile, "\n");
103 fflush(conn->debugFile);
104 }
105 - syslog(LOG_INFO,"Sent PADT");
106 + info("Sent PADT");
107 }
108
109 +#ifdef unused
110 /**********************************************************************
111 *%FUNCTION: parseLogErrs
112 *%ARGUMENTS:
113 @@ -501,4 +500,5 @@
114 break;
115 }
116 }
117 +#endif
118
119 Index: ppp-2.4.3/pppd/plugins/rp-pppoe/discovery.c
120 ===================================================================
121 --- ppp-2.4.3.orig/pppd/plugins/rp-pppoe/discovery.c 2007-06-04 13:22:09.225452800 +0200
122 +++ ppp-2.4.3/pppd/plugins/rp-pppoe/discovery.c 2007-06-04 13:22:09.414424072 +0200
123 @@ -13,10 +13,6 @@
124
125 #include "pppoe.h"
126
127 -#ifdef HAVE_SYSLOG_H
128 -#include <syslog.h>
129 -#endif
130 -
131 #include <string.h>
132 #include <stdlib.h>
133 #include <errno.h>
134 @@ -167,24 +163,21 @@
135 if (conn->printACNames) {
136 printf("Got a Service-Name-Error tag: %.*s\n", (int) len, data);
137 } else {
138 - syslog(LOG_ERR, "PADO: Service-Name-Error: %.*s", (int) len, data);
139 - exit(1);
140 + fatal("PADO: Service-Name-Error: %.*s", (int) len, data);
141 }
142 break;
143 case TAG_AC_SYSTEM_ERROR:
144 if (conn->printACNames) {
145 printf("Got a System-Error tag: %.*s\n", (int) len, data);
146 } else {
147 - syslog(LOG_ERR, "PADO: System-Error: %.*s", (int) len, data);
148 - exit(1);
149 + fatal("PADO: System-Error: %.*s", (int) len, data);
150 }
151 break;
152 case TAG_GENERIC_ERROR:
153 if (conn->printACNames) {
154 printf("Got a Generic-Error tag: %.*s\n", (int) len, data);
155 } else {
156 - syslog(LOG_ERR, "PADO: Generic-Error: %.*s", (int) len, data);
157 - exit(1);
158 + fatal("PADO: Generic-Error: %.*s", (int) len, data);
159 }
160 break;
161 }
162 @@ -209,20 +202,14 @@
163 PPPoEConnection *conn = (PPPoEConnection *) extra;
164 switch(type) {
165 case TAG_SERVICE_NAME:
166 - syslog(LOG_DEBUG, "PADS: Service-Name: '%.*s'", (int) len, data);
167 + dbglog("PADS: Service-Name: '%.*s'", (int) len, data);
168 break;
169 case TAG_SERVICE_NAME_ERROR:
170 - syslog(LOG_ERR, "PADS: Service-Name-Error: %.*s", (int) len, data);
171 - fprintf(stderr, "PADS: Service-Name-Error: %.*s\n", (int) len, data);
172 - exit(1);
173 + fatal("PADS: Service-Name-Error: %.*s", (int) len, data);
174 case TAG_AC_SYSTEM_ERROR:
175 - syslog(LOG_ERR, "PADS: System-Error: %.*s", (int) len, data);
176 - fprintf(stderr, "PADS: System-Error: %.*s\n", (int) len, data);
177 - exit(1);
178 + fatal("PADS: System-Error: %.*s", (int) len, data);
179 case TAG_GENERIC_ERROR:
180 - syslog(LOG_ERR, "PADS: Generic-Error: %.*s", (int) len, data);
181 - fprintf(stderr, "PADS: Generic-Error: %.*s\n", (int) len, data);
182 - exit(1);
183 + fatal("PADS: Generic-Error: %.*s", (int) len, data);
184 case TAG_RELAY_SESSION_ID:
185 conn->relayId.type = htons(type);
186 conn->relayId.length = htons(len);
187 @@ -336,7 +323,7 @@
188 if (r >= 0 || errno != EINTR) break;
189 }
190 if (r < 0) {
191 - fatalSys("select (waitForPADO)");
192 + fatal("waitForPADO: select: %m");
193 }
194 if (r == 0) return; /* Timed out */
195 }
196 @@ -346,8 +333,7 @@
197
198 /* Check length */
199 if (ntohs(packet.length) + HDR_SIZE > len) {
200 - syslog(LOG_ERR, "Bogus PPPoE length field (%u)",
201 - (unsigned int) ntohs(packet.length));
202 + error("Bogus PPPoE length field (%u)", ntohs(packet.length));
203 continue;
204 }
205
206 @@ -366,16 +352,16 @@
207
208 if (packet.code == CODE_PADO) {
209 if (BROADCAST(packet.ethHdr.h_source)) {
210 - printErr("Ignoring PADO packet from broadcast MAC address");
211 + error("Ignoring PADO packet from broadcast MAC address");
212 continue;
213 }
214 parsePacket(&packet, parsePADOTags, &pc);
215 if (!pc.seenACName) {
216 - printErr("Ignoring PADO packet with no AC-Name tag");
217 + error("Ignoring PADO packet with no AC-Name tag");
218 continue;
219 }
220 if (!pc.seenServiceName) {
221 - printErr("Ignoring PADO packet with no Service-Name tag");
222 + error("Ignoring PADO packet with no Service-Name tag");
223 continue;
224 }
225 conn->numPADOs++;
226 @@ -513,7 +499,7 @@
227 if (r >= 0 || errno != EINTR) break;
228 }
229 if (r < 0) {
230 - fatalSys("select (waitForPADS)");
231 + fatal("waitForPADS: select: %m");
232 }
233 if (r == 0) return;
234 }
235 @@ -523,8 +509,7 @@
236
237 /* Check length */
238 if (ntohs(packet.length) + HDR_SIZE > len) {
239 - syslog(LOG_ERR, "Bogus PPPoE length field (%u)",
240 - (unsigned int) ntohs(packet.length));
241 + error("Bogus PPPoE length field (%u)", ntohs(packet.length));
242 continue;
243 }
244
245 @@ -556,11 +541,12 @@
246 /* Don't bother with ntohs; we'll just end up converting it back... */
247 conn->session = packet.session;
248
249 - syslog(LOG_INFO, "PPP session is %d", (int) ntohs(conn->session));
250 + info("PPP session is %d", ntohs(conn->session));
251
252 /* RFC 2516 says session id MUST NOT be zero or 0xFFFF */
253 if (ntohs(conn->session) == 0 || ntohs(conn->session) == 0xFFFF) {
254 - syslog(LOG_ERR, "Access concentrator used a session value of %x -- the AC is violating RFC 2516", (unsigned int) ntohs(conn->session));
255 + error("Access concentrator used a session value of 0x%x"
256 + " -- the AC is violating RFC 2516", ntohs(conn->session));
257 }
258 }
259
260 @@ -620,7 +606,7 @@
261
262 /* If we're only printing access concentrator names, we're done */
263 if (conn->printACNames) {
264 - die(0);
265 + exit(0);
266 }
267
268 timeout = PADI_TIMEOUT;
269 Index: ppp-2.4.3/pppd/plugins/rp-pppoe/if.c
270 ===================================================================
271 --- ppp-2.4.3.orig/pppd/plugins/rp-pppoe/if.c 2007-06-04 13:22:08.402577896 +0200
272 +++ ppp-2.4.3/pppd/plugins/rp-pppoe/if.c 2007-06-04 13:22:09.416423768 +0200
273 @@ -40,10 +40,6 @@
274 #include <sys/ioctl.h>
275 #endif
276
277 -#ifdef HAVE_SYSLOG_H
278 -#include <syslog.h>
279 -#endif
280 -
281 #include <errno.h>
282 #include <stdlib.h>
283 #include <string.h>
284 @@ -127,7 +123,7 @@
285 {
286 UINT16_t type = (UINT16_t) ntohs(packet->ethHdr.h_proto);
287 if (type != Eth_PPPOE_Discovery && type != Eth_PPPOE_Session) {
288 - syslog(LOG_ERR, "Invalid ether type 0x%x", type);
289 + error("Invalid ethernet type 0x%x", type);
290 }
291 return type;
292 }
293 @@ -156,7 +152,7 @@
294 ifc.ifc_len = sizeof(inbuf);
295 ifc.ifc_buf = inbuf;
296 if (ioctl(sock, SIOCGIFCONF, &ifc) < 0) {
297 - fatalSys("SIOCGIFCONF");
298 + fatal("SIOCGIFCONF: %m");
299 }
300 ifr = ifc.ifc_req;
301 ifreq.ifr_name[0] = '\0';
302 @@ -172,9 +168,7 @@
303 (sdl->sdl_alen == ETH_ALEN) &&
304 !strncmp(ifname, ifr->ifr_name, sizeof(ifr->ifr_name))) {
305 if (found) {
306 - char buffer[256];
307 - sprintf(buffer, "interface %.16s has more than one ethernet address", ifname);
308 - rp_fatal(buffer);
309 + fatal("interface %s has more than one ethernet address", ifname);
310 } else {
311 found = 1;
312 memcpy(hwaddr, LLADDR(sdl), ETH_ALEN);
313 @@ -183,9 +177,7 @@
314 }
315 }
316 if (!found) {
317 - char buffer[256];
318 - sprintf(buffer, "interface %.16s has no ethernet address", ifname);
319 - rp_fatal(buffer);
320 + fatal("interface %s has no ethernet address", ifname);
321 }
322 }
323
324 @@ -252,7 +244,7 @@
325
326 /* Apply the filter */
327 if (ioctl(fd, BIOCSETF, &bpfProgram) < 0) {
328 - fatalSys("ioctl(BIOCSETF)");
329 + fatal("ioctl(BIOCSETF): %m");
330 }
331 }
332 }
333 @@ -298,42 +290,36 @@
334 if (fd < 0) {
335 switch (errno) {
336 case EACCES: /* permission denied */
337 - {
338 - char buffer[256];
339 - sprintf(buffer, "Cannot open %.32s -- pppoe must be run as root.", bpfName);
340 - rp_fatal(buffer);
341 - }
342 + fatal("Cannot open %s -- pppoe must be run as root.", bpfName);
343 break;
344 case EBUSY:
345 case ENOENT: /* no such file */
346 if (i == 0) {
347 - rp_fatal("No /dev/bpf* devices (check your kernel configuration for BPF support)");
348 + fatal("No /dev/bpf* devices (check your kernel configuration for BPF support)");
349 } else {
350 - rp_fatal("All /dev/bpf* devices are in use");
351 + fatal("All /dev/bpf* devices are in use");
352 }
353 break;
354 }
355 - fatalSys(bpfName);
356 + fatal("%s: %m", bpfName);
357 }
358
359 if ((sock = socket(AF_LOCAL, SOCK_DGRAM, 0)) < 0) {
360 - fatalSys("socket");
361 + fatal("socket: %m");
362 }
363
364 /* Check that the interface is up */
365 strncpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
366 if (ioctl(sock, SIOCGIFFLAGS, &ifr) < 0) {
367 - fatalSys("ioctl(SIOCGIFFLAGS)");
368 + fatal("ioctl(SIOCGIFFLAGS): %m");
369 }
370 if ((ifr.ifr_flags & IFF_UP) == 0) {
371 - char buffer[256];
372 - sprintf(buffer, "Interface %.16s is not up\n", ifname);
373 - rp_fatal(buffer);
374 + fatal("Interface %s is not up", ifname);
375 }
376
377 /* Fill in hardware address and initialize the packet filter rules */
378 if (hwaddr == NULL) {
379 - rp_fatal("openInterface: no hwaddr arg.");
380 + fatal("openInterface: no hwaddr arg.");
381 }
382 getHWaddr(sock, ifname, hwaddr);
383 initFilter(fd, type, hwaddr);
384 @@ -342,58 +328,52 @@
385 #if !defined(__OpenBSD__)
386 strncpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
387 if (ioctl(sock, SIOCGIFMTU, &ifr) < 0) {
388 - fatalSys("ioctl(SIOCGIFMTU)");
389 + fatal("ioctl(SIOCGIFMTU): %m");
390 }
391 if (ifr.ifr_mtu < ETH_DATA_LEN) {
392 - char buffer[256];
393 - sprintf(buffer, "Interface %.16s has MTU of %d -- should be %d. You may have serious connection problems.",
394 + error("Interface %s has MTU of %d -- should be %d."
395 + " You may have serious connection problems.",
396 ifname, ifr.ifr_mtu, ETH_DATA_LEN);
397 - printErr(buffer);
398 }
399 #endif
400
401 /* done with the socket */
402 if (close(sock) < 0) {
403 - fatalSys("close");
404 + fatal("close: %m");
405 }
406
407 /* Check the BPF version number */
408 if (ioctl(fd, BIOCVERSION, &bpf_ver) < 0) {
409 - fatalSys("ioctl(BIOCVERSION)");
410 + fatal("ioctl(BIOCVERSION): %m");
411 }
412 if ((bpf_ver.bv_major != BPF_MAJOR_VERSION) ||
413 (bpf_ver.bv_minor < BPF_MINOR_VERSION)) {
414 - char buffer[256];
415 - sprintf(buffer, "Unsupported BPF version: %d.%d (kernel: %d.%d)",
416 + fatal("Unsupported BPF version: %d.%d (kernel: %d.%d)",
417 BPF_MAJOR_VERSION, BPF_MINOR_VERSION,
418 bpf_ver.bv_major, bpf_ver.bv_minor);
419 - rp_fatal(buffer);
420 }
421
422 /* allocate a receive packet buffer */
423 if (ioctl(fd, BIOCGBLEN, &bpfLength) < 0) {
424 - fatalSys("ioctl(BIOCGBLEN)");
425 + fatal("ioctl(BIOCGBLEN): %m");
426 }
427 if (!(bpfBuffer = (unsigned char *) malloc(bpfLength))) {
428 - rp_fatal("malloc");
429 + fatal("malloc");
430 }
431
432 /* reads should return as soon as there is a packet available */
433 optval = 1;
434 if (ioctl(fd, BIOCIMMEDIATE, &optval) < 0) {
435 - fatalSys("ioctl(BIOCIMMEDIATE)");
436 + fatal("ioctl(BIOCIMMEDIATE): %m");
437 }
438
439 /* Bind the interface to the filter */
440 strncpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
441 if (ioctl(fd, BIOCSETIF, &ifr) < 0) {
442 - char buffer[256];
443 - sprintf(buffer, "ioctl(BIOCSETIF) can't select interface %.16s",
444 - ifname);
445 - rp_fatal(buffer);
446 + fatal("ioctl(BIOCSETIF) can't select interface %s: %m", ifname);
447 }
448
449 - syslog(LOG_INFO, "Interface=%.16s HWaddr=%02X:%02X:%02X:%02X:%02X:%02X Device=%.32s Buffer size=%d",
450 + info("Interface=%s HWaddr=%02X:%02X:%02X:%02X:%02X:%02X Device=%s Buffer size=%d",
451 ifname,
452 hwaddr[0], hwaddr[1], hwaddr[2],
453 hwaddr[3], hwaddr[4], hwaddr[5],
454 @@ -442,48 +422,41 @@
455 if ((fd = socket(domain, stype, htons(type))) < 0) {
456 /* Give a more helpful message for the common error case */
457 if (errno == EPERM) {
458 - rp_fatal("Cannot create raw socket -- pppoe must be run as root.");
459 + fatal("Cannot create raw socket -- pppoe must be run as root.");
460 }
461 - fatalSys("socket");
462 + fatal("cannot create the raw socket: %m");
463 }
464
465 if (setsockopt(fd, SOL_SOCKET, SO_BROADCAST, &optval, sizeof(optval)) < 0) {
466 - fatalSys("setsockopt");
467 + fatal("setsockopt(SOL_SOCKET, SO_BROADCAST): %m");
468 }
469
470 /* Fill in hardware address */
471 if (hwaddr) {
472 strncpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
473 - if (ioctl(fd, SIOCGIFHWADDR, &ifr) < 0) {
474 - fatalSys("ioctl(SIOCGIFHWADDR)");
475 - }
476 + if (ioctl(fd, SIOCGIFHWADDR, &ifr) < 0)
477 + fatal("ioctl(SIOCGIFHWADDR): %m");
478 memcpy(hwaddr, ifr.ifr_hwaddr.sa_data, ETH_ALEN);
479 #ifdef ARPHRD_ETHER
480 if (ifr.ifr_hwaddr.sa_family != ARPHRD_ETHER) {
481 - char buffer[256];
482 - sprintf(buffer, "Interface %.16s is not Ethernet", ifname);
483 - rp_fatal(buffer);
484 + fatal("Interface %s is not Ethernet", ifname);
485 }
486 #endif
487 if (NOT_UNICAST(hwaddr)) {
488 - char buffer[256];
489 - sprintf(buffer,
490 - "Interface %.16s has broadcast/multicast MAC address??",
491 + fatal("Interface %s has broadcast/multicast MAC address",
492 ifname);
493 - rp_fatal(buffer);
494 }
495 }
496
497 /* Sanity check on MTU */
498 strncpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
499 if (ioctl(fd, SIOCGIFMTU, &ifr) < 0) {
500 - fatalSys("ioctl(SIOCGIFMTU)");
501 + fatal("ioctl(SIOCGIFMTU): %m");
502 }
503 if (ifr.ifr_mtu < ETH_DATA_LEN) {
504 - char buffer[256];
505 - sprintf(buffer, "Interface %.16s has MTU of %d -- should be %d. You may have serious connection problems.",
506 + error("Interface %s has MTU of %d -- should be %d."
507 + " You may have serious connection problems.",
508 ifname, ifr.ifr_mtu, ETH_DATA_LEN);
509 - printErr(buffer);
510 }
511
512 #ifdef HAVE_STRUCT_SOCKADDR_LL
513 @@ -493,7 +466,7 @@
514
515 strncpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
516 if (ioctl(fd, SIOCGIFINDEX, &ifr) < 0) {
517 - fatalSys("ioctl(SIOCFIGINDEX): Could not get interface index");
518 + fatal("ioctl(SIOCFIGINDEX): Could not get interface index: %m");
519 }
520 sa.sll_ifindex = ifr.ifr_ifindex;
521
522 @@ -503,7 +476,7 @@
523
524 /* We're only interested in packets on specified interface */
525 if (bind(fd, (struct sockaddr *) &sa, sizeof(sa)) < 0) {
526 - fatalSys("bind");
527 + fatal("bind: %m");
528 }
529
530 return fd;
531 @@ -527,13 +500,11 @@
532 {
533 #if defined(USE_BPF)
534 if (write(sock, pkt, size) < 0) {
535 - sysErr("write (sendPacket)");
536 - return -1;
537 + fatal("sendPacket: write: %m");
538 }
539 #elif defined(HAVE_STRUCT_SOCKADDR_LL)
540 if (send(sock, pkt, size, 0) < 0) {
541 - sysErr("send (sendPacket)");
542 - return -1;
543 + fatal("sendPacket: send: %m");
544 }
545 #else
546 #ifdef USE_DLPI
547 @@ -577,12 +548,11 @@
548 struct sockaddr sa;
549
550 if (!conn) {
551 - rp_fatal("relay and server not supported on Linux 2.0 kernels");
552 + fatal("relay and server not supported on Linux 2.0 kernels");
553 }
554 strcpy(sa.sa_data, conn->ifName);
555 if (sendto(sock, pkt, size, 0, &sa, sizeof(sa)) < 0) {
556 - sysErr("sendto (sendPacket)");
557 - return -1;
558 + fatal("sendPacket: sendto: %m");
559 }
560 #endif
561 #endif
562 @@ -632,26 +602,24 @@
563 if (bpfSize <= 0) {
564 bpfOffset = 0;
565 if ((bpfSize = read(sock, bpfBuffer, bpfLength)) < 0) {
566 - sysErr("read (receivePacket)");
567 - return -1;
568 + fatal("receivePacket: read: %m");
569 }
570 }
571 if (bpfSize < sizeof(hdr)) {
572 - syslog(LOG_ERR, "Truncated bpf packet header: len=%d", bpfSize);
573 + error("Truncated bpf packet header: len=%d", bpfSize);
574 clearPacketHeader(pkt); /* resets bpfSize and bpfOffset */
575 return 0;
576 }
577 memcpy(&hdr, bpfBuffer + bpfOffset, sizeof(hdr));
578 if (hdr.bh_caplen != hdr.bh_datalen) {
579 - syslog(LOG_ERR, "Truncated bpf packet: caplen=%d, datalen=%d",
580 + error("Truncated bpf packet: caplen=%d, datalen=%d",
581 hdr.bh_caplen, hdr.bh_datalen);
582 clearPacketHeader(pkt); /* resets bpfSize and bpfOffset */
583 return 0;
584 }
585 seglen = hdr.bh_hdrlen + hdr.bh_caplen;
586 if (seglen > bpfSize) {
587 - syslog(LOG_ERR, "Truncated bpf packet: seglen=%d, bpfSize=%d",
588 - seglen, bpfSize);
589 + error("Truncated bpf packet: seglen=%d, bpfSize=%d", seglen, bpfSize);
590 clearPacketHeader(pkt); /* resets bpfSize and bpfOffset */
591 return 0;
592 }
593 @@ -676,16 +644,14 @@
594 data.len = 0;
595
596 if ((retval = getmsg(sock, NULL, &data, &flags)) < 0) {
597 - sysErr("read (receivePacket)");
598 - return -1;
599 + fatal("receivePacket: getmsg: %m");
600 }
601
602 *size = data.len;
603
604 #else
605 if ((*size = recv(sock, pkt, sizeof(PPPoEPacket), 0)) < 0) {
606 - sysErr("recv (receivePacket)");
607 - return -1;
608 + fatal("receivePacket: recv: %m");
609 }
610 #endif
611 #endif
612 @@ -716,7 +682,7 @@
613 int ppa;
614
615 if(strlen(ifname) > PATH_MAX) {
616 - rp_fatal("socket: string to long");
617 + fatal("openInterface: interface name too long");
618 }
619
620 ppa = atoi(&ifname[strlen(ifname)-1]);
621 @@ -729,9 +695,9 @@
622 if (( fd = open(base_dev, O_RDWR)) < 0) {
623 /* Give a more helpful message for the common error case */
624 if (errno == EPERM) {
625 - rp_fatal("Cannot create raw socket -- pppoe must be run as root.");
626 + fatal("Cannot create raw socket -- pppoe must be run as root.");
627 }
628 - fatalSys("socket");
629 + fatal("open(%s): %m", base_dev);
630 }
631
632 /* rearranged order of DLPI code - delphys 20010803 */
633 @@ -747,17 +713,18 @@
634 dl_abssaplen = ABS(dlp->info_ack.dl_sap_length);
635 dl_saplen = dlp->info_ack.dl_sap_length;
636 if (ETHERADDRL != (dlp->info_ack.dl_addr_length - dl_abssaplen))
637 - fatalSys("invalid destination physical address length");
638 + fatal("invalid destination physical address length");
639 dl_addrlen = dl_abssaplen + ETHERADDRL;
640
641 /* ethernet address retrieved as part of DL_INFO_ACK - delphys 20010803 */
642 memcpy(hwaddr, (u_char*)((char*)(dlp) + (int)(dlp->info_ack.dl_addr_offset)), ETHERADDRL);
643
644 if ( strioctl(fd, DLIOCRAW, -1, 0, NULL) < 0 ) {
645 - fatalSys("DLIOCRAW");
646 + fatal("DLIOCRAW: %m");
647 }
648
649 - if (ioctl(fd, I_FLUSH, FLUSHR) < 0) fatalSys("I_FLUSH");
650 + if (ioctl(fd, I_FLUSH, FLUSHR) < 0)
651 + fatal("I_FLUSH: %m");
652
653 return fd;
654 }
655 @@ -780,7 +747,7 @@
656 flags = 0;
657
658 if (putmsg(fd, &ctl, (struct strbuf*) NULL, flags) < 0)
659 - fatalSys("dlpromiscon: putmsg");
660 + fatal("dlpromiscon: putmsg: %m");
661
662 }
663
664 @@ -799,7 +766,7 @@
665 flags = RS_HIPRI;
666
667 if (putmsg(fd, &ctl, (struct strbuf*) NULL, flags) < 0)
668 - fatalSys("dlinforeq: putmsg");
669 + fatal("dlinforeq: putmsg: %m");
670 }
671
672 void dlunitdatareq(int fd, u_char *addrp, int addrlen, u_long minpri, u_long maxpri, u_char *datap, int datalen)
673 @@ -827,7 +794,7 @@
674 data.buf = (char *) datap;
675
676 if (putmsg(fd, &ctl, &data, 0) < 0)
677 - fatalSys("dlunitdatareq: putmsg");
678 + fatal("dlunitdatareq: putmsg: %m");
679 }
680
681 void dlinfoack(int fd, char *bufp)
682 @@ -847,18 +814,14 @@
683 expecting(DL_INFO_ACK, dlp);
684
685 if (ctl.len < sizeof (dl_info_ack_t)) {
686 - char buffer[256];
687 - sprintf(buffer, "dlinfoack: response ctl.len too short: %d", ctl.len);
688 - rp_fatal(buffer);
689 + fatal("dlinfoack: response ctl.len too short: %d", ctl.len);
690 }
691
692 if (flags != RS_HIPRI)
693 - rp_fatal("dlinfoack: DL_INFO_ACK was not M_PCPROTO");
694 + fatal("dlinfoack: DL_INFO_ACK was not M_PCPROTO");
695
696 if (ctl.len < sizeof (dl_info_ack_t)) {
697 - char buffer[256];
698 - sprintf(buffer, "dlinfoack: short response ctl.len: %d", ctl.len);
699 - rp_fatal(buffer);
700 + fatal("dlinfoack: short response ctl.len: %d", ctl.len);
701 }
702 }
703
704 @@ -882,7 +845,7 @@
705 flags = 0;
706
707 if (putmsg(fd, &ctl, (struct strbuf*) NULL, flags) < 0)
708 - fatalSys("dlbindreq: putmsg");
709 + fatal("dlbindreq: putmsg: %m");
710 }
711
712 void dlattachreq(int fd, u_long ppa)
713 @@ -901,7 +864,7 @@
714 flags = 0;
715
716 if (putmsg(fd, &ctl, (struct strbuf*) NULL, flags) < 0)
717 - fatalSys("dlattachreq: putmsg");
718 + fatal("dlattachreq: putmsg: %m");
719 }
720
721 void dlokack(int fd, char *bufp)
722 @@ -921,18 +884,14 @@
723 expecting(DL_OK_ACK, dlp);
724
725 if (ctl.len < sizeof (dl_ok_ack_t)) {
726 - char buffer[256];
727 - sprintf(buffer, "dlokack: response ctl.len too short: %d", ctl.len);
728 - rp_fatal(buffer);
729 + fatal("dlokack: response ctl.len too short: %d", ctl.len);
730 }
731
732 if (flags != RS_HIPRI)
733 - rp_fatal("dlokack: DL_OK_ACK was not M_PCPROTO");
734 + fatal("dlokack: DL_OK_ACK was not M_PCPROTO");
735
736 if (ctl.len < sizeof (dl_ok_ack_t)) {
737 - char buffer[256];
738 - sprintf(buffer, "dlokack: short response ctl.len: %d", ctl.len);
739 - rp_fatal(buffer);
740 + fatal("dlokack: short response ctl.len: %d", ctl.len);
741 }
742 }
743
744 @@ -953,12 +912,10 @@
745 expecting(DL_BIND_ACK, dlp);
746
747 if (flags != RS_HIPRI)
748 - rp_fatal("dlbindack: DL_OK_ACK was not M_PCPROTO");
749 + fatal("dlbindack: DL_OK_ACK was not M_PCPROTO");
750
751 if (ctl.len < sizeof (dl_bind_ack_t)) {
752 - char buffer[256];
753 - sprintf(buffer, "dlbindack: short response ctl.len: %d", ctl.len);
754 - rp_fatal(buffer);
755 + fatal("dlbindack: short response ctl.len: %d", ctl.len);
756 }
757 }
758
759 @@ -989,8 +946,7 @@
760 */
761 (void) signal(SIGALRM, sigalrm);
762 if (alarm(MAXWAIT) < 0) {
763 - (void) sprintf(errmsg, "%s: alarm", caller);
764 - fatalSys(errmsg);
765 + fatal("%s: alarm", caller);
766 }
767
768 /*
769 @@ -998,61 +954,48 @@
770 */
771 *flagsp = 0;
772 if ((rc = getmsg(fd, ctlp, datap, flagsp)) < 0) {
773 - (void) sprintf(errmsg, "%s: getmsg", caller);
774 - fatalSys(errmsg);
775 + fatal(errmsg, "%s: getmsg: %m", caller);
776 }
777
778 /*
779 * Stop timer.
780 */
781 if (alarm(0) < 0) {
782 - (void) sprintf(errmsg, "%s: alarm", caller);
783 - fatalSys(errmsg);
784 + fatal("%s: alarm", caller);
785 }
786
787 /*
788 * Check for MOREDATA and/or MORECTL.
789 */
790 if ((rc & (MORECTL | MOREDATA)) == (MORECTL | MOREDATA)) {
791 - char buffer[256];
792 - sprintf(buffer, "%s: MORECTL|MOREDATA", caller);
793 - rp_fatal(buffer);
794 + fatal("%s: MORECTL|MOREDATA", caller);
795 }
796
797 if (rc & MORECTL) {
798 - char buffer[256];
799 - sprintf(buffer, "%s: MORECTL", caller);
800 - rp_fatal(buffer);
801 + fatal("%s: MORECTL", caller);
802 }
803
804 if (rc & MOREDATA) {
805 - char buffer[256];
806 - sprintf(buffer, "%s: MOREDATA", caller);
807 - rp_fatal(buffer);
808 + fatal("%s: MOREDATA", caller);
809 }
810
811 /*
812 * Check for at least sizeof (long) control data portion.
813 */
814 if (ctlp->len < sizeof (long)) {
815 - char buffer[256];
816 - sprintf(buffer, "getmsg: control portion length < sizeof (long): %d", ctlp->len);
817 - rp_fatal(buffer);
818 + fatal("getmsg: control portion length < sizeof (long): %d", ctlp->len);
819 }
820 }
821
822 void sigalrm(int sig)
823 {
824 - (void) rp_fatal("sigalrm: TIMEOUT");
825 + fatal("sigalrm: TIMEOUT");
826 }
827
828 void expecting(int prim, union DL_primitives *dlp)
829 {
830 if (dlp->dl_primitive != (u_long)prim) {
831 - char buffer[256];
832 - sprintf(buffer, "expected %s got %s", dlprim(prim), dlprim(dlp->dl_primitive));
833 - rp_fatal(buffer);
834 - exit(1);
835 + fatal("expected %s got %s", dlprim(prim), dlprim(dlp->dl_primitive));
836 }
837 }
838
839 Index: ppp-2.4.3/pppd/plugins/rp-pppoe/Makefile.linux
840 ===================================================================
841 --- ppp-2.4.3.orig/pppd/plugins/rp-pppoe/Makefile.linux 2007-06-04 13:22:08.408576984 +0200
842 +++ ppp-2.4.3/pppd/plugins/rp-pppoe/Makefile.linux 2007-06-04 13:22:09.416423768 +0200
843 @@ -28,8 +28,8 @@
844 CFLAGS=$(COPTS) -I../../../include/linux
845 all: rp-pppoe.so pppoe-discovery
846
847 -pppoe-discovery: libplugin.a pppoe-discovery.o
848 - $(CC) -o pppoe-discovery pppoe-discovery.o libplugin.a
849 +pppoe-discovery: pppoe-discovery.o utils.o libplugin.a
850 + $(CC) -o pppoe-discovery pppoe-discovery.o utils.o libplugin.a
851
852 pppoe-discovery.o: pppoe-discovery.c
853 $(CC) $(CFLAGS) '-DVERSION="$(VERSION)"' -c -o pppoe-discovery.o pppoe-discovery.c
854 Index: ppp-2.4.3/pppd/plugins/rp-pppoe/plugin.c
855 ===================================================================
856 --- ppp-2.4.3.orig/pppd/plugins/rp-pppoe/plugin.c 2007-06-04 13:22:08.414576072 +0200
857 +++ ppp-2.4.3/pppd/plugins/rp-pppoe/plugin.c 2007-06-04 13:22:09.417423616 +0200
858 @@ -35,7 +35,6 @@
859 #include "pppd/pathnames.h"
860
861 #include <linux/types.h>
862 -#include <syslog.h>
863 #include <sys/ioctl.h>
864 #include <sys/types.h>
865 #include <sys/socket.h>
866 @@ -173,10 +172,8 @@
867 (unsigned) conn->peerEth[5]);
868
869 if (connect(conn->sessionSocket, (struct sockaddr *) &sp,
870 - sizeof(struct sockaddr_pppox)) < 0) {
871 + sizeof(struct sockaddr_pppox)) < 0)
872 fatal("Failed to connect PPPoE socket: %d %m", errno);
873 - return -1;
874 - }
875
876 return conn->sessionSocket;
877 }
878 @@ -365,11 +362,9 @@
879 }
880
881 add_options(Options);
882 -
883 - info("RP-PPPoE plugin version %s compiled against pppd %s",
884 - RP_VERSION, VERSION);
885 }
886
887 +#ifdef unused
888 /**********************************************************************
889 *%FUNCTION: fatalSys
890 *%ARGUMENTS:
891 @@ -423,6 +418,7 @@
892 {
893 rp_fatal(str);
894 }
895 +#endif
896
897
898 struct channel pppoe_channel = {
899 Index: ppp-2.4.3/pppd/plugins/rp-pppoe/pppoe-discovery.c
900 ===================================================================
901 --- ppp-2.4.3.orig/pppd/plugins/rp-pppoe/pppoe-discovery.c 2007-06-04 13:22:08.420575160 +0200
902 +++ ppp-2.4.3/pppd/plugins/rp-pppoe/pppoe-discovery.c 2007-06-04 13:22:09.417423616 +0200
903 @@ -17,14 +17,8 @@
904
905 #include "pppoe.h"
906
907 -char *xstrdup(const char *s);
908 void usage(void);
909
910 -void die(int status)
911 -{
912 - exit(status);
913 -}
914 -
915 int main(int argc, char *argv[])
916 {
917 int opt;
918 @@ -32,17 +26,17 @@
919
920 conn = malloc(sizeof(PPPoEConnection));
921 if (!conn)
922 - fatalSys("malloc");
923 + fatal("malloc");
924
925 memset(conn, 0, sizeof(PPPoEConnection));
926
927 while ((opt = getopt(argc, argv, "I:D:VUAS:C:h")) > 0) {
928 switch(opt) {
929 case 'S':
930 - conn->serviceName = xstrdup(optarg);
931 + conn->serviceName = strDup(optarg);
932 break;
933 case 'C':
934 - conn->acName = xstrdup(optarg);
935 + conn->acName = strDup(optarg);
936 break;
937 case 'U':
938 conn->useHostUniq = 1;
939 @@ -57,7 +51,7 @@
940 fprintf(conn->debugFile, "pppoe-discovery %s\n", VERSION);
941 break;
942 case 'I':
943 - conn->ifName = xstrdup(optarg);
944 + conn->ifName = strDup(optarg);
945 break;
946 case 'A':
947 /* this is the default */
948 @@ -74,7 +68,7 @@
949
950 /* default interface name */
951 if (!conn->ifName)
952 - conn->ifName = strdup("eth0");
953 + conn->ifName = strDup("eth0");
954
955 conn->discoverySocket = -1;
956 conn->sessionSocket = -1;
957 @@ -84,39 +78,6 @@
958 exit(0);
959 }
960
961 -void rp_fatal(char const *str)
962 -{
963 - char buf[1024];
964 -
965 - printErr(str);
966 - sprintf(buf, "pppoe-discovery: %.256s", str);
967 - exit(1);
968 -}
969 -
970 -void fatalSys(char const *str)
971 -{
972 - char buf[1024];
973 - int i = errno;
974 -
975 - sprintf(buf, "%.256s: %.256s", str, strerror(i));
976 - printErr(buf);
977 - sprintf(buf, "pppoe-discovery: %.256s: %.256s", str, strerror(i));
978 - exit(1);
979 -}
980 -
981 -void sysErr(char const *str)
982 -{
983 - rp_fatal(str);
984 -}
985 -
986 -char *xstrdup(const char *s)
987 -{
988 - register char *ret = strdup(s);
989 - if (!ret)
990 - sysErr("strdup");
991 - return ret;
992 -}
993 -
994 void usage(void)
995 {
996 fprintf(stderr, "Usage: pppoe-discovery [options]\n");
997 Index: ppp-2.4.3/pppd/plugins/rp-pppoe/pppoe.h
998 ===================================================================
999 --- ppp-2.4.3.orig/pppd/plugins/rp-pppoe/pppoe.h 2007-06-04 13:22:08.426574248 +0200
1000 +++ ppp-2.4.3/pppd/plugins/rp-pppoe/pppoe.h 2007-06-04 13:22:09.418423464 +0200
1001 @@ -307,12 +307,18 @@
1002 unsigned char *findTag(PPPoEPacket *packet, UINT16_t tagType,
1003 PPPoETag *tag);
1004
1005 +void dbglog(char *, ...); /* log a debug message */
1006 +void info(char *, ...); /* log an informational message */
1007 +void warn(char *, ...); /* log a warning message */
1008 +void error(char *, ...); /* log an error message */
1009 +void fatal(char *, ...); /* log an error message and die(1) */
1010 +
1011 #define SET_STRING(var, val) do { if (var) free(var); var = strDup(val); } while(0);
1012
1013 #define CHECK_ROOM(cursor, start, len) \
1014 do {\
1015 if (((cursor)-(start))+(len) > MAX_PPPOE_PAYLOAD) { \
1016 - syslog(LOG_ERR, "Would create too-long packet"); \
1017 + error("Would create too-long packet"); \
1018 return; \
1019 } \
1020 } while(0)
1021 Index: ppp-2.4.3/pppd/plugins/rp-pppoe/utils.c
1022 ===================================================================
1023 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
1024 +++ ppp-2.4.3/pppd/plugins/rp-pppoe/utils.c 2007-06-04 13:22:09.418423464 +0200
1025 @@ -0,0 +1,62 @@
1026 +#include <stdio.h>
1027 +#include <stdlib.h>
1028 +#include <unistd.h>
1029 +#include <stdarg.h>
1030 +#include <syslog.h>
1031 +
1032 +void dbglog(const char *fmt, ...)
1033 +{
1034 + va_list ap;
1035 +
1036 + va_start(ap, fmt);
1037 + vsyslog(LOG_DEBUG, fmt, ap);
1038 + vfprintf(stderr, fmt, ap);
1039 + fputs("\n", stderr);
1040 + va_end(ap);
1041 +}
1042 +
1043 +void info(const char *fmt, ...)
1044 +{
1045 + va_list ap;
1046 +
1047 + va_start(ap, fmt);
1048 + vsyslog(LOG_INFO, fmt, ap);
1049 + vfprintf(stderr, fmt, ap);
1050 + fputs("\n", stderr);
1051 + va_end(ap);
1052 +}
1053 +
1054 +void warn(const char *fmt, ...)
1055 +{
1056 + va_list ap;
1057 +
1058 + va_start(ap, fmt);
1059 + vsyslog(LOG_WARNING, fmt, ap);
1060 + vfprintf(stderr, fmt, ap);
1061 + fputs("\n", stderr);
1062 + va_end(ap);
1063 +}
1064 +
1065 +void error(const char *fmt, ...)
1066 +{
1067 + va_list ap;
1068 +
1069 + va_start(ap, fmt);
1070 + vsyslog(LOG_ERR, fmt, ap);
1071 + vfprintf(stderr, fmt, ap);
1072 + fputs("\n", stderr);
1073 + va_end(ap);
1074 +}
1075 +
1076 +void fatal(const char *fmt, ...)
1077 +{
1078 + va_list ap;
1079 +
1080 + va_start(ap, fmt);
1081 + vsyslog(LOG_ERR, fmt, ap);
1082 + vfprintf(stderr, fmt, ap);
1083 + fputs("\n", stderr);
1084 + va_end(ap);
1085 + exit(1);
1086 +}
1087 +
This page took 0.094763 seconds and 5 git commands to generate.