1190207Srpaulo/* @(#) $Header: /tcpdump/master/tcpdump/ospf.h,v 1.23 2007-10-08 07:53:21 hannes Exp $ (LBL) */
217680Spst/*
339297Sfenner * Copyright (c) 1991, 1993, 1994, 1995, 1996, 1997
417680Spst *	The Regents of the University of California.  All rights reserved.
517680Spst *
617680Spst * Redistribution and use in source and binary forms, with or without
717680Spst * modification, are permitted provided that: (1) source code distributions
817680Spst * retain the above copyright notice and this paragraph in its entirety, (2)
917680Spst * distributions including binary code include the above copyright notice and
1017680Spst * this paragraph in its entirety in the documentation or other materials
1117680Spst * provided with the distribution, and (3) all advertising materials mentioning
1217680Spst * features or use of this software display the following acknowledgement:
1317680Spst * ``This product includes software developed by the University of California,
1417680Spst * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
1517680Spst * the University nor the names of its contributors may be used to endorse
1617680Spst * or promote products derived from this software without specific prior
1717680Spst * written permission.
1817680Spst * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
1917680Spst * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
2017680Spst * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
2117680Spst *
2217680Spst * OSPF support contributed by Jeffrey Honig (jch@mitchell.cit.cornell.edu)
2317680Spst */
24127668Sbms#define	OSPF_TYPE_UMD           0	/* UMd's special monitoring packets */
25127668Sbms#define	OSPF_TYPE_HELLO         1	/* Hello */
26127668Sbms#define	OSPF_TYPE_DD            2	/* Database Description */
27127668Sbms#define	OSPF_TYPE_LS_REQ        3	/* Link State Request */
28127668Sbms#define	OSPF_TYPE_LS_UPDATE     4	/* Link State Update */
29127668Sbms#define	OSPF_TYPE_LS_ACK        5	/* Link State Ack */
3017680Spst
31127668Sbms/* Options field
32127668Sbms *
33127668Sbms * +------------------------------------+
34190207Srpaulo * | DN | O | DC | L | N/P | MC | E | T |
35127668Sbms * +------------------------------------+
36127668Sbms *
37127668Sbms */
38127668Sbms
3917680Spst#define OSPF_OPTION_T	0x01	/* T bit: TOS support	*/
4017680Spst#define OSPF_OPTION_E	0x02	/* E bit: External routes advertised	*/
4117680Spst#define	OSPF_OPTION_MC	0x04	/* MC bit: Multicast capable */
42127668Sbms#define	OSPF_OPTION_NP	0x08	/* N/P bit: NSSA capable */
43127668Sbms#define	OSPF_OPTION_EA	0x10	/* EA bit: External Attribute capable */
44190207Srpaulo#define	OSPF_OPTION_L	0x10	/* L bit: Packet contains LLS data block */
45127668Sbms#define	OSPF_OPTION_DC	0x20	/* DC bit: Demand circuit capable */
46127668Sbms#define	OSPF_OPTION_O	0x40	/* O bit: Opaque LSA capable */
47146773Ssam#define	OSPF_OPTION_DN	0x80	/* DN bit: Up/Down Bit capable - draft-ietf-ospf-2547-dnbit-04 */
4817680Spst
4917680Spst/* ospf_authtype	*/
5017680Spst#define	OSPF_AUTH_NONE		0	/* No auth-data */
5117680Spst#define	OSPF_AUTH_SIMPLE	1	/* Simple password */
52172683Smlaier#define OSPF_AUTH_SIMPLE_LEN	8	/* max length of simple authentication */
5339297Sfenner#define OSPF_AUTH_MD5		2	/* MD5 authentication */
54127668Sbms#define OSPF_AUTH_MD5_LEN	16	/* length of MD5 authentication */
5517680Spst
5617680Spst/* db_flags	*/
57190207Srpaulo#define	OSPF_DB_INIT		0x04
5817680Spst#define	OSPF_DB_MORE		0x02
59190207Srpaulo#define	OSPF_DB_MASTER          0x01
60190207Srpaulo#define OSPF_DB_RESYNC          0x08  /* RFC4811 */
6117680Spst
6217680Spst/* ls_type	*/
6317680Spst#define	LS_TYPE_ROUTER		1   /* router link */
6417680Spst#define	LS_TYPE_NETWORK		2   /* network link */
6517680Spst#define	LS_TYPE_SUM_IP		3   /* summary link */
6617680Spst#define	LS_TYPE_SUM_ABR		4   /* summary area link */
6717680Spst#define	LS_TYPE_ASE		5   /* ASE  */
6817680Spst#define	LS_TYPE_GROUP		6   /* Group membership (multicast */
6917680Spst				    /* extensions 23 July 1991) */
70146773Ssam#define	LS_TYPE_NSSA            7   /* rfc3101 - Not so Stubby Areas */
71127668Sbms#define	LS_TYPE_OPAQUE_LL       9   /* rfc2370 - Opaque Link Local */
72127668Sbms#define	LS_TYPE_OPAQUE_AL      10   /* rfc2370 - Opaque Link Local */
73127668Sbms#define	LS_TYPE_OPAQUE_DW      11   /* rfc2370 - Opaque Domain Wide */
7417680Spst
75127668Sbms#define LS_OPAQUE_TYPE_TE       1   /* rfc3630 */
76146773Ssam#define LS_OPAQUE_TYPE_GRACE    3   /* rfc3623 */
77146773Ssam#define LS_OPAQUE_TYPE_RI       4   /* draft-ietf-ospf-cap-03 */
78127668Sbms
79127668Sbms#define LS_OPAQUE_TE_TLV_ROUTER 1   /* rfc3630 */
80127668Sbms#define LS_OPAQUE_TE_TLV_LINK   2   /* rfc3630 */
81127668Sbms
82127668Sbms#define LS_OPAQUE_TE_LINK_SUBTLV_LINK_TYPE             1 /* rfc3630 */
83127668Sbms#define LS_OPAQUE_TE_LINK_SUBTLV_LINK_ID               2 /* rfc3630 */
84127668Sbms#define LS_OPAQUE_TE_LINK_SUBTLV_LOCAL_IP              3 /* rfc3630 */
85127668Sbms#define LS_OPAQUE_TE_LINK_SUBTLV_REMOTE_IP             4 /* rfc3630 */
86127668Sbms#define LS_OPAQUE_TE_LINK_SUBTLV_TE_METRIC             5 /* rfc3630 */
87127668Sbms#define LS_OPAQUE_TE_LINK_SUBTLV_MAX_BW                6 /* rfc3630 */
88127668Sbms#define LS_OPAQUE_TE_LINK_SUBTLV_MAX_RES_BW            7 /* rfc3630 */
89127668Sbms#define LS_OPAQUE_TE_LINK_SUBTLV_UNRES_BW              8 /* rfc3630 */
90127668Sbms#define LS_OPAQUE_TE_LINK_SUBTLV_ADMIN_GROUP           9 /* rfc3630 */
91190207Srpaulo#define LS_OPAQUE_TE_LINK_SUBTLV_LINK_LOCAL_REMOTE_ID 11 /* rfc4203 */
92190207Srpaulo#define LS_OPAQUE_TE_LINK_SUBTLV_LINK_PROTECTION_TYPE 14 /* rfc4203 */
93190207Srpaulo#define LS_OPAQUE_TE_LINK_SUBTLV_INTF_SW_CAP_DESCR    15 /* rfc4203 */
94190207Srpaulo#define LS_OPAQUE_TE_LINK_SUBTLV_SHARED_RISK_GROUP    16 /* rfc4203 */
95162017Ssam#define LS_OPAQUE_TE_LINK_SUBTLV_BW_CONSTRAINTS       17 /* rfc4124 */
96127668Sbms
97127668Sbms#define LS_OPAQUE_TE_LINK_SUBTLV_LINK_TYPE_PTP        1  /* rfc3630 */
98127668Sbms#define LS_OPAQUE_TE_LINK_SUBTLV_LINK_TYPE_MA         2  /* rfc3630 */
99127668Sbms
100146773Ssam#define LS_OPAQUE_GRACE_TLV_PERIOD       1 /* rfc3623 */
101146773Ssam#define LS_OPAQUE_GRACE_TLV_REASON       2 /* rfc3623 */
102146773Ssam#define LS_OPAQUE_GRACE_TLV_INT_ADDRESS  3 /* rfc3623 */
103146773Ssam
104146773Ssam#define LS_OPAQUE_GRACE_TLV_REASON_UNKNOWN     0 /* rfc3623 */
105146773Ssam#define LS_OPAQUE_GRACE_TLV_REASON_SW_RESTART  1 /* rfc3623 */
106146773Ssam#define LS_OPAQUE_GRACE_TLV_REASON_SW_UPGRADE  2 /* rfc3623 */
107146773Ssam#define LS_OPAQUE_GRACE_TLV_REASON_CP_SWITCH   3 /* rfc3623 */
108146773Ssam
109146773Ssam#define LS_OPAQUE_RI_TLV_CAP             1 /* draft-ietf-ospf-cap-03 */
110146773Ssam
11117680Spst
11217680Spst/* rla_link.link_type	*/
11317680Spst#define	RLA_TYPE_ROUTER		1   /* point-to-point to another router	*/
11417680Spst#define	RLA_TYPE_TRANSIT	2   /* connection to transit network	*/
11517680Spst#define	RLA_TYPE_STUB		3   /* connection to stub network	*/
11617680Spst#define RLA_TYPE_VIRTUAL	4   /* virtual link			*/
11717680Spst
11817680Spst/* rla_flags	*/
11917680Spst#define	RLA_FLAG_B	0x01
12017680Spst#define	RLA_FLAG_E	0x02
12117680Spst#define	RLA_FLAG_W1	0x04
12217680Spst#define	RLA_FLAG_W2	0x08
12317680Spst
12417680Spst/* sla_tosmetric breakdown	*/
12517680Spst#define	SLA_MASK_TOS		0x7f000000
12617680Spst#define	SLA_MASK_METRIC		0x00ffffff
12717680Spst#define SLA_SHIFT_TOS		24
12817680Spst
12917680Spst/* asla_tosmetric breakdown	*/
13017680Spst#define	ASLA_FLAG_EXTERNAL	0x80000000
13117680Spst#define	ASLA_MASK_TOS		0x7f000000
13217680Spst#define	ASLA_SHIFT_TOS		24
13317680Spst#define	ASLA_MASK_METRIC	0x00ffffff
13417680Spst
13517680Spst/* multicast vertex type */
13617680Spst#define	MCLA_VERTEX_ROUTER	1
13717680Spst#define	MCLA_VERTEX_NETWORK	2
13817680Spst
139190207Srpaulo/* Link-Local-Signaling */
140190207Srpaulo#define OSPF_LLS_EO             1  /* RFC4811, RFC4812 */
141190207Srpaulo#define OSPF_LLS_MD5            2  /* RFC4813 */
142190207Srpaulo
143190207Srpaulo#define OSPF_LLS_EO_LR		0x00000001		/* RFC4811 */
144190207Srpaulo#define OSPF_LLS_EO_RS		0x00000002		/* RFC4812 */
145190207Srpaulo
146190207Srpaulo/*
147190207Srpaulo * TOS metric struct (will be 0 or more in router links update)
148190207Srpaulo */
149190207Srpaulostruct tos_metric {
150190207Srpaulo    u_int8_t tos_type;
151190207Srpaulo    u_int8_t reserved;
152190207Srpaulo    u_int8_t tos_metric[2];
153190207Srpaulo};
154190207Srpaulostruct tos_link {
155190207Srpaulo    u_int8_t link_type;
156190207Srpaulo    u_int8_t link_tos_count;
157190207Srpaulo    u_int8_t tos_metric[2];
158190207Srpaulo};
159190207Srpaulounion un_tos {
160190207Srpaulo    struct tos_link link;
161190207Srpaulo    struct tos_metric metrics;
162190207Srpaulo};
163190207Srpaulo
16417680Spst/* link state advertisement header */
16517680Spststruct lsa_hdr {
16675115Sfenner    u_int16_t ls_age;
16775115Sfenner    u_int8_t ls_options;
16875115Sfenner    u_int8_t ls_type;
169127668Sbms    union {
170127668Sbms        struct in_addr lsa_id;
171127668Sbms        struct { /* opaque LSAs change the LSA-ID field */
172127668Sbms            u_int8_t opaque_type;
173127668Sbms            u_int8_t opaque_id[3];
174127668Sbms	} opaque_field;
175127668Sbms    } un_lsa_id;
17617680Spst    struct in_addr ls_router;
17717680Spst    u_int32_t ls_seq;
17875115Sfenner    u_int16_t ls_chksum;
17975115Sfenner    u_int16_t ls_length;
180127668Sbms};
18117680Spst
18217680Spst/* link state advertisement */
18317680Spststruct lsa {
18417680Spst    struct lsa_hdr ls_hdr;
18517680Spst
18617680Spst    /* Link state types */
18717680Spst    union {
18817680Spst	/* Router links advertisements */
18917680Spst	struct {
19075115Sfenner	    u_int8_t rla_flags;
19175115Sfenner	    u_int8_t rla_zero[1];
19275115Sfenner	    u_int16_t rla_count;
19317680Spst	    struct rlalink {
19417680Spst		struct in_addr link_id;
19517680Spst		struct in_addr link_data;
196190207Srpaulo                union un_tos un_tos;
19717680Spst	    } rla_link[1];		/* may repeat	*/
19817680Spst	} un_rla;
19917680Spst
20017680Spst	/* Network links advertisements */
20117680Spst	struct {
20217680Spst	    struct in_addr nla_mask;
20317680Spst	    struct in_addr nla_router[1];	/* may repeat	*/
20417680Spst	} un_nla;
20517680Spst
20617680Spst	/* Summary links advertisements */
20717680Spst	struct {
20817680Spst	    struct in_addr sla_mask;
20917680Spst	    u_int32_t sla_tosmetric[1];	/* may repeat	*/
21017680Spst	} un_sla;
21117680Spst
21217680Spst	/* AS external links advertisements */
21317680Spst	struct {
21417680Spst	    struct in_addr asla_mask;
21517680Spst	    struct aslametric {
21617680Spst		u_int32_t asla_tosmetric;
21717680Spst		struct in_addr asla_forward;
21817680Spst		struct in_addr asla_tag;
21917680Spst	    } asla_metric[1];		/* may repeat	*/
22017680Spst	} un_asla;
22117680Spst
22217680Spst	/* Multicast group membership */
22317680Spst	struct mcla {
22417680Spst	    u_int32_t mcla_vtype;
22517680Spst	    struct in_addr mcla_vid;
22617680Spst	} un_mcla[1];
227127668Sbms
228127668Sbms        /* Opaque TE LSA */
229127668Sbms        struct {
230127668Sbms	    u_int16_t type;
231127668Sbms	    u_int16_t length;
232127668Sbms	    u_int8_t data[1]; /* may repeat   */
233127668Sbms	} un_te_lsa_tlv;
234127668Sbms
235146773Ssam        /* Opaque Grace LSA */
236146773Ssam        struct {
237146773Ssam	    u_int16_t type;
238146773Ssam	    u_int16_t length;
239146773Ssam	    u_int8_t data[1]; /* may repeat   */
240146773Ssam	} un_grace_tlv;
241146773Ssam
242146773Ssam        /* Opaque Router information LSA */
243146773Ssam        struct {
244146773Ssam	    u_int16_t type;
245146773Ssam	    u_int16_t length;
246146773Ssam	    u_int8_t data[1]; /* may repeat   */
247146773Ssam	} un_ri_tlv;
248146773Ssam
249127668Sbms        /* Unknown LSA */
250127668Sbms        struct unknown {
251127668Sbms	    u_int8_t data[1]; /* may repeat   */
252127668Sbms	} un_unknown[1];
253127668Sbms
25417680Spst    } lsa_un;
255127668Sbms};
25617680Spst
25717680Spst#define	OSPF_AUTH_SIZE	8
25817680Spst
25917680Spst/*
26017680Spst * the main header
26117680Spst */
26217680Spststruct ospfhdr {
26375115Sfenner    u_int8_t ospf_version;
26475115Sfenner    u_int8_t ospf_type;
26575115Sfenner    u_int16_t ospf_len;
26617680Spst    struct in_addr ospf_routerid;
26717680Spst    struct in_addr ospf_areaid;
26875115Sfenner    u_int16_t ospf_chksum;
26975115Sfenner    u_int16_t ospf_authtype;
27075115Sfenner    u_int8_t ospf_authdata[OSPF_AUTH_SIZE];
27117680Spst    union {
27217680Spst
27317680Spst	/* Hello packet */
27417680Spst	struct {
27517680Spst	    struct in_addr hello_mask;
27675115Sfenner	    u_int16_t hello_helloint;
27775115Sfenner	    u_int8_t hello_options;
27875115Sfenner	    u_int8_t hello_priority;
27917680Spst	    u_int32_t hello_deadint;
28017680Spst	    struct in_addr hello_dr;
28117680Spst	    struct in_addr hello_bdr;
28217680Spst	    struct in_addr hello_neighbor[1]; /* may repeat	*/
28317680Spst	} un_hello;
28417680Spst
28517680Spst	/* Database Description packet */
28617680Spst	struct {
287190207Srpaulo	    u_int16_t db_ifmtu;
28875115Sfenner	    u_int8_t db_options;
28975115Sfenner	    u_int8_t db_flags;
29017680Spst	    u_int32_t db_seq;
29117680Spst	    struct lsa_hdr db_lshdr[1]; /* may repeat	*/
29217680Spst	} un_db;
29317680Spst
29417680Spst	/* Link State Request */
29517680Spst	struct lsr {
296127668Sbms	    u_int8_t ls_type[4];
297127668Sbms            union {
298127668Sbms                struct in_addr ls_stateid;
299127668Sbms                struct { /* opaque LSAs change the LSA-ID field */
300127668Sbms                    u_int8_t opaque_type;
301127668Sbms                    u_int8_t opaque_id[3];
302127668Sbms                } opaque_field;
303127668Sbms            } un_ls_stateid;
30417680Spst	    struct in_addr ls_router;
30517680Spst	} un_lsr[1];		/* may repeat	*/
30617680Spst
30717680Spst	/* Link State Update */
30817680Spst	struct {
30917680Spst	    u_int32_t lsu_count;
31017680Spst	    struct lsa lsu_lsa[1]; /* may repeat	*/
31117680Spst	} un_lsu;
31217680Spst
31317680Spst	/* Link State Acknowledgement */
31417680Spst	struct {
31517680Spst	    struct lsa_hdr lsa_lshdr[1]; /* may repeat	*/
31617680Spst	} un_lsa ;
31717680Spst    } ospf_un ;
318127668Sbms};
31917680Spst
32017680Spst#define	ospf_hello	ospf_un.un_hello
32117680Spst#define	ospf_db		ospf_un.un_db
32217680Spst#define	ospf_lsr	ospf_un.un_lsr
32317680Spst#define	ospf_lsu	ospf_un.un_lsu
32417680Spst#define	ospf_lsa	ospf_un.un_lsa
32517680Spst
326190207Srpaulo/* Functions shared by ospf and ospf6 */
327235530Sdelphijextern int ospf_print_te_lsa(const u_int8_t *, u_int);
328235530Sdelphijextern int ospf_print_grace_lsa(const u_int8_t *, u_int);
329