xref: /openbsd/usr.sbin/tcpdump/ospf.h (revision 62302bca)
1 /*	$OpenBSD: ospf.h,v 1.11 2019/04/14 00:37:31 dlg Exp $	*/
2 
3 /*
4  * Copyright (c) 1991, 1993, 1994, 1995, 1996, 1997
5  *	The Regents of the University of California.  All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that: (1) source code distributions
9  * retain the above copyright notice and this paragraph in its entirety, (2)
10  * distributions including binary code include the above copyright notice and
11  * this paragraph in its entirety in the documentation or other materials
12  * provided with the distribution, and (3) all advertising materials mentioning
13  * features or use of this software display the following acknowledgement:
14  * ``This product includes software developed by the University of California,
15  * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
16  * the University nor the names of its contributors may be used to endorse
17  * or promote products derived from this software without specific prior
18  * written permission.
19  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
20  * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
21  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
22  *
23  * OSPF support contributed by Jeffrey Honig (jch@mitchell.cit.cornell.edu)
24  */
25 #define	OSPF_TYPE_UMD	0	/* UMd's special monitoring packets */
26 #define	OSPF_TYPE_HELLO	1	/* Hello */
27 #define	OSPF_TYPE_DB	2	/* Database Description */
28 #define	OSPF_TYPE_LSR	3	/* Link State Request */
29 #define	OSPF_TYPE_LSU	4	/* Link State Update */
30 #define	OSPF_TYPE_LSA	5	/* Link State Ack */
31 #define	OSPF_TYPE_MAX	6
32 
33 /* Options *_options	*/
34 #define OSPF_OPTION_T	0x01	/* T bit: TOS support	*/
35 #define OSPF_OPTION_E	0x02	/* E bit: External routes advertised	*/
36 #define	OSPF_OPTION_MC	0x04	/* MC bit: Multicast capable */
37 
38 /* ospf_authtype	*/
39 #define	OSPF_AUTH_NONE		0	/* No auth-data */
40 #define	OSPF_AUTH_SIMPLE	1	/* Simple password */
41 #define OSPF_AUTH_MD5		2	/* MD5 authentication */
42 #define     OSPF_AUTH_MD5_LEN	16	/* length of MD5 authentication */
43 
44 
45 /* db_flags	*/
46 #define	OSPF_DB_INIT		0x04	    /*	*/
47 #define	OSPF_DB_MORE		0x02
48 #define	OSPF_DB_MASTER		0x01
49 
50 /* ls_type	*/
51 #define	LS_TYPE_ROUTER		1   /* router link */
52 #define	LS_TYPE_NETWORK		2   /* network link */
53 #define	LS_TYPE_SUM_IP		3   /* summary link */
54 #define	LS_TYPE_SUM_ABR		4   /* summary area link */
55 #define	LS_TYPE_ASE		5   /* ASE  */
56 #define	LS_TYPE_GROUP		6   /* Group membership (multicast */
57 				    /* extensions 23 July 1991) */
58 #define	LS_TYPE_MAX		7
59 
60 /*************************************************
61  *
62  * is the above a bug in the documentation?
63  *
64  *************************************************/
65 
66 
67 /* rla_link.link_type	*/
68 #define	RLA_TYPE_ROUTER		1   /* point-to-point to another router	*/
69 #define	RLA_TYPE_TRANSIT	2   /* connection to transit network	*/
70 #define	RLA_TYPE_STUB		3   /* connection to stub network	*/
71 #define RLA_TYPE_VIRTUAL	4   /* virtual link			*/
72 
73 /* rla_flags	*/
74 #define	RLA_FLAG_B	0x01
75 #define	RLA_FLAG_E	0x02
76 #define	RLA_FLAG_W1	0x04
77 #define	RLA_FLAG_W2	0x08
78 
79 /* sla_tosmetric breakdown	*/
80 #define	SLA_MASK_TOS		0x7f000000
81 #define	SLA_MASK_METRIC		0x00ffffff
82 #define SLA_SHIFT_TOS		24
83 
84 /* asla_tosmetric breakdown	*/
85 #define	ASLA_FLAG_EXTERNAL	0x80000000
86 #define	ASLA_MASK_TOS		0x7f000000
87 #define	ASLA_SHIFT_TOS		24
88 #define	ASLA_MASK_METRIC	0x00ffffff
89 
90 /* multicast vertex type */
91 #define	MCLA_VERTEX_ROUTER	1
92 #define	MCLA_VERTEX_NETWORK	2
93 
94 /* link state advertisement header */
95 struct lsa_hdr {
96     u_short ls_age;
97     u_char ls_options;
98     u_char ls_type;
99     struct in_addr ls_stateid;
100     struct in_addr ls_router;
101     u_int32_t ls_seq;
102     u_short ls_chksum;
103     u_short ls_length;
104 } ;
105 
106 /* link state advertisement */
107 struct lsa {
108     struct lsa_hdr ls_hdr;
109 
110     /* Link state types */
111     union {
112 	/* Router links advertisements */
113 	struct {
114 	    u_char rla_flags;
115 	    u_char rla_zero[1];
116 	    u_short rla_count;
117 	    struct rlalink {
118 		struct in_addr link_id;
119 		struct in_addr link_data;
120 		u_char link_type;
121 		u_char link_toscount;
122 		u_short link_tos0metric;
123 	    } rla_link[1];		/* may repeat	*/
124 	} un_rla;
125 
126 	/* Network links advertisements */
127 	struct {
128 	    struct in_addr nla_mask;
129 	    struct in_addr nla_router[1];	/* may repeat	*/
130 	} un_nla;
131 
132 	/* Summary links advertisements */
133 	struct {
134 	    struct in_addr sla_mask;
135 	    u_int32_t sla_tosmetric[1];	/* may repeat	*/
136 	} un_sla;
137 
138 	/* AS external links advertisements */
139 	struct {
140 	    struct in_addr asla_mask;
141 	    struct aslametric {
142 		u_int32_t asla_tosmetric;
143 		struct in_addr asla_forward;
144 		u_int32_t asla_tag;
145 	    } asla_metric[1];		/* may repeat	*/
146 	} un_asla;
147 
148 	/* Multicast group membership */
149 	struct mcla {
150 	    u_int32_t mcla_vtype;
151 	    struct in_addr mcla_vid;
152 	} un_mcla[1];
153     } lsa_un;
154 } ;
155 
156 
157 /*
158  * TOS metric struct (will be 0 or more in router links update)
159  */
160 struct tos_metric {
161     u_char tos_type;
162     u_char tos_zero;
163     u_short tos_metric;
164 } ;
165 
166 #define	OSPF_AUTH_SIZE	8
167 
168 /*
169  * the main header
170  */
171 struct ospfhdr {
172     u_char ospf_version;
173     u_char ospf_type;
174     u_short ospf_len;
175     struct in_addr ospf_routerid;
176     struct in_addr ospf_areaid;
177     u_short ospf_chksum;
178     u_short ospf_authtype;
179     u_char ospf_authdata[OSPF_AUTH_SIZE];
180     union {
181 
182 	/* Hello packet */
183 	struct {
184 	    struct in_addr hello_mask;
185 	    u_short hello_helloint;
186 	    u_char hello_options;
187 	    u_char hello_priority;
188 	    u_int32_t hello_deadint;
189 	    struct in_addr hello_dr;
190 	    struct in_addr hello_bdr;
191 	    struct in_addr hello_neighbor[1]; /* may repeat	*/
192 	} un_hello;
193 
194 	/* Database Description packet */
195 	struct {
196 	    u_int16_t db_mtu;
197 	    u_char db_options;
198 	    u_char db_flags;
199 	    u_int32_t db_seq;
200 	    struct lsa_hdr db_lshdr[1]; /* may repeat	*/
201 	} un_db;
202 
203 	/* Link State Request */
204 	struct lsr {
205 	    u_int32_t ls_type;
206 	    struct in_addr ls_stateid;
207 	    struct in_addr ls_router;
208 	} un_lsr[1];		/* may repeat	*/
209 
210 	/* Link State Update */
211 	struct {
212 	    u_int32_t lsu_count;
213 	    struct lsa lsu_lsa[1]; /* may repeat	*/
214 	} un_lsu;
215 
216 	/* Link State Acknowledgement */
217 	struct {
218 	    struct lsa_hdr lsa_lshdr[1]; /* may repeat	*/
219 	} un_lsa ;
220     } ospf_un ;
221 } ;
222 
223 struct ospf_md5_authdata {
224 	uint16_t	auth_md5_offset;
225 	uint8_t		auth_keyid;
226 	uint8_t		auth_len;
227 	uint32_t	auth_seq;
228 };
229 
230 #define	ospf_hello	ospf_un.un_hello
231 #define	ospf_db		ospf_un.un_db
232 #define	ospf_lsr	ospf_un.un_lsr
233 #define	ospf_lsu	ospf_un.un_lsu
234 #define	ospf_lsa	ospf_un.un_lsa
235 
236