Annotation of embedaddon/mpd/src/proto.c, revision 1.1.1.1

1.1       misho       1: 
                      2: /*
                      3:  * proto.c
                      4:  *
                      5:  * Written by Archie Cobbs <archie@freebsd.org>
                      6:  * Copyright (c) 1995-1999 Whistle Communications, Inc. All rights reserved.
                      7:  * See ``COPYRIGHT.whistle''
                      8:  */
                      9: 
                     10: #include "ppp.h"
                     11: 
                     12: /*
                     13:  * DEFINITIONS
                     14:  */
                     15: 
                     16:   /* Protocol number <-> name mapping */
                     17:   struct protoname {
                     18:     u_short    proto;
                     19:     const char *name;
                     20:   };
                     21: 
                     22: /*
                     23:  * INTERNAL VARIABLES
                     24:  */
                     25: 
                     26:   /* These are protocols we use and keep stats on */
                     27:   static const struct protoname statProtos[] = {
                     28:     { 0,               "Unknown" },
                     29:     { PROTO_IP,                "IP" },
                     30:     { PROTO_VJUNCOMP,  "VJUNCOMP" },
                     31:     { PROTO_VJCOMP,    "VJCOMP" },
                     32:     { PROTO_IPV6,      "IPv6" },
                     33:     { PROTO_MP,                "MP" },
                     34:     { PROTO_IPCP,      "IPCP" },
                     35:     { PROTO_IPV6CP,    "IPV6CP" },
                     36:     { PROTO_ICOMPD,    "ICOMPD" },
                     37:     { PROTO_COMPD,     "COMPD" },
                     38:     { PROTO_ICCP,      "ICCP" },
                     39:     { PROTO_CCP,       "CCP" },
                     40:     { PROTO_LCP,       "LCP" },
                     41:     { PROTO_PAP,       "PAP" },
                     42:     { PROTO_LQR,       "LQR" },
                     43:     { PROTO_CHAP,      "CHAP" },
                     44:     { PROTO_ICRYPT,    "ICRYPT" },
                     45:     { PROTO_CRYPT,     "CRYPT" },
                     46:     { PROTO_IECP,      "IECP" },
                     47:     { PROTO_ECP,       "ECP" },
                     48:     { PROTO_SPAP,      "SPAP" },
                     49:     { PROTO_ATCP,      "ATCP" },
                     50:     { PROTO_EAP,       "EAP" },
                     51:   };
                     52:   #define NUM_STAT_PROTOCOLS   (sizeof(statProtos) / sizeof(*statProtos))
                     53: 
                     54: /*
                     55:  * These are other protocols we recognize but don't use
                     56:  * Reference: ftp://ftp.isi.edu/in-notes/iana/assignments/ppp-numbers
                     57:  */
                     58: 
                     59:   static const struct protoname protoNames[] = {
                     60: #ifdef PROTO_NAME_LIST
                     61: 
                     62: /* Network layer protocols */
                     63:     { 0x0001,  "Padding Protocol" },
                     64:     { 0x0021,  "Internet Protocol" },
                     65:     { 0x0023,  "OSI Network Layer" },
                     66:     { 0x0025,  "Xerox NS IDP" },
                     67:     { 0x0027,  "DECnet Phase IV" },
                     68:     { 0x0029,  "Appletalk" },
                     69:     { 0x002b,  "Novell IPX" },
                     70:     { 0x002d,  "Van Jacobson Compressed TCP/IP" },
                     71:     { 0x002f,  "Van Jacobson Uncompressed TCP/IP" },
                     72:     { 0x0031,  "Bridging PDU" },
                     73:     { 0x0033,  "Stream Protocol (ST-II)" },
                     74:     { 0x0035,  "Banyan Vines" },
                     75:     { 0x0037,  "reserved (until 1993)" },
                     76:     { 0x0039,  "AppleTalk EDDP" },
                     77:     { 0x003b,  "AppleTalk SmartBuffered" },
                     78:     { 0x003d,  "Multi-Link" },
                     79:     { 0x003f,  "NETBIOS Framing" },
                     80:     { 0x0041,  "Cisco Systems" },
                     81:     { 0x0043,  "Ascom Timeplex" },
                     82:     { 0x0045,  "Fujitsu Link Backup and Load Balancing (LBLB)" },
                     83:     { 0x0047,  "DCA Remote Lan" },
                     84:     { 0x0049,  "Serial Data Transport Protocol (PPP-SDTP)" },
                     85:     { 0x004b,  "SNA over 802.2" },
                     86:     { 0x004d,  "SNA" },
                     87:     { 0x004f,  "IP6 Header Compression" },
                     88:     { 0x0051,  "KNX Bridging Data" },
                     89:     { 0x0053,  "Encryption" },
                     90:     { 0x0055,  "Individual Link Encryption" },
                     91:     { 0x0057,  "IPv6 over PPP" },
                     92:     { 0x0059,  "PPP Multiplexing (RFC 3153)" },
                     93:     { 0x005b,  "Vendor-Specific Network Protocol" },
                     94:     { 0x005d,  "TRILL Network Protocol (TNP)" },
                     95:     { 0x0061,  "RTP IPHC Full Header" },
                     96:     { 0x0063,  "RTP IPHC Compressed TCP" },
                     97:     { 0x0065,  "RTP IPHC Compressed Non TCP" },
                     98:     { 0x0067,  "RTP IPHC Compressed UDP 8" },
                     99:     { 0x0069,  "RTP IPHC Compressed RTP 8" },
                    100:     { 0x006f,  "Stampede Bridging" },
                    101:     { 0x0071,  "BAP Bandwidth Allocation Protocol" },
                    102:     { 0x0073,  "MP+ Protocol" },
                    103:     { 0x007d,  "reserved (Control Escape) (RFC 1661)" },
                    104:     { 0x007f,  "reserved (compression inefficient) (RFC 1662)" },
                    105:     { 0x00c1,  "NTCITS IPI" },
                    106:     { 0x00cf,  "reserved (PPP NLPID)" },
                    107:     { 0x00fb,  "compression on single link in multilink group" },
                    108:     { 0x00fd,  "1st choice compression (RFC 1962)" },
                    109:     { 0x00ff,  "reserved" },
                    110: 
                    111:     { 0x0201,  "802.1d Hello Packets (RFC 1220)" },
                    112:     { 0x0203,  "IBM Source Routing BPDU" },
                    113:     { 0x0205,  "DEC LANBridge100 Spanning Tree" },
                    114:     { 0x0207,  "Cisco Discovery Protocol" },
                    115:     { 0x0209,  "Netcs Twin Routing" },
                    116:     { 0x0211,  "Optical Supervisory Channel Protocol (OSCP)" },
                    117:     { 0x0213,  "Optical Supervisory Channel Protocol (OSCP)" },
                    118:     { 0x0231,  "Luxcom" },
                    119:     { 0x0233,  "Sigma Network Systems" },
                    120:     { 0x0235,  "Apple Client Server Protocol" },
                    121:     { 0x0281,  "MPLS Unicast" },
                    122:     { 0x0283,  "MPLS Multicast" },
                    123:     { 0x0285,  "IEEE p1284.4 standard - data packets" },
                    124:     { 0x0287,  "ETSI TETRA Network Protocol Type 1" },
                    125:     { 0x0289,  "Multichannel Flow Treatment Protocol" },
                    126: 
                    127:     { 0x2063,  "RTP IPHC Compressed TCP No Delta" },
                    128:     { 0x2065,  "RTP IPHC Context State" },
                    129:     { 0x2067,  "RTP IPHC Compressed UDP 16" },
                    130:     { 0x2069,  "RTP IPHC Compressed RTP 16" },
                    131: 
                    132:     { 0x4001,  "Cray Communications Control Protocol" },
                    133:     { 0x4003,  "CDPD Mobile Network Registration Protocol" },
                    134:     { 0x4021,  "Stacker LZS" },
                    135: 
                    136: /* Network layer control protocols */
                    137: 
                    138:     { 0x8021,  "Internet Protocol Control Protocol" },
                    139:     { 0x8023,  "OSI Network Layer Control Protocol" },
                    140:     { 0x8025,  "Xerox NS IDP Control Protocol" },
                    141:     { 0x8027,  "DECnet Phase IV Control Protocol" },
                    142:     { 0x8029,  "Appletalk Control Protocol" },
                    143:     { 0x802b,  "Novell IPX Control Protocol" },
                    144:     { 0x802d,  "reserved" },
                    145:     { 0x802f,  "reserved" },
                    146:     { 0x8031,  "Bridging NCP" },
                    147:     { 0x8033,  "Stream Protocol Control Protocol" },
                    148:     { 0x8035,  "Banyan Vines Control Protocol" },
                    149:     { 0x8037,  "reserved till 1993" },
                    150:     { 0x8039,  "reserved" },
                    151:     { 0x803b,  "reserved" },
                    152:     { 0x803d,  "Multi-Link Control Protocol" },
                    153:     { 0x803f,  "NETBIOS Framing Control Protocol" },
                    154:     { 0x8041,  "Cisco Systems Control Protocol" },
                    155:     { 0x8043,  "Ascom Timeplex" },
                    156:     { 0x8045,  "Fujitsu LBLB Control Protocol" },
                    157:     { 0x8047,  "DCA Remote Lan Network Control Protocol (RLNCP)" },
                    158:     { 0x8049,  "Serial Data Control Protocol (PPP-SDCP)" },
                    159:     { 0x804b,  "SNA over 802.2 Control Protocol" },
                    160:     { 0x804d,  "SNA Control Protocol" },
                    161:     { 0x804f,  "IP6 Header Compression Control Protocol" },
                    162:     { 0x8051,  "KNX Bridging Control Protocol" },
                    163:     { 0x8053,  "Encryption Control Protocol" },
                    164:     { 0x8055,  "Individual Link Encryption Control Protocol" },
                    165:     { 0x8057,  "IPv6 PPP Control Protocol" },
                    166:     { 0x806f,  "Stampede Bridging Control Protocol" },
                    167:     { 0x8071,  "BACP Bandwidth Allocation Control Protocol" },
                    168:     { 0x8073,  "MP+ Control Protocol" },
                    169:     { 0x807d,  "Not Used - reserved" },
                    170:     { 0x80c1,  "NTCITS IPI Control Protocol" },
                    171:     { 0x80cf,  "Not Used - reserved" },
                    172:     { 0x80fb,  "compression on single link in multilink group control" },
                    173:     { 0x80fd,  "Compression Control Protocol" },
                    174:     { 0x80ff,  "Not Used - reserved" },
                    175: 
                    176:     { 0x8207,  "Cisco Discovery Protocol Control" },
                    177:     { 0x8209,  "Netcs Twin Routing" },
                    178:     { 0x820b,  "STP - Control Protocol" },
                    179:     { 0x820d,  "EDPCP - Extreme Discovery Protocol Ctrl Prtcl" },
                    180:     { 0x8235,  "Apple Client Server Protocol Control" },
                    181:     { 0x8281,  "MPLS Control Protocol (RFC 3032)" },
                    182:     { 0x8283,  "Tag Switching - Multicast" },
                    183:     { 0x8285,  "IEEE p1284.4 standard - Protocol Control" },
                    184:     { 0x8287,  "ETSI TETRA NSP1 Control Protocol" },
                    185:     { 0x8289,  "Multichannel Flow Treatment Protocol" },
                    186: 
                    187: /* Link layer control protocols */
                    188: 
                    189:     { 0xc021,  "Link Control Protocol" },
                    190:     { 0xc023,  "Password Authentication Protocol" },
                    191:     { 0xc025,  "Link Quality Report" },
                    192:     { 0xc027,  "Shiva Password Authentication Protocol" },
                    193:     { 0xc029,  "CallBack Control Protocol (CBCP)" },
                    194:     { 0xc02B,  "PPP Bandwidth Allocation Control Protocol (RFC 2125)" },
                    195:     { 0xc02D,  "PPP Bandwidth Allocation Protocol (RFC 2125)" },
                    196:     { 0xc05B,  "Vendor-Specific Authentication Protocol (RFC 3772)" },
                    197:     { 0xc081,  "Container Control Protocol", },
                    198:     { 0xc223,  "Challenge Handshake Authentication Protocol" },
                    199:     { 0xc225,  "RSA Authentication Protocol" },
                    200:     { 0xc227,  "Extensible Authentication Protocol" },
                    201:     { 0xc26f,  "Stampede Bridging Authorization Protocol" },
                    202:     { 0xc281,  "Proprietary Authentication Protocol", },
                    203:     { 0xc283,  "Proprietary Authentication Protocol", },
                    204:     { 0xc481,  "Proprietary Node ID Authentication Protocol", },
                    205: #endif
                    206:   };
                    207:   #define NUM_PROTO_NAMES      (sizeof(protoNames) / sizeof(*protoNames))
                    208: 
                    209: /*
                    210:  * INTERNAL FUNCTIONS
                    211:  */
                    212: 
                    213:   static int   ProtoNameCmp(const void *v1, const void *v2);
                    214: 
                    215: /*
                    216:  * ProtoName()
                    217:  * XXX For unknown protocols this function return pointer 
                    218:  * on the static variable. It is not good, but I think 
                    219:  * it should not create troubles as it is used only for logging.
                    220:  */
                    221: 
                    222: const char *
                    223: ProtoName(int proto)
                    224: {
                    225:   int                  k;
                    226:   static char          buf[20];
                    227:   struct protoname     key, *pn;
                    228: 
                    229:   /* First check our stat list for known short names */
                    230:   for (k = 0; k < NUM_STAT_PROTOCOLS; k++) {
                    231:     if (proto == statProtos[k].proto)
                    232:       return(statProtos[k].name);
                    233:   }
                    234: 
                    235:   /* Now look in list of all defined protocols */
                    236:   key.proto = proto;
                    237:   if ((pn = bsearch(&key, protoNames,
                    238:       NUM_PROTO_NAMES, sizeof(*pn), ProtoNameCmp)) != NULL)
                    239:     return(pn->name);
                    240: 
                    241:   /* Return hex value */
                    242:   buf[19] = 0;
                    243:   sprintf(buf, "0x%04x", proto);
                    244:   return(buf);
                    245: }
                    246: 
                    247: /*
                    248:  * ProtoNameCmp()
                    249:  */
                    250: 
                    251: static int
                    252: ProtoNameCmp(const void *v1, const void *v2)
                    253: {
                    254:   struct protoname     *const p1 = (struct protoname *) v1;
                    255:   struct protoname     *const p2 = (struct protoname *) v2;
                    256: 
                    257:   return(p1->proto - p2->proto);
                    258: }
                    259: 
                    260: 

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>