Skip to content

Commit

Permalink
loxilb-io/loxilb#675 Initial support for proxy protocol v2
Browse files Browse the repository at this point in the history
  • Loading branch information
TrekkieCoder committed Nov 27, 2024
1 parent 38319bc commit e59b5b4
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 20 deletions.
38 changes: 19 additions & 19 deletions kernel/llb_kern_cdefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -1285,7 +1285,7 @@ dp_set_tcp_dst_ip6(void *md, struct xfi *xf, __be32 *xip)
bpf_l4_csum_replace(md, tcp_csum_off, old_dip[3], xip[3], BPF_F_PSEUDO_HDR |sizeof(*xip));
bpf_skb_store_bytes(md, ip_dst_off, xip, sizeof(xf->l34m.saddr), 0);

DP_XADDR_CP(xf->l34m.daddr, xip);
//DP_XADDR_CP(xf->l34m.daddr, xip);

return 0;
}
Expand All @@ -1301,7 +1301,7 @@ dp_set_tcp_dst_ip(void *md, struct xfi *xf, __be32 xip)
bpf_l4_csum_replace(md, tcp_csum_off, old_dip, xip, BPF_F_PSEUDO_HDR | sizeof(xip));
bpf_l3_csum_replace(md, ip_csum_off, old_dip, xip, sizeof(xip));
bpf_skb_store_bytes(md, ip_dst_off, &xip, sizeof(xip), 0);
xf->l34m.daddr4 = xip;
//xf->l34m.daddr4 = xip;

return 0;
}
Expand All @@ -1317,7 +1317,7 @@ dp_set_tcp_sport(void *md, struct xfi *xf, __be16 xport)

bpf_l4_csum_replace(md, tcp_csum_off, old_sport, xport, sizeof(xport));
bpf_skb_store_bytes(md, tcp_sport_off, &xport, sizeof(xport), 0);
xf->l34m.source = xport;
// xf->l34m.source = xport;

return 0;
}
Expand All @@ -1333,7 +1333,7 @@ dp_set_tcp_dport(void *md, struct xfi *xf, __be16 xport)

bpf_l4_csum_replace(md, tcp_csum_off, old_dport, xport, sizeof(xport));
bpf_skb_store_bytes(md, tcp_dport_off, &xport, sizeof(xport), 0);
xf->l34m.dest = xport;
//xf->l34m.dest = xport;

return 0;
}
Expand All @@ -1354,7 +1354,7 @@ dp_set_udp_src_ip6(void *md, struct xfi *xf, __be32 *xip)
bpf_l4_csum_replace(md, udp_csum_off, old_sip[3], xip[3], BPF_F_PSEUDO_HDR |sizeof(*xip));

bpf_skb_store_bytes(md, ip_src_off, xip, sizeof(xf->l34m.saddr), 0);
DP_XADDR_CP(xf->l34m.saddr, xip);
//DP_XADDR_CP(xf->l34m.saddr, xip);

return 0;
}
Expand Down Expand Up @@ -1393,7 +1393,7 @@ dp_set_udp_dst_ip6(void *md, struct xfi *xf, __be32 *xip)
bpf_l4_csum_replace(md, udp_csum_off, old_dip[2], xip[2], BPF_F_PSEUDO_HDR |sizeof(*xip));
bpf_l4_csum_replace(md, udp_csum_off, old_dip[3], xip[3], BPF_F_PSEUDO_HDR |sizeof(*xip));
bpf_skb_store_bytes(md, ip_dst_off, xip, sizeof(xf->l34m.daddr), 0);
DP_XADDR_CP(xf->l34m.daddr, xip);
//DP_XADDR_CP(xf->l34m.daddr, xip);

return 0;
}
Expand All @@ -1412,7 +1412,7 @@ dp_set_udp_dst_ip(void *md, struct xfi *xf, __be32 xip)
bpf_l4_csum_replace(md, udp_csum_off, old_dip, xip, BPF_F_PSEUDO_HDR | sizeof(xip));
bpf_l3_csum_replace(md, ip_csum_off, old_dip, xip, sizeof(xip));
bpf_skb_store_bytes(md, ip_dst_off, &xip, sizeof(xip), 0);
xf->l34m.daddr4 = xip;
//xf->l34m.daddr4 = xip;

return 0;
}
Expand All @@ -1431,7 +1431,7 @@ dp_set_udp_sport(void *md, struct xfi *xf, __be16 xport)
//bpf_skb_store_bytes(md, udp_csum_off, &csum, sizeof(csum), 0);
bpf_l4_csum_replace(md, udp_csum_off, old_sport, xport, sizeof(xport));
bpf_skb_store_bytes(md, udp_sport_off, &xport, sizeof(xport), 0);
xf->l34m.source = xport;
//xf->l34m.source = xport;

return 0;
}
Expand All @@ -1450,7 +1450,7 @@ dp_set_udp_dport(void *md, struct xfi *xf, __be16 xport)
//bpf_skb_store_bytes(md, udp_csum_off, &csum, sizeof(csum), 0);
bpf_l4_csum_replace(md, udp_csum_off, old_dport, xport, sizeof(xport));
bpf_skb_store_bytes(md, udp_dport_off, &xport, sizeof(xport), 0);
xf->l34m.dest = xport;
//xf->l34m.dest = xport;

return 0;
}
Expand All @@ -1461,7 +1461,7 @@ dp_set_icmp_src_ip6(void *md, struct xfi *xf, __be32 *xip)
int ip_src_off = xf->pm.l3_off + offsetof(struct ipv6hdr, saddr);

bpf_skb_store_bytes(md, ip_src_off, xip, sizeof(struct in6_addr), 0);
DP_XADDR_CP(xf->l34m.saddr, xip);
//DP_XADDR_CP(xf->l34m.saddr, xip);

return 0;
}
Expand All @@ -1475,7 +1475,7 @@ dp_set_icmp_src_ip(void *md, struct xfi *xf, __be32 xip)

bpf_l3_csum_replace(md, ip_csum_off, old_sip, xip, sizeof(xip));
bpf_skb_store_bytes(md, ip_src_off, &xip, sizeof(xip), 0);
xf->l34m.saddr4 = xip;
//xf->l34m.saddr4 = xip;

return 0;
}
Expand All @@ -1486,7 +1486,7 @@ dp_set_icmp_dst_ip6(void *md, struct xfi *xf, __be32 *xip)
int ip_dst_off = xf->pm.l3_off + offsetof(struct ipv6hdr, daddr);

bpf_skb_store_bytes(md, ip_dst_off, xip, sizeof(struct in6_addr), 0);
DP_XADDR_CP(xf->l34m.daddr, xip);
//DP_XADDR_CP(xf->l34m.daddr, xip);

return 0;
}
Expand All @@ -1500,7 +1500,7 @@ dp_set_icmp_dst_ip(void *md, struct xfi *xf, __be32 xip)

bpf_l3_csum_replace(md, ip_csum_off, old_dip, xip, sizeof(xip));
bpf_skb_store_bytes(md, ip_dst_off, &xip, sizeof(xip), 0);
xf->l34m.daddr4 = xip;
//xf->l34m.daddr4 = xip;

return 0;
}
Expand All @@ -1511,7 +1511,7 @@ dp_set_sctp_src_ip6(void *md, struct xfi *xf, __be32 *xip)
int ip_src_off = xf->pm.l3_off + offsetof(struct ipv6hdr, saddr);

bpf_skb_store_bytes(md, ip_src_off, xip, sizeof(struct in6_addr), 0);
DP_XADDR_CP(xf->l34m.saddr, xip);
//DP_XADDR_CP(xf->l34m.saddr, xip);

return 0;
}
Expand All @@ -1535,7 +1535,7 @@ dp_set_sctp_src_ip(void *md, struct xfi *xf, __be32 xip)
}
bpf_l3_csum_replace(md, ip_csum_off, old_sip, xip, sizeof(xip));
bpf_skb_store_bytes(md, ip_src_off, &xip, sizeof(xip), 0);
xf->l34m.saddr4 = xip;
//xf->l34m.saddr4 = xip;

return 0;
}
Expand All @@ -1546,7 +1546,7 @@ dp_set_sctp_dst_ip6(void *md, struct xfi *xf, __be32 *xip)
int ip_dst_off = xf->pm.l3_off + offsetof(struct ipv6hdr, daddr);

bpf_skb_store_bytes(md, ip_dst_off, xip, sizeof(struct in6_addr), 0);
DP_XADDR_CP(xf->l34m.daddr, xip);
//DP_XADDR_CP(xf->l34m.daddr, xip);

return 0;
}
Expand All @@ -1571,7 +1571,7 @@ dp_set_sctp_dst_ip(void *md, struct xfi *xf, __be32 xip)

bpf_l3_csum_replace(md, ip_csum_off, old_dip, xip, sizeof(xip));
bpf_skb_store_bytes(md, ip_dst_off, &xip, sizeof(xip), 0);
xf->l34m.daddr4 = xip;
//xf->l34m.daddr4 = xip;

return 0;
}
Expand All @@ -1587,7 +1587,7 @@ dp_set_sctp_sport(void *md, struct xfi *xf, __be16 xport)

bpf_skb_store_bytes(md, sctp_csum_off, &csum , sizeof(csum), 0);
bpf_skb_store_bytes(md, sctp_sport_off, &xport, sizeof(xport), 0);
xf->l34m.source = xport;
//xf->l34m.source = xport;

return 0;
}
Expand All @@ -1603,7 +1603,7 @@ dp_set_sctp_dport(void *md, struct xfi *xf, __be16 xport)

bpf_skb_store_bytes(md, sctp_csum_off, &csum , sizeof(csum), 0);
bpf_skb_store_bytes(md, sctp_dport_off, &xport, sizeof(xport), 0);
xf->l34m.dest = xport;
//xf->l34m.dest = xport;

return 0;
}
Expand Down
3 changes: 2 additions & 1 deletion kernel/loxilb_libdp.c
Original file line number Diff line number Diff line change
Expand Up @@ -2585,7 +2585,8 @@ ll_ct_get_state(struct dp_ct_key *key, struct dp_ct_tact *adat, bool *est, uint6
ts->state & CT_TCP_SYNC_MASK ||
ts->state == CT_TCP_CLOSED) {
*to = CT_TCP_FN_CPTO;
} else if (ts->state == CT_TCP_EST) {
} else if (ts->state == CT_TCP_EST ||
ts->state == CT_TCP_PEST ) {
*est = true;
}
} else if (key->l4proto == IPPROTO_UDP) {
Expand Down

0 comments on commit e59b5b4

Please sign in to comment.