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