Skip to content

Commit 4fd6780

Browse files
committed
Condense pure OFFSET_NOT_SET DLTs in init_linktype().
Use one code block for several DLTs. Make it clear which of these DLTs support "link[N:M]" only and which one DLT only may have to do with the "steps of 7" comments.
1 parent e19111c commit 4fd6780

File tree

1 file changed

+31
-86
lines changed

1 file changed

+31
-86
lines changed

gencode.c

Lines changed: 31 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -2106,22 +2106,6 @@ init_linktype(compiler_state_t *cstate, pcap_t *p)
21062106
cstate->off_nl_nosnap = OFFSET_NOT_SET; /* no 802.2 LLC */
21072107
break;
21082108

2109-
case DLT_BACNET_MS_TP:
2110-
/*
2111-
* The third octet of an MS/TP frame is Frame Type, but it is
2112-
* the MS/TP frame type [0..7] rather than a network protocol
2113-
* type. It can be tested using "link[2]". If in future it
2114-
* becomes necessary to have a solution that matches the
2115-
* problem space better, it would need to be a new special
2116-
* primitive that works on MS/TP DLT(s) only and takes names
2117-
* for the types, for example, "ms-tp type token".
2118-
*/
2119-
cstate->off_linktype.constant_part = OFFSET_NOT_SET;
2120-
cstate->off_linkpl.constant_part = OFFSET_NOT_SET;
2121-
cstate->off_nl = OFFSET_NOT_SET;
2122-
cstate->off_nl_nosnap = OFFSET_NOT_SET;
2123-
break;
2124-
21252109
case DLT_JUNIPER_SERVICES:
21262110
cstate->off_linktype.constant_part = 12;
21272111
cstate->off_linkpl.constant_part = OFFSET_NOT_SET; /* L3 proto location dep. on cookie type */
@@ -2206,16 +2190,6 @@ init_linktype(compiler_state_t *cstate, pcap_t *p)
22062190
cstate->off_nl_nosnap = 0;
22072191
break;
22082192

2209-
case DLT_AX25_KISS:
2210-
/*
2211-
* Currently, only raw "link[N:M]" filtering is supported.
2212-
*/
2213-
cstate->off_linktype.constant_part = OFFSET_NOT_SET; /* variable, min 15, max 71 steps of 7 */
2214-
cstate->off_linkpl.constant_part = OFFSET_NOT_SET;
2215-
cstate->off_nl = OFFSET_NOT_SET; /* variable, min 16, max 71 steps of 7 */
2216-
cstate->off_nl_nosnap = OFFSET_NOT_SET; /* no 802.2 LLC */
2217-
break;
2218-
22192193
case DLT_IPNET:
22202194
cstate->off_linktype.constant_part = 1;
22212195
cstate->off_linkpl.constant_part = 24; /* ipnet header length */
@@ -2254,82 +2228,53 @@ init_linktype(compiler_state_t *cstate, pcap_t *p)
22542228
break;
22552229

22562230
case DLT_EN3MB:
2257-
/*
2258-
* Currently, only raw "link[N:M]" filtering is supported.
2259-
*/
2260-
cstate->off_linktype.constant_part = OFFSET_NOT_SET; /* variable, min 15, max 71 steps of 7 */
2261-
cstate->off_linkpl.constant_part = OFFSET_NOT_SET;
2262-
cstate->off_nl = OFFSET_NOT_SET; /* variable, min 16, max 71 steps of 7 */
2263-
cstate->off_nl_nosnap = OFFSET_NOT_SET; /* no 802.2 LLC */
2264-
break;
2265-
22662231
case DLT_AX25:
2267-
/*
2268-
* Currently, only raw "link[N:M]" filtering is supported.
2269-
*/
2270-
cstate->off_linktype.constant_part = OFFSET_NOT_SET; /* variable, min 15, max 71 steps of 7 */
2271-
cstate->off_linkpl.constant_part = OFFSET_NOT_SET;
2272-
cstate->off_nl = OFFSET_NOT_SET; /* variable, min 16, max 71 steps of 7 */
2273-
cstate->off_nl_nosnap = OFFSET_NOT_SET; /* no 802.2 LLC */
2274-
break;
2275-
22762232
case DLT_PRONET:
2277-
/*
2278-
* Currently, only raw "link[N:M]" filtering is supported.
2279-
*/
2280-
cstate->off_linktype.constant_part = OFFSET_NOT_SET; /* variable, min 15, max 71 steps of 7 */
2281-
cstate->off_linkpl.constant_part = OFFSET_NOT_SET;
2282-
cstate->off_nl = OFFSET_NOT_SET; /* variable, min 16, max 71 steps of 7 */
2283-
cstate->off_nl_nosnap = OFFSET_NOT_SET; /* no 802.2 LLC */
2284-
break;
2285-
22862233
case DLT_CHAOS:
2287-
/*
2288-
* Currently, only raw "link[N:M]" filtering is supported.
2289-
*/
2290-
cstate->off_linktype.constant_part = OFFSET_NOT_SET; /* variable, min 15, max 71 steps of 7 */
2291-
cstate->off_linkpl.constant_part = OFFSET_NOT_SET;
2292-
cstate->off_nl = OFFSET_NOT_SET; /* variable, min 16, max 71 steps of 7 */
2293-
cstate->off_nl_nosnap = OFFSET_NOT_SET; /* no 802.2 LLC */
2294-
break;
2295-
22962234
#ifdef DLT_HIPPI
22972235
case DLT_HIPPI:
2298-
/*
2299-
* Currently, only raw "link[N:M]" filtering is supported.
2300-
*/
2301-
cstate->off_linktype.constant_part = OFFSET_NOT_SET; /* variable, min 15, max 71 steps of 7 */
2302-
cstate->off_linkpl.constant_part = OFFSET_NOT_SET;
2303-
cstate->off_nl = OFFSET_NOT_SET; /* variable, min 16, max 71 steps of 7 */
2304-
cstate->off_nl_nosnap = OFFSET_NOT_SET; /* no 802.2 LLC */
2305-
break;
2306-
23072236
#endif
2308-
23092237
case DLT_REDBACK_SMARTEDGE:
2310-
/*
2311-
* Currently, only raw "link[N:M]" filtering is supported.
2312-
*/
2313-
cstate->off_linktype.constant_part = OFFSET_NOT_SET; /* variable, min 15, max 71 steps of 7 */
2314-
cstate->off_linkpl.constant_part = OFFSET_NOT_SET;
2315-
cstate->off_nl = OFFSET_NOT_SET; /* variable, min 16, max 71 steps of 7 */
2316-
cstate->off_nl_nosnap = OFFSET_NOT_SET; /* no 802.2 LLC */
2317-
break;
2318-
2319-
23202238
#ifdef DLT_HHDLC
23212239
case DLT_HHDLC:
2240+
#endif
23222241
/*
23232242
* Currently, only raw "link[N:M]" filtering is supported.
23242243
*/
2325-
cstate->off_linktype.constant_part = OFFSET_NOT_SET; /* variable, min 15, max 71 steps of 7 */
2244+
case DLT_AX25_KISS:
2245+
/*
2246+
* Idem, plus the initial code for AX.25 KISS commented:
2247+
*
2248+
* - "variable, min 15, max 71 steps of 7" about off_linktype
2249+
* - "variable, min 16, max 71 steps of 7" about off_nl
2250+
*
2251+
* It is not clear how that relates with the AX.25 and KISS
2252+
* specifications, also there is a possibility of Linux kernel
2253+
* modifying the packet type and/or structure. So if anybody
2254+
* would like to implement a better filtering support for this
2255+
* DLT, it would be a good idea to verify and to document all
2256+
* particulars of the encoding first.
2257+
*/
2258+
case DLT_BACNET_MS_TP:
2259+
/*
2260+
* This DLT supports a few primitives besides "link[N:M]", but
2261+
* "link proto", whether explicit or implicit, is not one of
2262+
* these.
2263+
*
2264+
* The third octet of an MS/TP frame is Frame Type, but it is
2265+
* the MS/TP frame type [0..7] rather than a network protocol
2266+
* type. It can be tested using "link[2]". If in future it
2267+
* becomes necessary to have a solution that matches the
2268+
* problem space better, it would need to be a new special
2269+
* primitive that works on MS/TP DLT(s) only and takes names
2270+
* for the types, for example, "ms-tp type token".
2271+
*/
2272+
cstate->off_linktype.constant_part = OFFSET_NOT_SET;
23262273
cstate->off_linkpl.constant_part = OFFSET_NOT_SET;
2327-
cstate->off_nl = OFFSET_NOT_SET; /* variable, min 16, max 71 steps of 7 */
2274+
cstate->off_nl = OFFSET_NOT_SET;
23282275
cstate->off_nl_nosnap = OFFSET_NOT_SET; /* no 802.2 LLC */
23292276
break;
23302277

2331-
#endif
2332-
23332278
default:
23342279
/*
23352280
* For values in the range in which we've assigned new

0 commit comments

Comments
 (0)