12 typedef struct Ospfpkt Ospfpkt;
25 #define OSPF_HDRSIZE 24
39 [OSPFdd] "data definition",
40 [OSPFlsrequest] "link state request",
41 [OSPFlsupdate] "link state update",
42 [OSPFlsack] "link state ack",
50 if(x > 0 && x <= OSPFlsack)
52 sprint(type, "type %d", x);
57 ospfauth(Ospfpkt *ospf)
59 static char auth[100];
63 return "no authentication";
65 sprint(auth, "password(%8.8ux %8.8ux)", NetL(ospf->auth),
69 sprint(auth, "crypto(plen %d id %d dlen %d)", NetS(ospf->auth),
70 ospf->auth[2], ospf->auth[3]);
73 sprint(auth, "auth%d(%8.8ux %8.8ux)", NetS(ospf->autype), NetL(ospf->auth),
79 typedef struct Ospfhello Ospfhello;
93 seprintospfhello(char *p, char *e, void *a)
97 return seprint(p, e, "%s(mask %V interval %d opt %ux pri %ux deadt %d designated %V bdesignated %V)",
99 h->mask, NetS(h->interval), h->options, h->pri,
100 NetL(h->deadint), h->designated, h->bdesignated);
114 [LSARouter] "Router LSA",
115 [LSANetwork] "Network LSA",
116 [LSASummN] "Summary LSA (Network)",
117 [LSASummR] "Summary LSA (Router)",
118 [LSAASext] "LSA AS external",
124 static char type[16];
126 if(x > 0 && x <= LSAASext)
128 sprint(type, "type %d", x);
132 /* OSPF Link State Advertisement Header */
133 /* rfc2178 section 12.1 */
134 /* data of Ospfpkt point to a 4-uchar value that is the # of LSAs */
137 uchar options; /* 0x2=stub area, 0x1=TOS routing capable */
139 uchar lstype; /* 1=Router-LSAs
141 * 3=Summary-LSAs (to network)
142 * 4=Summary-LSAs (to AS boundary routers)
150 uchar lsalen[2]; /* includes the 20 byte lsa header */
163 struct OspfLSAhdr hdr;
168 struct OspfLSAhdr hdr;
173 /* Summary Link State Advertisement info */
175 uchar flag; /* always zero */
180 struct OspfLSAhdr hdr;
185 /* AS external Link State Advertisement info */
187 uchar flag; /* external */
193 struct OspfASextLSA {
194 struct OspfLSAhdr hdr;
196 struct OspfASext lsa;
199 /* OSPF Link State Update Packet */
200 struct OspfLSupdpkt {
204 struct OspfrtLSA rt[1];
205 struct OspfntLSA nt[1];
206 struct OspfsummLSA sum[1];
207 struct OspfASextLSA as[1];
212 seprintospflsaheader(char *p, char *e, struct OspfLSAhdr *h)
214 return seprint(p, e, "age %d opt %ux type %ux lsid %V adv_rt %V seqno %ux c %4.4ux l %d",
215 NetS(h->lsage), h->options&0xff, h->lstype,
216 h->lsid, h->advtrt, NetL(h->lsseqno), NetS(h->lscksum),
220 /* OSPF Database Description Packet */
226 struct OspfLSAhdr hdr[1]; /* LSA headers... */
230 seprintospfdatadesc(char *p, char *e, void *a, int len)
235 g = (struct OspfDDpkt *)a;
236 nlsa = len/sizeof(struct OspfLSAhdr);
237 for (i=0; i<nlsa; i++) {
238 p = seprint(p, e, "lsa%d(", i);
239 p = seprintospflsaheader(p, e, &(g->hdr[i]));
240 p = seprint(p, e, ")");
242 return seprint(p, e, ")");
246 seprintospflsupdate(char *p, char *e, void *a, int len)
249 struct OspfLSupdpkt *g;
250 struct OspfLSAhdr *h;
252 g = (struct OspfLSupdpkt *)a;
253 nlsa = NetL(g->lsacnt);
254 h = (struct OspfLSAhdr *)(g->hdr);
255 p = seprint(p, e, "%d-%s(", nlsa, ospfpkttype(OSPFlsupdate));
260 /* struct OspfrtLSA *h;
268 for (i=0; i<nlsa; i++) {
270 p = seprint(p, e, "lsa%d(", i);
271 p = seprintospflsaheader(p, e, &(h->hdr));
272 p = seprint(p, e, " mask %V attrt %V)",
273 h->netmask, h->attrt);
280 struct OspfsummLSA *h;
282 for (i=0; i<nlsa; i++) {
284 p = seprint(p, e, "lsa%d(", i);
285 p = seprintospflsaheader(p, e, &(h->hdr));
286 p = seprint(p, e, " mask %V met %d)",
287 h->netmask, Net3(h->lsa.metric));
293 struct OspfASextLSA *h;
295 for (i=0; i<nlsa; i++) {
297 p = seprint(p, e, " lsa%d(", i);
298 p = seprintospflsaheader(p, e, &(h->hdr));
299 p = seprint(p, e, " mask %V extflg %1.1ux met %d fwdaddr %V extrtflg %ux)",
300 h->netmask, h->lsa.flag, Net3(h->lsa.metric),
301 h->lsa.fwdaddr, NetL(h->lsa.exrttag));
306 p = seprint(p, e, "Not an LS update, lstype %d ", h->lstype);
307 p = seprint(p, e, " %.*H", len>64?64:len, a);
310 return seprint(p, e, ")");
314 seprintospflsack(char *p, char *e, void *a, int len)
317 struct OspfLSAhdr *h;
319 h = (struct OspfLSAhdr *)a;
320 nlsa = len/sizeof(struct OspfLSAhdr);
321 p = seprint(p, e, "%d-%s(", nlsa, ospfpkttype(OSPFlsack));
322 for (i=0; i<nlsa; i++) {
323 p = seprint(p, e, " lsa%d(", i);
324 p = seprintospflsaheader(p, e, &(h[i]));
325 p = seprint(p, e, ")");
327 return seprint(p, e, ")");
338 if(len < OSPF_HDRSIZE)
343 /* adjust packet size */
344 ospf = (Ospfpkt*)m->ps;
345 x = NetS(ospf->length);
350 p = seprint(p, e, "ver=%d type=%d len=%d r=%V a=%V c=%4.4ux %s ",
351 ospf->version, ospf->type, x,
352 ospf->router, ospf->area, NetS(ospf->sum),
355 switch (ospf->type) {
357 p = seprintospfhello(p, e, ospf->data);
360 p = seprintospfdatadesc(p, e, ospf->data, x);
363 p = seprint(p, e, " %s->", ospfpkttype(ospf->type));
366 p = seprintospflsupdate(p, e, ospf->data, x);
369 p = seprintospflsack(p, e, ospf->data, x);
373 p = seprint(p, e, " data=%.*H", x>64?64:x, ospf->data);