Skip to content

Commit 692ab62

Browse files
authored
Merge pull request #29 from perryan123/ipsec
nettrace commit: support ipsec analysis
2 parents 0f38278 + 6eefbb0 commit 692ab62

4 files changed

Lines changed: 42 additions & 0 deletions

File tree

shared/bpf/skb_shared.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@ typedef struct __attribute__((__packed__)) {
4040
struct {
4141
u16 op;
4242
} arp_ext;
43+
struct
44+
{
45+
u32 spi;
46+
u32 seq;
47+
} espheader;
4348
#define field_udp l4.udp
4449
} l4;
4550
u16 proto_l3;

shared/bpf/skb_utils.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,12 @@ static try_inline bool ipv6_not_equel(u8 *src, u8 *target)
194194
#define ATTR_IPV6_CHECK() \
195195
(filter && ATTR_OPS(addr, ATTR_IPV6_OPS))
196196

197+
struct ip_esp_hdr {
198+
__be32 spi;
199+
__be32 seq_no; /* Sequence number */
200+
__u8 enc_data[0]; /* Variable len but >=8. Mind the 64 bit alignment! */
201+
};
202+
197203
static try_inline int probe_parse_ip(void *ip, parse_ctx_t *ctx)
198204
{
199205
pkt_args_t *bpf_args = ctx->args;
@@ -285,6 +291,14 @@ static try_inline int probe_parse_ip(void *ip, parse_ctx_t *ctx)
285291
pkt->l4.icmp.id = _(icmp->un.echo.id);
286292
break;
287293
}
294+
case IPPROTO_ESP: {
295+
struct ip_esp_hdr *esp_hdr = l4;
296+
if (ATTR_ENABLE(port))
297+
goto err;
298+
pkt->l4.espheader.seq = _(esp_hdr->seq_no);
299+
pkt->l4.espheader.spi = _(esp_hdr->spi);
300+
break;
301+
}
288302
default:
289303
if (ATTR_ENABLE(port))
290304
goto err;

shared/pkt_utils.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ int ts_print_packet(char *buf, packet_t *pkt, char *minfo,
8282
daddr, ntohs(pkt->l4.min.dport));
8383
break;
8484
case IPPROTO_ICMP:
85+
case IPPROTO_ESP:
8586
BUF_FMT("%s -> %s", saddr, daddr);
8687
break;
8788
default:
@@ -116,6 +117,9 @@ int ts_print_packet(char *buf, packet_t *pkt, char *minfo,
116117
}
117118
BUF_FMT("seq: %u", ntohs(pkt->l4.icmp.seq));
118119
break;
120+
case IPPROTO_ESP:
121+
BUF_FMT(" spi:0x%x seq:0x%x", ntohl(pkt->l4.espheader.spi), ntohl(pkt->l4.espheader.seq));
122+
break;
119123
default:
120124
break;
121125
}

src/trace.yaml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,25 @@ children:
229229
- ip_finish_output_gso:2
230230
- ip_finish_output2:2
231231
- ip6_finish_output2:2
232+
- xfrm4_output:2
233+
- xfrm_output:1
234+
- xfrm_output2:2
235+
- xfrm_output_gso:2
236+
- xfrm_output_resume:1
237+
- xfrm4_transport_output:1
238+
- xfrm4_prepare_output:1
239+
- dst_output:2
240+
- ah_output:1
241+
- esp_output:1
242+
- esp_output_tail:1
243+
- xfrm4_rcv:0
244+
- xfrm4_policy_check:2
245+
- xfrm4_rcv:0
246+
- xfrm_input:0
247+
- ah_input:1
248+
- esp_input:1
249+
- xfrm4_transport_input:1
250+
- xfrm4_rcv_encap_finish:2
232251
- name: ip-route
233252
desc: ip route for packet in and out
234253
visual: true

0 commit comments

Comments
 (0)