| @@ -8,6 +8,7 @@ · 7 unmodified lines |
| 8 | #include <linux/kernel.h> | 8 | #include <linux/kernel.h> |
| 9 | #include <linux/skbuff.h> | 9 | #include <linux/skbuff.h> |
| 10 | #include <linux/module.h> | 10 | #include <linux/module.h> |
| | 11 | #include <linux/timekeeping.h> |
| 11 | #include <net/net_namespace.h> | 12 | #include <net/net_namespace.h> |
| 12 | #include <net/sock.h> | 13 | #include <net/sock.h> |
| 13 | #include <net/netlink.h> | 14 | #include <net/netlink.h> |
| @@ -358,6 +359,7 @@ static int psample_tunnel_meta_len(struct ip_tunnel_info *tun_info) · 344 unmodified lines |
| 358 | void psample_sample_packet(struct psample_group *group, struct sk_buff *skb, | 359 | void psample_sample_packet(struct psample_group *group, struct sk_buff *skb, |
| 359 | u32 sample_rate, const struct psample_metadata *md) | 360 | u32 sample_rate, const struct psample_metadata *md) |
| 360 | { | 361 | { |
| | 362 | ktime_t tstamp = ktime_get_real(); |
| 361 | int out_ifindex = md->out_ifindex; | 363 | int out_ifindex = md->out_ifindex; |
| 362 | int in_ifindex = md->in_ifindex; | 364 | int in_ifindex = md->in_ifindex; |
| 363 | u32 trunc_size = md->trunc_size; | 365 | u32 trunc_size = md->trunc_size; |
| @@ -372,10 +374,15 @@ void psample_sample_packet(struct psample_group *group, struct sk_buff *skb, · 8 unmodified lines |
| 372 | | 374 | |
| 373 | meta_len = (in_ifindex ? nla_total_size(sizeof(u16)) : 0) + | 375 | meta_len = (in_ifindex ? nla_total_size(sizeof(u16)) : 0) + |
| 374 | (out_ifindex ? nla_total_size(sizeof(u16)) : 0) + | 376 | (out_ifindex ? nla_total_size(sizeof(u16)) : 0) + |
| | 377 | (md->out_tc_valid ? nla_total_size(sizeof(u16)) : 0) + |
| | 378 | (md->out_tc_occ_valid ? nla_total_size_64bit(sizeof(u64)) : 0) + |
| | 379 | (md->latency_valid ? nla_total_size_64bit(sizeof(u64)) : 0) + |
| 375 | nla_total_size(sizeof(u32)) + /* sample_rate */ | 380 | nla_total_size(sizeof(u32)) + /* sample_rate */ |
| 376 | nla_total_size(sizeof(u32)) + /* orig_size */ | 381 | nla_total_size(sizeof(u32)) + /* orig_size */ |
| 377 | nla_total_size(sizeof(u32)) + /* group_num */ | 382 | nla_total_size(sizeof(u32)) + /* group_num */ |
| 378 | nla_total_size(sizeof(u32)); /* seq */ | 383 | nla_total_size(sizeof(u32)) + /* seq */ |
| | 384 | nla_total_size_64bit(sizeof(u64)) + /* timestamp */ |
| | 385 | nla_total_size(sizeof(u16)); /* protocol */ |
| 379 | | 386 | |
| 380 | #ifdef CONFIG_INET | 387 | #ifdef CONFIG_INET |
| 381 | tun_info = skb_tunnel_info(skb); | 388 | tun_info = skb_tunnel_info(skb); |
| @@ -425,6 +432,36 @@ void psample_sample_packet(struct psample_group *group, struct sk_buff *skb, · 43 unmodified lines |
| 425 | if (unlikely(ret < 0)) | 432 | if (unlikely(ret < 0)) |
| 426 | goto error; | 433 | goto error; |
| 427 | | 434 | |
| | 435 | if (md->out_tc_valid) { |
| | 436 | ret = nla_put_u16(nl_skb, PSAMPLE_ATTR_OUT_TC, md->out_tc); |
| | 437 | if (unlikely(ret < 0)) |
| | 438 | goto error; |
| | 439 | } |
| | 440 | |
| | 441 | if (md->out_tc_occ_valid) { |
| | 442 | ret = nla_put_u64_64bit(nl_skb, PSAMPLE_ATTR_OUT_TC_OCC, |
| | 443 | md->out_tc_occ, PSAMPLE_ATTR_PAD); |
| | 444 | if (unlikely(ret < 0)) |
| | 445 | goto error; |
| | 446 | } |
| | 447 | |
| | 448 | if (md->latency_valid) { |
| | 449 | ret = nla_put_u64_64bit(nl_skb, PSAMPLE_ATTR_LATENCY, |
| | 450 | md->latency, PSAMPLE_ATTR_PAD); |
| | 451 | if (unlikely(ret < 0)) |
| | 452 | goto error; |
| | 453 | } |
| | 454 | |
| | 455 | ret = nla_put_u64_64bit(nl_skb, PSAMPLE_ATTR_TIMESTAMP, |
| | 456 | ktime_to_ns(tstamp), PSAMPLE_ATTR_PAD); |
| | 457 | if (unlikely(ret < 0)) |
| | 458 | goto error; |
| | 459 | |
| | 460 | ret = nla_put_u16(nl_skb, PSAMPLE_ATTR_PROTO, |
| | 461 | be16_to_cpu(skb->protocol)); |
| | 462 | if (unlikely(ret < 0)) |
| | 463 | goto error; |
| | 464 | |
| 428 | if (data_len) { | 465 | if (data_len) { |
| 429 | int nla_len = nla_total_size(data_len); | 466 | int nla_len = nla_total_size(data_len); |
| 430 | struct nlattr *nla; | 467 | struct nlattr *nla; |