From 268a52a9344b84a8170eac712dcf7f75d0c35732 Mon Sep 17 00:00:00 2001 From: mzz2017 <2017@duck.com> Date: Wed, 1 Feb 2023 11:10:41 +0800 Subject: [PATCH] fix: remove unsupported (on old kernel) bpf_skb_adjust_room flag BPF_F_ADJ_ROOM_NO_CSUM_RESET --- cmd/run.go | 5 ++++- component/control/kern/tproxy.c | 22 ++++++++++++---------- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/cmd/run.go b/cmd/run.go index 2a735cf..9adfcc2 100644 --- a/cmd/run.go +++ b/cmd/run.go @@ -21,6 +21,9 @@ var ( Use: "run", Short: "Run dae in the foreground", Run: func(cmd *cobra.Command, args []string) { + if cfgFile == "" { + logrus.Fatalln("Argument \"--config\" or \"-c\" is required but not provided.") + } if err := Run(); err != nil { logrus.Fatalln(err) } @@ -29,7 +32,7 @@ var ( ) func init() { - runCmd.PersistentFlags().StringVarP(&cfgFile, "config", "c", "config.dae", "config file") + runCmd.PersistentFlags().StringVarP(&cfgFile, "config", "c", "", "config file") } func Run() (err error) { diff --git a/component/control/kern/tproxy.c b/component/control/kern/tproxy.c index 4dd74a4..e5c3bef 100644 --- a/component/control/kern/tproxy.c +++ b/component/control/kern/tproxy.c @@ -689,9 +689,8 @@ static __always_inline int encap_after_udp_hdr(struct __sk_buff *skb, return ret; } // Add room for new udp payload header. - if ((ret = bpf_skb_adjust_room(skb, newhdrlen, BPF_ADJ_ROOM_NET, - BPF_F_ADJ_ROOM_NO_CSUM_RESET))) { - bpf_printk("UDP ADJUST ROOM: %d", ret); + if ((ret = bpf_skb_adjust_room(skb, newhdrlen, BPF_ADJ_ROOM_NET, 0))) { + bpf_printk("UDP ADJUST ROOM(encap): %d", ret); return ret; } // Move the new room to the front of the UDP payload. @@ -776,9 +775,8 @@ static __always_inline int decap_after_udp_hdr(struct __sk_buff *skb, } // Adjust room to decap the header. - if ((ret = bpf_skb_adjust_room(skb, -decap_hdrlen, BPF_ADJ_ROOM_NET, - BPF_F_ADJ_ROOM_NO_CSUM_RESET))) { - bpf_printk("UDP ADJUST ROOM: %d", ret); + if ((ret = bpf_skb_adjust_room(skb, -decap_hdrlen, BPF_ADJ_ROOM_NET, 0))) { + bpf_printk("UDP ADJUST ROOM(decap): %d", ret); return ret; } @@ -1191,8 +1189,10 @@ int tproxy_ingress(struct __sk_buff *skb) { // Rewrite to control plane. // Encap a header to transmit fullcone tuple. - encap_after_udp_hdr(skb, ipversion, ihl, ipv4_tot_len, &new_hdr, - sizeof(new_hdr)); + if ((ret = encap_after_udp_hdr(skb, ipversion, ihl, ipv4_tot_len, + &new_hdr, sizeof(new_hdr)))) { + return TC_ACT_SHOT; + } // Rewrite udp dst ip. // bpf_printk("rewrite dst ip from %pI4", &ori_dst.ip); @@ -1692,8 +1692,10 @@ int tproxy_wan_egress(struct __sk_buff *skb) { }; // Encap a header to transmit fullcone tuple. - encap_after_udp_hdr(skb, ipversion, ihl, ipv4_tot_len, &new_hdr, - sizeof(new_hdr)); + if ((ret = encap_after_udp_hdr(skb, ipversion, ihl, ipv4_tot_len, + &new_hdr, sizeof(new_hdr)))) { + return TC_ACT_SHOT; + } // Redirect from egress to ingress. if ((ret = bpf_redirect(skb->ifindex, BPF_F_INGRESS)) == TC_ACT_SHOT) {