Skip to content

Commit efe1c57

Browse files
committed
frag6: Refactor duplicate code
Update a test output accordingly. (cherry picked from commit 37745f6)
1 parent 17f21cc commit efe1c57

File tree

2 files changed

+8
-13
lines changed

2 files changed

+8
-13
lines changed

print-frag6.c

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -42,18 +42,13 @@ frag6_print(netdissect_options *ndo, const u_char *bp, const u_char *bp2)
4242
dp = (const struct ip6_frag *)bp;
4343
ip6 = (const struct ip6_hdr *)bp2;
4444

45-
if (ndo->ndo_vflag) {
46-
ND_PRINT("frag (0x%08x:%u|%zu)",
47-
GET_BE_U_4(dp->ip6f_ident),
48-
GET_BE_U_2(dp->ip6f_offlg) & IP6F_OFF_MASK,
49-
sizeof(struct ip6_hdr) + GET_BE_U_2(ip6->ip6_plen) -
50-
(bp - bp2) - sizeof(struct ip6_frag));
51-
} else {
52-
ND_PRINT("frag (%u|%zu)",
53-
GET_BE_U_2(dp->ip6f_offlg) & IP6F_OFF_MASK,
54-
sizeof(struct ip6_hdr) + GET_BE_U_2(ip6->ip6_plen) -
55-
(bp - bp2) - sizeof(struct ip6_frag));
56-
}
45+
ND_PRINT("frag (");
46+
if (ndo->ndo_vflag)
47+
ND_PRINT("0x%08x:", GET_BE_U_4(dp->ip6f_ident));
48+
ND_PRINT("%u|%zu)",
49+
GET_BE_U_2(dp->ip6f_offlg) & IP6F_OFF_MASK,
50+
sizeof(struct ip6_hdr) + GET_BE_U_2(ip6->ip6_plen) -
51+
(bp - bp2) - sizeof(struct ip6_frag));
5752

5853
/* it is meaningless to decode non-first fragment */
5954
if ((GET_BE_U_2(dp->ip6f_offlg) & IP6F_OFF_MASK) != 0)

tests/ip6_frag_asan.out

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1 2038-01-01 00:00:00.000000 IP6 (class 0x51, flowlabel 0xb2100, hlim 16, next-header Fragment (44) payload length: 27136) 452:22:19:0:41a:e4ff:10ff:484d > 2243:80:1400:100:19:ffff:ffff:fffb: [|frag6]
1+
1 2038-01-01 00:00:00.000000 IP6 (class 0x51, flowlabel 0xb2100, hlim 16, next-header Fragment (44) payload length: 27136) 452:22:19:0:41a:e4ff:10ff:484d > 2243:80:1400:100:19:ffff:ffff:fffb: frag ( [|frag6]

0 commit comments

Comments
 (0)