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
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
|
/* $OpenBSD: print-ppp.c,v 1.32 2018/02/06 03:41:58 dlg Exp $ */
/*
* Copyright (c) 1990, 1991, 1993, 1994, 1995, 1996, 1997
* The Regents of the University of California. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that: (1) source code distributions
* retain the above copyright notice and this paragraph in its entirety, (2)
* distributions including binary code include the above copyright notice and
* this paragraph in its entirety in the documentation or other materials
* provided with the distribution, and (3) all advertising materials mentioning
* features or use of this software display the following acknowledgement:
* ``This product includes software developed by the University of California,
* Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
* the University nor the names of its contributors may be used to endorse
* or promote products derived from this software without specific prior
* written permission.
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*/
#ifdef PPP
#include <sys/time.h>
#include <sys/socket.h>
#include <sys/file.h>
#include <sys/ioctl.h>
struct mbuf;
struct rtentry;
#include <net/if.h>
#include <netinet/in.h>
#include <netinet/ip.h>
#include <ctype.h>
#include <netdb.h>
#include <pcap.h>
#include <signal.h>
#include <stdio.h>
#include <netinet/if_ether.h>
#include "ethertype.h"
#include <net/ppp_defs.h>
#include "interface.h"
#include "addrtoname.h"
#include "extract.h"
#ifndef nitems
#define nitems(_a) (sizeof((_a)) / sizeof((_a)[0]))
#endif
#ifndef PPP_EAP
#define PPP_EAP 0xc227
#endif
#ifndef PPP_CDP
#define PPP_CDP 0x0207
#endif
#ifndef PPP_CDPCP
#define PPP_CDPCP 0x8207
#endif
struct protonames {
u_short protocol;
char *name;
};
static const struct protonames protonames[] = {
/*
* Protocol field values.
*/
{ PPP_IP, "IP" }, /* Internet Protocol */
{ PPP_XNS, "XNS" }, /* Xerox NS */
{ PPP_IPX, "IPX" }, /* IPX Datagram (RFC1552) */
{ PPP_AT, "AppleTalk" }, /* AppleTalk Protocol */
{ PPP_VJC_COMP, "VJC_UNCOMP" }, /* VJ compressed TCP */
{ PPP_VJC_UNCOMP,"VJC_UNCOMP" },/* VJ uncompressed TCP */
{ PPP_IPV6, "IPv6" }, /* Internet Protocol version 6 */
{ PPP_COMP, "COMP" }, /* compressed packet */
{ PPP_IPCP, "IPCP" }, /* IP Control Protocol */
{ PPP_ATCP, "AppleTalkCP" },/* AppleTalk Control Protocol */
{ PPP_IPXCP, "IPXCP" }, /* IPX Control Protocol (RFC1552) */
{ PPP_IPV6CP, "IPV6CP" }, /* IPv6 Control Protocol */
{ PPP_CCP, "CCP" }, /* Compression Control Protocol */
{ PPP_LCP, "LCP" }, /* Link Control Protocol */
{ PPP_PAP, "PAP" }, /* Password Authentication Protocol */
{ PPP_LQR, "LQR" }, /* Link Quality Report protocol */
{ PPP_CBCP, "CBCP" }, /* Callback Control Protocol */
{ PPP_CHAP, "CHAP" }, /* Cryptographic Handshake Auth. Proto */
{ PPP_EAP, "EAP" }, /* Extensible Auth. Protocol */
{ PPP_CDP, "CDP" },
{ PPP_CDPCP, "CDPCP" },
};
struct ppp_control {
uint8_t code;
uint8_t id;
uint16_t len;
};
struct ppp_cp_type {
const char *unkname;
int mincode;
int maxcode;
const char **codes;
};
/* LCP */
#define LCP_CONF_REQ 1
#define LCP_CONF_ACK 2
#define LCP_CONF_NAK 3
#define LCP_CONF_REJ 4
#define LCP_TERM_REQ 5
#define LCP_TERM_ACK 6
#define LCP_CODE_REJ 7
#define LCP_PROT_REJ 8
#define LCP_ECHO_REQ 9
#define LCP_ECHO_RPL 10
#define LCP_DISC_REQ 11
#define LCP_MIN LCP_CONF_REQ
#define LCP_MAX LCP_DISC_REQ
static const char *lcpcodes[] = {
/*
* LCP code values (RFC1661, pp26)
*/
"Configure-Request",
"Configure-Ack",
"Configure-Nak",
"Configure-Reject",
"Terminate-Request",
"Terminate-Ack",
"Code-Reject",
"Protocol-Reject",
"Echo-Request",
"Echo-Reply",
"Discard-Request",
};
#define LCPOPT_VEXT 0
#define LCPOPT_MRU 1
#define LCPOPT_ACCM 2
#define LCPOPT_AP 3
#define LCPOPT_QP 4
#define LCPOPT_MN 5
#define LCPOPT_PFC 7
#define LCPOPT_ACFC 8
#define LCPOPT_MIN 0
#define LCPOPT_MAX 24
static char *lcpconfopts[] = {
"Vendor-Ext",
"Max-Rx-Unit",
"Async-Ctrl-Char-Map",
"Auth-Prot",
"Quality-Prot",
"Magic-Number",
"unassigned (6)",
"Prot-Field-Compr",
"Add-Ctrl-Field-Compr",
"FCS-Alternatives",
"Self-Describing-Pad",
"Numbered-Mode",
"Multi-Link-Procedure",
"Call-Back",
"Connect-Time"
"Compund-Frames",
"Nominal-Data-Encap",
"Multilink-MRRU",
"Multilink-SSNHF",
"Multilink-ED",
"Proprietary",
"DCE-Identifier",
"Multilink-Plus-Proc",
"Link-Discriminator",
"LCP-Auth-Option",
};
/* CHAP */
#define CHAP_CHAL 1
#define CHAP_RESP 2
#define CHAP_SUCC 3
#define CHAP_FAIL 4
#define CHAP_CODEMIN 1
#define CHAP_CODEMAX 4
static const char *chapcode[] = {
"Challenge",
"Response",
"Success",
"Failure",
};
/* PAP */
#define PAP_AREQ 1
#define PAP_AACK 2
#define PAP_ANAK 3
#define PAP_CODEMIN 1
#define PAP_CODEMAX 3
static const char *papcode[] = {
"Authenticate-Request",
"Authenticate-Ack",
"Authenticate-Nak",
};
/* EAP */
#define EAP_CHAL 1
#define EAP_RESP 2
#define EAP_SUCC 3
#define EAP_FAIL 4
#define EAP_CODEMIN EAP_CHAL
#define EAP_CODEMAX EAP_FAIL
#define EAP_TYPE_IDENTITY 1
#define EAP_TYPE_NOTIFICATION 2
#define EAP_TYPE_NAK 3
#define EAP_TYPE_MD5_CHALLENGE 4
#define EAP_TYPE_OTP 5
#define EAP_TYPE_TOKEN 6
#define EAP_TYPEMIN EAP_TYPE_IDENTITY
#define EAP_TYPEMAX EAP_TYPE_TOKEN
static const char *eapcode[] = {
"Challenge",
"Response",
"Success",
"Failure",
};
static const char *eaptype[] = {
"Identity",
"Notification",
"Nak",
"MD5-Challenge",
"One-Time-Password",
"Token",
};
/* IPCP */
#define IPCP_CODE_CFG_REQ 1
#define IPCP_CODE_CFG_ACK 2
#define IPCP_CODE_CFG_NAK 3
#define IPCP_CODE_CFG_REJ 4
#define IPCP_CODE_TRM_REQ 5
#define IPCP_CODE_TRM_ACK 6
#define IPCP_CODE_COD_REJ 7
#define IPCP_CODE_MIN IPCP_CODE_CFG_REQ
#define IPCP_CODE_MAX IPCP_CODE_COD_REJ
#define IPCP_2ADDR 1
#define IPCP_CP 2
#define IPCP_ADDR 3
/* IPV6CP */
#define IPV6CP_CODE_CFG_REQ 1
#define IPV6CP_CODE_CFG_ACK 2
#define IPV6CP_CODE_CFG_NAK 3
#define IPV6CP_CODE_CFG_REJ 4
#define IPV6CP_CODE_TRM_REQ 5
#define IPV6CP_CODE_TRM_ACK 6
#define IPV6CP_CODE_COD_REJ 7
#define IPV6CP_CODE_MIN IPV6CP_CODE_CFG_REQ
#define IPV6CP_CODE_MAX IPV6CP_CODE_COD_REJ
#define IPV6CP_IFID 1
static int print_lcp_config_options(const u_char *p, int);
static void handle_lcp(const u_char *, int);
static void handle_chap(const u_char *p, int);
static void handle_eap(const u_char *p, int);
static void handle_ipcp(const u_char *p, int);
static int print_ipcp_config_options(const u_char *, int);
static void handle_ipv6cp(const u_char *p, int);
static int print_ipv6cp_config_options(const u_char *, int);
static void handle_pap(const u_char *p, int);
struct pppoe_header {
u_int8_t vertype; /* PPPoE version/type */
u_int8_t code; /* PPPoE code (packet type) */
u_int16_t sessionid; /* PPPoE session id */
u_int16_t len; /* PPPoE payload length */
};
#define PPPOE_CODE_SESSION 0x00 /* Session */
#define PPPOE_CODE_PADO 0x07 /* Active Discovery Offer */
#define PPPOE_CODE_PADI 0x09 /* Active Discovery Initiation */
#define PPPOE_CODE_PADR 0x19 /* Active Discovery Request */
#define PPPOE_CODE_PADS 0x65 /* Active Discovery Session-Confirm */
#define PPPOE_CODE_PADT 0xa7 /* Active Discovery Terminate */
#define PPPOE_TAG_END_OF_LIST 0x0000 /* End Of List */
#define PPPOE_TAG_SERVICE_NAME 0x0101 /* Service Name */
#define PPPOE_TAG_AC_NAME 0x0102 /* Access Concentrator Name */
#define PPPOE_TAG_HOST_UNIQ 0x0103 /* Host Uniq */
#define PPPOE_TAG_AC_COOKIE 0x0104 /* Access Concentratr Cookie */
#define PPPOE_TAG_VENDOR_SPEC 0x0105 /* Vendor Specific */
#define PPPOE_TAG_RELAY_SESSION 0x0110 /* Relay Session Id */
#define PPPOE_TAG_MAX_PAYLOAD 0x0120 /* RFC 4638 Max Payload */
#define PPPOE_TAG_SERVICE_NAME_ERROR 0x0201 /* Service Name Error */
#define PPPOE_TAG_AC_SYSTEM_ERROR 0x0202 /* Acc. Concentrator Error */
#define PPPOE_TAG_GENERIC_ERROR 0x0203 /* Generic Error */
static void
ppp_protoname(uint16_t proto)
{
const struct protonames *protoname;
int i;
/* bsearch? */
for (i = 0; i < nitems(protonames); i++) {
protoname = &protonames[i];
if (proto == protoname->protocol) {
printf("%s ", protoname->name);
return;
}
}
printf("unknown-ppp-%04x", proto);
}
void
ppp_print(const u_char *p, u_int length)
{
uint16_t proto;
int l;
l = snapend - p;
if (l < sizeof(proto)) {
printf("[|ppp]");
return;
}
proto = EXTRACT_16BITS(p);
p += sizeof(proto);
l -= sizeof(proto);
length -= sizeof(proto);
if (eflag)
ppp_protoname(proto);
switch (proto) {
case PPP_IP:
ip_print(p, length);
return;
case PPP_IPV6:
ip6_print(p, length);
return;
}
if (!eflag)
ppp_protoname(proto);
switch(proto) {
case PPP_LCP:
handle_lcp(p, l);
break;
case PPP_CHAP:
handle_chap(p, l);
break;
case PPP_EAP:
handle_eap(p, l);
break;
case PPP_PAP:
handle_pap(p, l);
break;
case PPP_IPCP:
handle_ipcp(p, l);
break;
case PPP_IPV6CP:
handle_ipv6cp(p, l);
break;
}
}
static int
ppp_cp_header(struct ppp_control *pc, const u_char *p, int l,
const struct ppp_cp_type *t)
{
uint8_t code;
int off = 0;
int len;
len = sizeof(pc->code);
if (l < len)
return (-1);
pc->code = code = *(p + off);
if (code >= t->mincode && code <= t->maxcode)
printf("%s ", t->codes[code - 1]);
else
printf("unknown-%s-%u ", t->unkname, pc->code);
off = len;
len += sizeof(pc->id);
if (l < len)
return (-1);
pc->id = *(p + off);
printf("Id=0x%02x:", pc->id);
off = len;
len += sizeof(pc->len);
if (l < len)
return (-1);
pc->len = EXTRACT_16BITS(p + off);
return (len);
}
/* print LCP frame */
static const struct ppp_cp_type ppp_cp_lcp = {
"lcp",
LCP_MIN, LCP_MAX,
lcpcodes,
};
static void
handle_lcp(const u_char *p, int l)
{
struct ppp_control pc;
int i;
if (ppp_cp_header(&pc, p, l, &ppp_cp_lcp) == -1)
goto trunc;
if (l > pc.len)
l = pc.len;
p += sizeof(pc);
l -= sizeof(pc);
switch (pc.code) {
case LCP_CONF_REQ:
case LCP_CONF_ACK:
case LCP_CONF_NAK:
case LCP_CONF_REJ:
while (l > 0) {
int optlen;
optlen = print_lcp_config_options(p, l);
if (optlen == -1)
goto trunc;
if (optlen == 0)
break;
p += optlen;
l -= optlen;
}
break;
case LCP_ECHO_REQ:
case LCP_ECHO_RPL:
if (l < 4)
goto trunc;
printf(" Magic-Number=%u", EXTRACT_32BITS(p));
p += 4;
l -= 4;
i = sizeof(pc) + 4;
if (i == pc.len)
break;
printf(" Data=");
do {
if (l == 0)
goto trunc;
printf("%02x", *p);
p++;
l--;
} while (++i < pc.len);
break;
case LCP_TERM_REQ:
case LCP_TERM_ACK:
case LCP_CODE_REJ:
case LCP_PROT_REJ:
case LCP_DISC_REQ:
default:
break;
}
return;
trunc:
printf("[|lcp]");
}
/* LCP config options */
static int
print_lcp_config_options(const u_char *p, int l)
{
uint8_t type, length;
uint16_t proto;
if (l < sizeof(type))
return (-1);
type = p[0];
if (type <= LCPOPT_MAX)
printf(" %s", lcpconfopts[type]);
else
printf(" unknown-lcp-%u", type);
if (l < sizeof(type) + sizeof(length))
return (-1);
length = p[1];
if (length < sizeof(type) + sizeof(length))
return (0);
if (l > length)
l = length;
p += sizeof(type) + sizeof(length);
l -= sizeof(type) + sizeof(length);
switch (type) {
case LCPOPT_MRU:
if (length != 4)
goto invalid;
if (l < 2)
return (-1);
printf("=%u", EXTRACT_16BITS(p));
break;
case LCPOPT_AP:
if (length < 4)
goto invalid;
if (l < sizeof(proto))
return (-1);
proto = EXTRACT_16BITS(p);
switch (proto) {
case PPP_PAP:
printf("=PAP");
break;
case PPP_CHAP:
printf("=CHAP");
if (length < 5)
goto invalid;
p += sizeof(proto);
l -= sizeof(proto);
type = *p;
switch (type) {
case 0x05:
printf("/MD5");
break;
case 0x80:
printf("/Microsoft");
break;
default:
printf("/unknown-algorithm-%02x", type);
break;
}
break;
case PPP_EAP:
printf("=EAP");
break;
case 0xc027:
printf("=SPAP");
break;
case 0xc127:
printf("=Old-SPAP");
break;
default:
printf("=unknown-ap-%04x", proto);
break;
}
break;
case LCPOPT_QP:
if (length < 4)
goto invalid;
if (l < sizeof(proto))
return (-1);
proto = EXTRACT_16BITS(p);
switch (proto) {
case PPP_LQR:
printf(" LQR");
break;
default:
printf(" unknown-qp-%u", proto);
}
break;
case LCPOPT_MN:
if (length < 6)
goto invalid;
if (l < 4)
return (-1);
printf("=%u", EXTRACT_32BITS(p));
break;
case LCPOPT_PFC:
printf(" PFC");
break;
case LCPOPT_ACFC:
printf(" ACFC");
break;
}
return (length);
invalid:
printf(" invalid opt len %u", length);
return (length);
}
/* CHAP */
static const struct ppp_cp_type ppp_cp_chap = {
"chap",
CHAP_CODEMIN, CHAP_CODEMAX,
chapcode,
};
static void
handle_chap(const u_char *p, int l)
{
struct ppp_control pc;
uint8_t vsize;
int i;
if (ppp_cp_header(&pc, p, l, &ppp_cp_chap) == -1)
goto trunc;
if (l > pc.len)
l = pc.len;
p += sizeof(pc);
l -= sizeof(pc);
switch (pc.code) {
case CHAP_CHAL:
case CHAP_RESP:
if (l < sizeof(vsize))
goto trunc;
vsize = *p;
if (vsize < 1) {
printf(" invalid Value-Size");
return;
}
p += sizeof(vsize);
l -= sizeof(vsize);
printf(" Value=");
for (i = 0; i < vsize; i++) {
if (l == 0)
goto trunc;
printf("%02x", *p);
p++;
l--;
}
printf(" Name=");
for (i += sizeof(pc) + sizeof(vsize); i < pc.len; i++) {
if (l == 0)
goto trunc;
safeputchar(*p);
p++;
l--;
}
break;
case CHAP_SUCC:
case CHAP_FAIL:
printf(" Message=");
for (i = sizeof(pc); i < pc.len; i++) {
if (l == 0)
goto trunc;
safeputchar(*p);
p++;
l--;
}
break;
}
return;
trunc:
printf("[|chap]");
}
/* EAP */
static const struct ppp_cp_type ppp_cp_eap = {
"eap",
EAP_CODEMIN, EAP_CODEMAX,
eapcode,
};
static void
handle_eap(const u_char *p, int l)
{
struct ppp_control pc;
uint8_t type, vsize;
int i;
if (ppp_cp_header(&pc, p, l, &ppp_cp_eap) == -1)
goto trunc;
if (l > pc.len)
l = pc.len;
p += sizeof(pc);
l -= sizeof(pc);
switch (pc.code) {
case EAP_CHAL:
case EAP_RESP:
if (l < sizeof(type))
goto trunc;
type = *p;
p += sizeof(type);
l -= sizeof(type);
if (type >= EAP_TYPEMIN && type <= EAP_TYPEMAX)
printf(" %s", eaptype[type - 1]);
else {
printf(" unknown-eap-type-%u", type);
return;
}
switch (type) {
case EAP_TYPE_IDENTITY:
case EAP_TYPE_NOTIFICATION:
case EAP_TYPE_OTP:
i = sizeof(pc) + sizeof(type);
if (i == pc.len)
break;
printf("=");
do {
if (l == 0)
goto trunc;
safeputchar(*p);
p++;
l--;
} while (++i < pc.len);
break;
case EAP_TYPE_NAK:
if (l < sizeof(type))
goto trunc;
type = *p;
if (type >= EAP_TYPEMIN && type <= EAP_TYPEMAX)
printf(" %s", eaptype[type - 1]);
else
printf(" unknown-eap-type-%u", type);
break;
case EAP_TYPE_MD5_CHALLENGE:
if (l < sizeof(vsize))
goto trunc;
vsize = *p;
p += sizeof(vsize);
l -= sizeof(vsize);
printf("=");
for (i = 0; i < vsize; i++) {
if (l == 0)
goto trunc;
printf("%02x", *p);
p++;
l--;
}
break;
}
break;
case CHAP_SUCC:
case CHAP_FAIL:
break;
}
return;
trunc:
printf("[|eap]");
}
/* PAP */
static const struct ppp_cp_type ppp_cp_pap = {
"pap",
PAP_CODEMIN, PAP_CODEMAX,
papcode,
};
static void
handle_pap(const u_char *p, int l)
{
struct ppp_control pc;
uint8_t x;
int i;
if (ppp_cp_header(&pc, p, l, &ppp_cp_pap) == -1)
goto trunc;
if (l > pc.len)
l = pc.len;
p += sizeof(pc);
l -= sizeof(pc);
switch (pc.code) {
case PAP_AREQ:
if (l < sizeof(x)) /* Peer-ID Length */
goto trunc;
x = *p;
p += sizeof(x);
l -= sizeof(x);
printf(" Peer-Id=");
for (i = 0; i < x; i++) {
if (l == 0)
goto trunc;
safeputchar(*p);
p++;
l--;
}
if (l < sizeof(x)) /* Passwd-Length */
goto trunc;
x = *p;
p += sizeof(x);
l -= sizeof(x);
printf(" Passwd=");
for (i = 0; i < x; i++) {
if (l == 0)
goto trunc;
safeputchar(*p);
p++;
l--;
}
break;
case PAP_AACK:
case PAP_ANAK:
if (l < sizeof(x)) /* Msg-Length */
goto trunc;
x = *p;
p += sizeof(x);
l -= sizeof(x);
printf(" Message=");
for (i = 0; i < x; i++) {
if (l == 0)
goto trunc;
safeputchar(*p);
p++;
l--;
}
break;
}
return;
trunc:
printf("[|pap]");
}
/* IPCP */
#define IP_LEN 4
#define IP_FMT "%u.%u.%u.%u"
#define IP_ARG(_p) (_p)[0], (_p)[1], (_p)[2], (_p)[3]
static const struct ppp_cp_type ppp_cp_ipcp = {
"ipcp",
IPCP_CODE_MIN, IPCP_CODE_MAX,
lcpcodes,
};
static void
handle_ipcp(const u_char *p, int l)
{
struct ppp_control pc;
if (ppp_cp_header(&pc, p, l, &ppp_cp_ipcp) == -1)
goto trunc;
if (l > pc.len)
l = pc.len;
p += sizeof(pc);
l -= sizeof(pc);
switch (pc.code) {
case IPCP_CODE_CFG_REQ:
case IPCP_CODE_CFG_ACK:
case IPCP_CODE_CFG_NAK:
case IPCP_CODE_CFG_REJ:
while (l > 0) {
int optlen;
optlen = print_ipcp_config_options(p, l);
if (optlen == -1)
goto trunc;
if (optlen == 0)
break;
p += optlen;
l -= optlen;
}
break;
case IPCP_CODE_TRM_REQ:
case IPCP_CODE_TRM_ACK:
case IPCP_CODE_COD_REJ:
default:
break;
}
return;
trunc:
printf("[|ipcp]");
}
static int
print_ipcp_config_options(const u_char *p, int l)
{
uint8_t type, length;
if (l < sizeof(type))
return (-1);
type = p[0];
switch (type) {
case IPCP_2ADDR:
printf(" IP-Addresses");
break;
case IPCP_CP:
printf(" IP-Compression-Protocol");
break;
case IPCP_ADDR:
printf(" IP-Address");
break;
default:
printf(" ipcp-type-%u", type);
break;
}
if (l < sizeof(type) + sizeof(length))
return (-1);
length = p[1];
p += (sizeof(type) + sizeof(length));
l -= (sizeof(type) + sizeof(length));
switch (type) {
case IPCP_2ADDR:
if (length != 10)
goto invalid;
if (l < IP_LEN)
return (-1);
printf(" Src=" IP_FMT, IP_ARG(p));
p += IP_LEN;
l -= IP_LEN;
if (l < IP_LEN)
return (-1);
printf(" Dst=" IP_FMT, IP_ARG(p));
break;
case IPCP_CP:
if (length < 4)
goto invalid;
if (l < sizeof(type))
return (-1);
type = EXTRACT_16BITS(p);
switch (type) {
case 0x0037:
printf(" Van Jacobsen Compressed TCP/IP");
break;
default:
printf("ipcp-compression-type-%u", type);
break;
}
break;
case IPCP_ADDR:
if (length != 6)
goto invalid;
if (l < IP_LEN)
return (-1);
printf("=" IP_FMT, IP_ARG(p));
break;
}
return (length);
invalid:
printf(" invalid opt len %u", length);
return (length);
}
/* IPV6CP */
static const struct ppp_cp_type ppp_cp_ipv6cp = {
"ipv6cp",
IPV6CP_CODE_MIN, IPV6CP_CODE_MAX,
lcpcodes,
};
static void
handle_ipv6cp(const u_char *p, int l)
{
struct ppp_control pc;
if (ppp_cp_header(&pc, p, l, &ppp_cp_ipv6cp) == -1)
goto trunc;
if (l > pc.len)
l = pc.len;
p += sizeof(pc);
l -= sizeof(pc);
switch (pc.code) {
case IPV6CP_CODE_CFG_REQ:
case IPV6CP_CODE_CFG_ACK:
case IPV6CP_CODE_CFG_NAK:
case IPV6CP_CODE_CFG_REJ:
while (l > 0) {
int optlen;
optlen = print_ipv6cp_config_options(p, l);
if (optlen == -1)
goto trunc;
if (optlen == 0)
break;
p += optlen;
l -= optlen;
}
break;
case IPV6CP_CODE_TRM_REQ:
case IPV6CP_CODE_TRM_ACK:
case IPV6CP_CODE_COD_REJ:
default:
break;
}
return;
trunc:
printf("[|ipv6cp]");
}
static int
print_ipv6cp_config_options(const u_char *p, int l)
{
uint8_t type, length;
if (l < sizeof(type))
return (-1);
type = p[0];
switch (type) {
case IPV6CP_IFID:
printf(" IPv6-Interface-Id");
break;
default:
printf(" ipv6cp-type-%u", type);
break;
}
if (l < sizeof(type) + sizeof(length))
return (-1);
length = p[1];
p += (sizeof(type) + sizeof(length));
l -= (sizeof(type) + sizeof(length));
switch (type) {
case IPV6CP_IFID:
if (length != 10)
goto invalid;
if (l < 8)
return (-1);
printf("=%04x:%04x:%04x:%04x", EXTRACT_16BITS(p + 0),
EXTRACT_16BITS(p + 2), EXTRACT_16BITS(p + 4),
EXTRACT_16BITS(p + 6));
break;
default:
break;
}
return (length);
invalid:
printf(" invalid opt len %u", length);
return (length);
}
void
ppp_if_print(u_char *user, const struct pcap_pkthdr *h, const u_char *p)
{
u_int length = h->len;
u_int caplen = h->caplen;
packetp = p;
snapend = p + caplen;
ts_print(&h->ts);
ppp_hdlc_print(p, length);
if (xflag)
default_print((const u_char *)(p + PPP_HDRLEN),
caplen - PPP_HDRLEN);
putchar('\n');
}
void
ppp_ether_if_print(u_char *user, const struct pcap_pkthdr *h, const u_char *p)
{
u_int16_t pppoe_sid, pppoe_len;
u_int l = h->caplen;
u_int length = h->len;
packetp = p;
snapend = p + l;
ts_print(&h->ts);
if (eflag)
printf("PPPoE ");
if (l < sizeof(struct pppoe_header)) {
printf("[|pppoe]");
return;
}
pppoe_sid = EXTRACT_16BITS(p + 2);
pppoe_len = EXTRACT_16BITS(p + 4);
if (eflag) {
printf("\n\tcode ");
switch (p[1]) {
case PPPOE_CODE_PADI:
printf("Initiation");
break;
case PPPOE_CODE_PADO:
printf("Offer");
break;
case PPPOE_CODE_PADR:
printf("Request");
break;
case PPPOE_CODE_PADS:
printf("Confirm");
break;
case PPPOE_CODE_PADT:
printf("Terminate");
break;
case PPPOE_CODE_SESSION:
printf("Session");
break;
default:
printf("Unknown(0x%02x)", p[1]);
break;
}
printf(", version %d, type %d, id 0x%04x, length %d\n\t",
(p[0] & 0xf), (p[0] & 0xf0) >> 4, pppoe_sid, pppoe_len);
}
if (length < pppoe_len) {
(void)printf(" truncated-pppoe - %d bytes missing!",
pppoe_len - length);
pppoe_len = length;
}
ppp_print(p + sizeof(struct pppoe_header), pppoe_len);
if (xflag)
default_print(p, h->caplen);
putchar('\n');
}
int
pppoe_if_print(u_short ethertype, const u_char *p, u_int length, u_int l)
{
uint16_t pppoe_sid, pppoe_len;
if (ethertype == ETHERTYPE_PPPOEDISC)
printf("PPPoE-Discovery");
else
printf("PPPoE-Session");
if (l < sizeof(struct pppoe_header))
goto trunc;
printf("\n\tcode ");
switch (p[1]) {
case PPPOE_CODE_PADI:
printf("Initiation");
break;
case PPPOE_CODE_PADO:
printf("Offer");
break;
case PPPOE_CODE_PADR:
printf("Request");
break;
case PPPOE_CODE_PADS:
printf("Confirm");
break;
case PPPOE_CODE_PADT:
printf("Terminate");
break;
case PPPOE_CODE_SESSION:
printf("Session");
break;
default:
printf("Unknown(0x%02x)", p[1]);
break;
}
pppoe_sid = EXTRACT_16BITS(p + 2);
pppoe_len = EXTRACT_16BITS(p + 4);
printf(", version %d, type %d, id 0x%04x, length %d",
(p[0] & 0xf), (p[0] & 0xf0) >> 4, pppoe_sid, pppoe_len);
p += sizeof(struct pppoe_header);
l -= sizeof(struct pppoe_header);
length -= sizeof(struct pppoe_header);
if (length < pppoe_len) {
(void)printf(" truncated-pppoe - %d bytes missing!",
pppoe_len - length);
pppoe_len = length;
}
if (l > pppoe_len)
l = pppoe_len;
if (ethertype == ETHERTYPE_PPPOEDISC) {
while (l > 0) {
u_int16_t t_type, t_len;
if (l < 4)
goto trunc;
t_type = EXTRACT_16BITS(p);
t_len = EXTRACT_16BITS(p + 2);
p += 4;
l -= 4;
if (l < t_len)
goto trunc;
printf("\n\ttag ");
switch (t_type) {
case PPPOE_TAG_END_OF_LIST:
printf("End-Of-List");
break;
case PPPOE_TAG_SERVICE_NAME:
printf("Service-Name");
break;
case PPPOE_TAG_AC_NAME:
printf("AC-Name");
break;
case PPPOE_TAG_HOST_UNIQ:
printf("Host-Uniq");
break;
case PPPOE_TAG_AC_COOKIE:
printf("AC-Cookie");
break;
case PPPOE_TAG_VENDOR_SPEC:
printf("Vendor-Specific");
break;
case PPPOE_TAG_RELAY_SESSION:
printf("Relay-Session");
break;
case PPPOE_TAG_MAX_PAYLOAD:
printf("PPP-Max-Payload");
break;
case PPPOE_TAG_SERVICE_NAME_ERROR:
printf("Service-Name-Error");
break;
case PPPOE_TAG_AC_SYSTEM_ERROR:
printf("AC-System-Error");
break;
case PPPOE_TAG_GENERIC_ERROR:
printf("Generic-Error");
break;
default:
printf("Unknown(0x%04x)", t_type);
}
printf(", length %u%s", t_len, t_len ? " " : "");
if (t_len) {
for (t_type = 0; t_type < t_len; t_type++) {
if (isprint(p[t_type]))
printf("%c", p[t_type]);
else
printf("\\%03o", p[t_type]);
}
}
p += t_len;
l -= t_len;
}
} else if (ethertype == ETHERTYPE_PPPOE) {
printf("\n\t");
ppp_print(p, pppoe_len);
}
return (1);
trunc:
printf("[|pppoe]");
return (1);
}
void
ppp_hdlc_print(const u_char *p, u_int length)
{
uint8_t address, control;
int l;
l = snapend - p;
if (l < sizeof(address) + sizeof(control))
goto trunc;
address = p[0];
control = p[1];
p += sizeof(address) + sizeof(control);
l -= sizeof(address) + sizeof(control);
length -= sizeof(address) + sizeof(control);
switch (address) {
case 0xff: /* All-Stations */
if (eflag)
printf("%02x %02x %u ", address, control, length);
if (control != 0x3) {
printf(" discard");
break;
}
ppp_print(p, length);
break;
default:
printf("ppp address 0x%02x unknown", address);
break;
}
return;
trunc:
printf("[|ppp]");
}
void
ppp_hdlc_if_print(u_char *user, const struct pcap_pkthdr *h,
const u_char *p)
{
int l = h->caplen;
packetp = p;
snapend = p + l;
ts_print(&h->ts);
if (eflag)
printf("PPP ");
ppp_hdlc_print(p, h->len);
if (xflag)
default_print(p, l);
printf("\n");
}
#else
#include <sys/types.h>
#include <sys/time.h>
#include <stdio.h>
#include "interface.h"
void
ppp_if_print(user, h, p)
u_char *user;
const struct pcap_pkthdr *h;
const u_char *p;
{
error("not configured for ppp");
/* NOTREACHED */
}
#endif
|