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

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
1.1.1.2 ! misho      56:  * Reference: http://www.iana.org/assignments/ppp-numbers/ppp-numbers.xhtml
1.1       misho      57:  */
                     58: 
                     59:   static const struct protoname protoNames[] = {
                     60: #ifdef PROTO_NAME_LIST
                     61: 
                     62: /* Network layer protocols */
                     63:     { 0x0001,  "Padding Protocol" },
1.1.1.2 ! misho      64:     { 0x0002,  "ROHC small-CID" },
        !            65:     { 0x0005,  "ROHC large-CID" },
1.1       misho      66:     { 0x0021,  "Internet Protocol" },
                     67:     { 0x0023,  "OSI Network Layer" },
                     68:     { 0x0025,  "Xerox NS IDP" },
                     69:     { 0x0027,  "DECnet Phase IV" },
                     70:     { 0x0029,  "Appletalk" },
                     71:     { 0x002b,  "Novell IPX" },
                     72:     { 0x002d,  "Van Jacobson Compressed TCP/IP" },
                     73:     { 0x002f,  "Van Jacobson Uncompressed TCP/IP" },
                     74:     { 0x0031,  "Bridging PDU" },
                     75:     { 0x0033,  "Stream Protocol (ST-II)" },
                     76:     { 0x0035,  "Banyan Vines" },
                     77:     { 0x0037,  "reserved (until 1993)" },
                     78:     { 0x0039,  "AppleTalk EDDP" },
                     79:     { 0x003b,  "AppleTalk SmartBuffered" },
                     80:     { 0x003d,  "Multi-Link" },
                     81:     { 0x003f,  "NETBIOS Framing" },
                     82:     { 0x0041,  "Cisco Systems" },
                     83:     { 0x0043,  "Ascom Timeplex" },
                     84:     { 0x0045,  "Fujitsu Link Backup and Load Balancing (LBLB)" },
                     85:     { 0x0047,  "DCA Remote Lan" },
                     86:     { 0x0049,  "Serial Data Transport Protocol (PPP-SDTP)" },
                     87:     { 0x004b,  "SNA over 802.2" },
                     88:     { 0x004d,  "SNA" },
                     89:     { 0x004f,  "IP6 Header Compression" },
                     90:     { 0x0051,  "KNX Bridging Data" },
                     91:     { 0x0053,  "Encryption" },
                     92:     { 0x0055,  "Individual Link Encryption" },
1.1.1.2 ! misho      93:     { 0x0057,  "Internet Protocol version 6" },
        !            94:     { 0x0059,  "PPP Muxing (RFC 3153)" },
1.1       misho      95:     { 0x005b,  "Vendor-Specific Network Protocol" },
                     96:     { 0x005d,  "TRILL Network Protocol (TNP)" },
                     97:     { 0x0061,  "RTP IPHC Full Header" },
                     98:     { 0x0063,  "RTP IPHC Compressed TCP" },
                     99:     { 0x0065,  "RTP IPHC Compressed Non TCP" },
                    100:     { 0x0067,  "RTP IPHC Compressed UDP 8" },
                    101:     { 0x0069,  "RTP IPHC Compressed RTP 8" },
                    102:     { 0x006f,  "Stampede Bridging" },
                    103:     { 0x0071,  "BAP Bandwidth Allocation Protocol" },
                    104:     { 0x0073,  "MP+ Protocol" },
                    105:     { 0x007d,  "reserved (Control Escape) (RFC 1661)" },
                    106:     { 0x007f,  "reserved (compression inefficient) (RFC 1662)" },
1.1.1.2 ! misho     107:     { 0x0081,  "Unassigned" },
        !           108:     { 0x0083,  "Unassigned" },
1.1       misho     109:     { 0x00c1,  "NTCITS IPI" },
1.1.1.2 ! misho     110:     { 0x00cf,  "Reserved (PPP NLPID)" },
        !           111:     { 0x00fb,  "Single link compression in multilink" },
        !           112:     { 0x00fd,  "Compressed datagram" },
        !           113:     { 0x00ff,  "Reserved (compression inefficient)" },
1.1       misho     114: 
                    115:     { 0x0201,  "802.1d Hello Packets (RFC 1220)" },
                    116:     { 0x0203,  "IBM Source Routing BPDU" },
                    117:     { 0x0205,  "DEC LANBridge100 Spanning Tree" },
                    118:     { 0x0207,  "Cisco Discovery Protocol" },
                    119:     { 0x0209,  "Netcs Twin Routing" },
1.1.1.2 ! misho     120:     { 0x020b,  "STP - Scheduled Transfer Protocol" },
        !           121:     { 0x020d,  "EDP - Extreme Discovery Protocol" },
1.1       misho     122:     { 0x0211,  "Optical Supervisory Channel Protocol (OSCP)" },
                    123:     { 0x0213,  "Optical Supervisory Channel Protocol (OSCP)" },
                    124:     { 0x0231,  "Luxcom" },
                    125:     { 0x0233,  "Sigma Network Systems" },
                    126:     { 0x0235,  "Apple Client Server Protocol" },
                    127:     { 0x0281,  "MPLS Unicast" },
                    128:     { 0x0283,  "MPLS Multicast" },
                    129:     { 0x0285,  "IEEE p1284.4 standard - data packets" },
                    130:     { 0x0287,  "ETSI TETRA Network Protocol Type 1" },
                    131:     { 0x0289,  "Multichannel Flow Treatment Protocol" },
                    132: 
                    133:     { 0x2063,  "RTP IPHC Compressed TCP No Delta" },
                    134:     { 0x2065,  "RTP IPHC Context State" },
                    135:     { 0x2067,  "RTP IPHC Compressed UDP 16" },
                    136:     { 0x2069,  "RTP IPHC Compressed RTP 16" },
                    137: 
                    138:     { 0x4001,  "Cray Communications Control Protocol" },
                    139:     { 0x4003,  "CDPD Mobile Network Registration Protocol" },
1.1.1.2 ! misho     140:     { 0x4005,  "Expand accelerator protocol" },
        !           141:     { 0x4007,  "ODSICP NCP" },
        !           142:     { 0x4009,  "DOCSIS DLL" },
        !           143:     { 0x400b,  "Cetacean Network Detection Protocol" },
1.1       misho     144:     { 0x4021,  "Stacker LZS" },
1.1.1.2 ! misho     145:     { 0x4023,  "RefTek Protocol" },
        !           146:     { 0x4025,  "Fibre Channel" },
        !           147:     { 0x4027,  "OpenDOF" },
        !           148:     { 0x405b,  "Vendor-Specific Protocol (VSP)" },
        !           149:     { 0x405d,  "TRILL Link State Protocol (TLSP)" },
1.1       misho     150: 
                    151: /* Network layer control protocols */
                    152: 
                    153:     { 0x8021,  "Internet Protocol Control Protocol" },
                    154:     { 0x8023,  "OSI Network Layer Control Protocol" },
                    155:     { 0x8025,  "Xerox NS IDP Control Protocol" },
                    156:     { 0x8027,  "DECnet Phase IV Control Protocol" },
                    157:     { 0x8029,  "Appletalk Control Protocol" },
                    158:     { 0x802b,  "Novell IPX Control Protocol" },
1.1.1.2 ! misho     159:     { 0x802d,  "Reserved" },
        !           160:     { 0x802f,  "Reserved" },
1.1       misho     161:     { 0x8031,  "Bridging NCP" },
                    162:     { 0x8033,  "Stream Protocol Control Protocol" },
                    163:     { 0x8035,  "Banyan Vines Control Protocol" },
1.1.1.2 ! misho     164:     { 0x8037,  "Unassigned" },
        !           165:     { 0x8039,  "Reserved" },
        !           166:     { 0x803b,  "Reserved" },
1.1       misho     167:     { 0x803d,  "Multi-Link Control Protocol" },
                    168:     { 0x803f,  "NETBIOS Framing Control Protocol" },
                    169:     { 0x8041,  "Cisco Systems Control Protocol" },
                    170:     { 0x8043,  "Ascom Timeplex" },
                    171:     { 0x8045,  "Fujitsu LBLB Control Protocol" },
                    172:     { 0x8047,  "DCA Remote Lan Network Control Protocol (RLNCP)" },
                    173:     { 0x8049,  "Serial Data Control Protocol (PPP-SDCP)" },
                    174:     { 0x804b,  "SNA over 802.2 Control Protocol" },
                    175:     { 0x804d,  "SNA Control Protocol" },
                    176:     { 0x804f,  "IP6 Header Compression Control Protocol" },
                    177:     { 0x8051,  "KNX Bridging Control Protocol" },
                    178:     { 0x8053,  "Encryption Control Protocol" },
                    179:     { 0x8055,  "Individual Link Encryption Control Protocol" },
                    180:     { 0x8057,  "IPv6 PPP Control Protocol" },
1.1.1.2 ! misho     181:     { 0x8059,  "PPP Muxing Control Protocol" },
        !           182:     { 0x805b,  "Vendor-Specific Network Control Protocol (VSNCP)" },
        !           183:     { 0x805d,  "TRILL Network Control Protocol (TNCP)" },
1.1       misho     184:     { 0x806f,  "Stampede Bridging Control Protocol" },
                    185:     { 0x8071,  "BACP Bandwidth Allocation Control Protocol" },
                    186:     { 0x8073,  "MP+ Control Protocol" },
                    187:     { 0x807d,  "Not Used - reserved" },
1.1.1.2 ! misho     188:     { 0x8081,  "Unassigned" },
        !           189:     { 0x8083,  "Unassigned" },
1.1       misho     190:     { 0x80c1,  "NTCITS IPI Control Protocol" },
                    191:     { 0x80cf,  "Not Used - reserved" },
1.1.1.2 ! misho     192:     { 0x80fb,  "single link compression in multilink control" },
1.1       misho     193:     { 0x80fd,  "Compression Control Protocol" },
                    194:     { 0x80ff,  "Not Used - reserved" },
                    195: 
                    196:     { 0x8207,  "Cisco Discovery Protocol Control" },
                    197:     { 0x8209,  "Netcs Twin Routing" },
                    198:     { 0x820b,  "STP - Control Protocol" },
                    199:     { 0x820d,  "EDPCP - Extreme Discovery Protocol Ctrl Prtcl" },
                    200:     { 0x8235,  "Apple Client Server Protocol Control" },
                    201:     { 0x8281,  "MPLS Control Protocol (RFC 3032)" },
                    202:     { 0x8283,  "Tag Switching - Multicast" },
                    203:     { 0x8285,  "IEEE p1284.4 standard - Protocol Control" },
                    204:     { 0x8287,  "ETSI TETRA NSP1 Control Protocol" },
                    205:     { 0x8289,  "Multichannel Flow Treatment Protocol" },
                    206: 
                    207: /* Link layer control protocols */
                    208: 
                    209:     { 0xc021,  "Link Control Protocol" },
                    210:     { 0xc023,  "Password Authentication Protocol" },
                    211:     { 0xc025,  "Link Quality Report" },
                    212:     { 0xc027,  "Shiva Password Authentication Protocol" },
                    213:     { 0xc029,  "CallBack Control Protocol (CBCP)" },
1.1.1.2 ! misho     214:     { 0xc02b,  "BACP Bandwidth Allocation Control Protocol (RFC 2125)" },
        !           215:     { 0xc02d,  "BAP (RFC 2125)" },
        !           216:     { 0xc05b,  "Vendor-Specific Authentication Protocol (RFC 3772)" },
1.1       misho     217:     { 0xc081,  "Container Control Protocol", },
                    218:     { 0xc223,  "Challenge Handshake Authentication Protocol" },
                    219:     { 0xc225,  "RSA Authentication Protocol" },
                    220:     { 0xc227,  "Extensible Authentication Protocol" },
1.1.1.2 ! misho     221:     { 0xc229,  "Mitsubishi Security Info Exch Ptcl (SIEP)" },
1.1       misho     222:     { 0xc26f,  "Stampede Bridging Authorization Protocol" },
                    223:     { 0xc281,  "Proprietary Authentication Protocol", },
                    224:     { 0xc283,  "Proprietary Authentication Protocol", },
                    225:     { 0xc481,  "Proprietary Node ID Authentication Protocol", },
                    226: #endif
                    227:   };
                    228:   #define NUM_PROTO_NAMES      (sizeof(protoNames) / sizeof(*protoNames))
                    229: 
                    230: /*
                    231:  * INTERNAL FUNCTIONS
                    232:  */
                    233: 
                    234:   static int   ProtoNameCmp(const void *v1, const void *v2);
                    235: 
                    236: /*
                    237:  * ProtoName()
                    238:  * XXX For unknown protocols this function return pointer 
                    239:  * on the static variable. It is not good, but I think 
                    240:  * it should not create troubles as it is used only for logging.
                    241:  */
                    242: 
                    243: const char *
                    244: ProtoName(int proto)
                    245: {
1.1.1.2 ! misho     246:   unsigned                     k;
1.1       misho     247:   static char          buf[20];
                    248:   struct protoname     key, *pn;
                    249: 
                    250:   /* First check our stat list for known short names */
                    251:   for (k = 0; k < NUM_STAT_PROTOCOLS; k++) {
                    252:     if (proto == statProtos[k].proto)
                    253:       return(statProtos[k].name);
                    254:   }
                    255: 
                    256:   /* Now look in list of all defined protocols */
                    257:   key.proto = proto;
                    258:   if ((pn = bsearch(&key, protoNames,
                    259:       NUM_PROTO_NAMES, sizeof(*pn), ProtoNameCmp)) != NULL)
                    260:     return(pn->name);
                    261: 
                    262:   /* Return hex value */
                    263:   buf[19] = 0;
                    264:   sprintf(buf, "0x%04x", proto);
                    265:   return(buf);
                    266: }
                    267: 
                    268: /*
                    269:  * ProtoNameCmp()
                    270:  */
                    271: 
                    272: static int
                    273: ProtoNameCmp(const void *v1, const void *v2)
                    274: {
1.1.1.2 ! misho     275:   const struct protoname *const p1 = (const struct protoname *) v1;
        !           276:   const struct protoname *const p2 = (const struct protoname *) v2;
1.1       misho     277: 
                    278:   return(p1->proto - p2->proto);
                    279: }
                    280: 
                    281: 

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