-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
50acd9a
commit d7d7d0d
Showing
23 changed files
with
233 additions
and
256 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -49,8 +49,6 @@ struct | |
|
||
static inline int throttle_flow(struct __sk_buff *skb, __u32 ip_address, uint32_t *throttle_rate_kbps) | ||
{ | ||
// use ip as key in map | ||
int key = ip_address; | ||
|
||
// find out if the packet should be dropped (i.e. if the rate is 0) | ||
if (*throttle_rate_kbps == 0) | ||
|
@@ -68,6 +66,9 @@ static inline int throttle_flow(struct __sk_buff *skb, __u32 ip_address, uint32_ | |
// return TC_ACT_OK; | ||
} | ||
|
||
// use ip as key in map | ||
uint32_t key = ip_address; | ||
|
||
// when was the last packet sent? | ||
uint64_t *last_tstamp = bpf_map_lookup_elem(&flow_map, &key); | ||
// calculate delay between packets based on bandwidth and packet size (kbps = byte/1000/second) | ||
|
@@ -92,7 +93,6 @@ static inline int throttle_flow(struct __sk_buff *skb, __u32 ip_address, uint32_ | |
// if it does not work, drop the packet | ||
if (bpf_map_update_elem(&flow_map, &key, &tstamp, BPF_ANY)) | ||
return TC_ACT_SHOT; | ||
// return TC_ACT_OK; | ||
|
||
return TC_ACT_OK; | ||
} | ||
|
@@ -108,7 +108,6 @@ static inline int throttle_flow(struct __sk_buff *skb, __u32 ip_address, uint32_ | |
// update last timestamp in map | ||
if (bpf_map_update_elem(&flow_map, &key, &next_tstamp, BPF_EXIST)) | ||
return TC_ACT_SHOT; | ||
// return TC_ACT_OK; | ||
|
||
// set delayed timestamp for packet | ||
skb->tstamp = next_tstamp; | ||
|
@@ -119,20 +118,18 @@ static inline int throttle_flow(struct __sk_buff *skb, __u32 ip_address, uint32_ | |
|
||
static inline int inject_delay(struct __sk_buff *skb, uint32_t *delay_us) | ||
{ | ||
uint64_t delay_ns; | ||
uint64_t now = bpf_ktime_get_ns(); | ||
delay_ns = (*delay_us) * NS_PER_US; | ||
uint64_t ts = skb->tstamp; | ||
uint64_t new_ts = ((uint64_t)skb->tstamp) + delay_ns; | ||
uint64_t delay_ns = (*delay_us) * NS_PER_US; | ||
|
||
// sometimes skb-tstamp is reset to 0 | ||
// https://patchwork.kernel.org/project/netdevbpf/patch/[email protected]/ | ||
// check if skb->tstamp == 0 | ||
if (ts == 0) | ||
if (skb->tstamp == 0) | ||
{ | ||
skb->tstamp = now + delay_ns; | ||
skb->tstamp = bpf_ktime_get_ns() + delay_ns; | ||
return TC_ACT_OK; | ||
} | ||
|
||
uint64_t new_ts = ((uint64_t)skb->tstamp) + delay_ns; | ||
// otherwise add additional delay to packets | ||
skb->tstamp = new_ts; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.