1 /*
2  * Copyright (c) 2001 William C. Fenner.
3  *                All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that: (1) source code
7  * distributions retain the above copyright notice and this paragraph
8  * in its entirety, and (2) distributions including binary code include
9  * the above copyright notice and this paragraph in its entirety in
10  * the documentation or other materials provided with the distribution.
11  * The name of William C. Fenner may not be used to endorse or
12  * promote products derived from this software without specific prior
13  * written permission.  THIS SOFTWARE IS PROVIDED ``AS IS'' AND
14  * WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT
15  * LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
16  * FOR A PARTICULAR PURPOSE.
17  */
18 
19 #include <sys/cdefs.h>
20 #ifndef lint
21 __RCSID("$NetBSD: print-msdp.c,v 1.8 2024/09/02 16:15:32 christos Exp $");
22 #endif
23 
24 /* \summary: Multicast Source Discovery Protocol (MSDP) printer */
25 
26 #include <config.h>
27 
28 #include "netdissect-stdinc.h"
29 
30 #include "netdissect.h"
31 #include "addrtoname.h"
32 #include "extract.h"
33 
34 #define MSDP_TYPE_MAX         7
35 
36 void
msdp_print(netdissect_options * ndo,const u_char * sp,u_int length)37 msdp_print(netdissect_options *ndo, const u_char *sp, u_int length)
38 {
39           unsigned int type, len;
40 
41           ndo->ndo_protocol = "msdp";
42           ND_PRINT(": ");
43           nd_print_protocol(ndo);
44           /* See if we think we're at the beginning of a compound packet */
45           type = GET_U_1(sp);
46           len = GET_BE_U_2(sp + 1);
47           if (len > 1500 || len < 3 || type == 0 || type > MSDP_TYPE_MAX)
48                     goto trunc;         /* not really truncated, but still not decodable */
49           while (length != 0) {
50                     type = GET_U_1(sp);
51                     len = GET_BE_U_2(sp + 1);
52                     if (len > 1400 || ndo->ndo_vflag)
53                               ND_PRINT(" [len %u]", len);
54                     if (len < 3)
55                               goto trunc;
56                     if (length < len)
57                               goto trunc;
58                     sp += 3;
59                     length -= 3;
60                     switch (type) {
61                     case 1:   /* IPv4 Source-Active */
62                     case 3: /* IPv4 Source-Active Response */
63                               if (type == 1)
64                                         ND_PRINT(" SA");
65                               else
66                                         ND_PRINT(" SA-Response");
67                               ND_PRINT(" %u entries", GET_U_1(sp));
68                               if ((u_int)((GET_U_1(sp) * 12) + 8) < len) {
69                                         ND_PRINT(" [w/data]");
70                                         if (ndo->ndo_vflag > 1) {
71                                                   ND_PRINT(" ");
72                                                   ip_print(ndo, sp +
73                                                              GET_U_1(sp) * 12 + 8 - 3,
74                                                              len - (GET_U_1(sp) * 12 + 8));
75                                         }
76                               }
77                               break;
78                     case 2:
79                               ND_PRINT(" SA-Request");
80                               ND_PRINT(" for %s", GET_IPADDR_STRING(sp + 1));
81                               break;
82                     case 4:
83                               ND_PRINT(" Keepalive");
84                               if (len != 3)
85                                         ND_PRINT("[len=%u] ", len);
86                               break;
87                     case 5:
88                               ND_PRINT(" Notification");
89                               break;
90                     default:
91                               ND_PRINT(" [type=%u len=%u]", type, len);
92                               break;
93                     }
94                     sp += (len - 3);
95                     length -= (len - 3);
96           }
97           return;
98 trunc:
99           nd_print_trunc(ndo);
100 }
101