@@ -962,10 +962,9 @@ static __always_inline void prep_redirect_to_control_plane(
962
962
__builtin_memcpy (& redirect_tuple .dip , & tuples -> five .dip ,
963
963
IPV6_BYTE_LENGTH );
964
964
}
965
- struct redirect_entry redirect_entry = {};
965
+ struct redirect_entry redirect_entry = { .ifindex = skb -> ifindex ,
966
+ .from_wan = from_wan };
966
967
967
- redirect_entry .ifindex = skb -> ifindex ;
968
- redirect_entry .from_wan = from_wan ;
969
968
__builtin_memcpy (redirect_entry .smac , ethh -> h_source ,
970
969
sizeof (ethh -> h_source ));
971
970
__builtin_memcpy (redirect_entry .dmac , ethh -> h_dest ,
@@ -1124,12 +1123,11 @@ int tproxy_lan_ingress(struct __sk_buff *skb)
1124
1123
bpf_printk ("shot routing: %d" , s64_ret );
1125
1124
return TC_ACT_SHOT ;
1126
1125
}
1127
- struct routing_result routing_result = { 0 };
1126
+ struct routing_result routing_result = { .outbound = s64_ret ,
1127
+ .mark = s64_ret >> 8 ,
1128
+ .must = (s64_ret >> 40 ) & 1 ,
1129
+ .dscp = tuples .dscp };
1128
1130
1129
- routing_result .outbound = s64_ret ;
1130
- routing_result .mark = s64_ret >> 8 ;
1131
- routing_result .must = (s64_ret >> 40 ) & 1 ;
1132
- routing_result .dscp = tuples .dscp ;
1133
1131
__builtin_memcpy (routing_result .mac , ethh .h_source ,
1134
1132
sizeof (routing_result .mac ));
1135
1133
/// NOTICE: No pid pname info for LAN packet.
@@ -1170,11 +1168,12 @@ int tproxy_lan_ingress(struct __sk_buff *skb)
1170
1168
}
1171
1169
1172
1170
// Check outbound connectivity in specific ipversion and l4proto.
1173
- struct outbound_connectivity_query q = { 0 };
1171
+ struct outbound_connectivity_query q = {
1172
+ .outbound = routing_result .outbound ,
1173
+ .ipversion = skb -> protocol == bpf_htons (ETH_P_IP ) ? 4 : 6 ,
1174
+ .l4proto = l4proto
1175
+ };
1174
1176
1175
- q .outbound = routing_result .outbound ;
1176
- q .ipversion = skb -> protocol == bpf_htons (ETH_P_IP ) ? 4 : 6 ;
1177
- q .l4proto = l4proto ;
1178
1177
__u32 * alive ;
1179
1178
1180
1179
alive = bpf_map_lookup_elem (& outbound_connectivity_map , & q );
@@ -1272,13 +1271,11 @@ refresh_udp_conn_state_timer(struct tuples_key *key, bool is_egress)
1272
1271
{
1273
1272
struct udp_conn_state * old_conn_state =
1274
1273
bpf_map_lookup_elem (& udp_conn_state_map , key );
1275
- struct udp_conn_state new_conn_state = { 0 };
1274
+ struct udp_conn_state new_conn_state = {
1275
+ .is_egress = old_conn_state ? old_conn_state -> is_egress :
1276
+ is_egress
1277
+ };
1276
1278
1277
- if (old_conn_state )
1278
- new_conn_state .is_egress =
1279
- old_conn_state -> is_egress ; // Keep the value.
1280
- else
1281
- new_conn_state .is_egress = is_egress ;
1282
1279
long ret = bpf_map_update_elem (& udp_conn_state_map , key ,
1283
1280
& new_conn_state , BPF_ANY );
1284
1281
if (unlikely (ret ))
@@ -1463,11 +1460,13 @@ int tproxy_wan_egress(struct __sk_buff *skb)
1463
1460
// Rewrite to control plane.
1464
1461
1465
1462
// Check outbound connectivity in specific ipversion and l4proto.
1466
- struct outbound_connectivity_query q = { 0 };
1463
+ struct outbound_connectivity_query q = {
1464
+ .outbound = outbound ,
1465
+ .ipversion = skb -> protocol == bpf_htons (ETH_P_IP ) ? 4 :
1466
+ 6 ,
1467
+ .l4proto = l4proto
1468
+ };
1467
1469
1468
- q .outbound = outbound ;
1469
- q .ipversion = skb -> protocol == bpf_htons (ETH_P_IP ) ? 4 : 6 ;
1470
- q .l4proto = l4proto ;
1471
1470
__u32 * alive ;
1472
1471
1473
1472
alive = bpf_map_lookup_elem (& outbound_connectivity_map , & q );
@@ -1479,12 +1478,13 @@ int tproxy_wan_egress(struct __sk_buff *skb)
1479
1478
}
1480
1479
1481
1480
if (unlikely (tcp_state_syn )) {
1482
- struct routing_result routing_result = {};
1481
+ struct routing_result routing_result = {
1482
+ .outbound = outbound ,
1483
+ .mark = mark ,
1484
+ .must = must ,
1485
+ .dscp = tuples .dscp
1486
+ };
1483
1487
1484
- routing_result .outbound = outbound ;
1485
- routing_result .mark = mark ;
1486
- routing_result .must = must ;
1487
- routing_result .dscp = tuples .dscp ;
1488
1488
__builtin_memcpy (routing_result .mac , ethh .h_source ,
1489
1489
sizeof (ethh .h_source ));
1490
1490
if (pid_pname ) {
@@ -1546,12 +1546,13 @@ int tproxy_wan_egress(struct __sk_buff *skb)
1546
1546
return TC_ACT_SHOT ;
1547
1547
}
1548
1548
// Construct new hdr to encap.
1549
- struct routing_result routing_result = {};
1549
+ struct routing_result routing_result = {
1550
+ .outbound = s64_ret ,
1551
+ .mark = s64_ret >> 8 ,
1552
+ .must = (s64_ret >> 40 ) & 1 ,
1553
+ .dscp = tuples .dscp
1554
+ };
1550
1555
1551
- routing_result .outbound = s64_ret ;
1552
- routing_result .mark = s64_ret >> 8 ;
1553
- routing_result .must = (s64_ret >> 40 ) & 1 ;
1554
- routing_result .dscp = tuples .dscp ;
1555
1556
__builtin_memcpy (routing_result .mac , ethh .h_source ,
1556
1557
sizeof (ethh .h_source ));
1557
1558
if (pid_pname ) {
@@ -1586,11 +1587,13 @@ int tproxy_wan_egress(struct __sk_buff *skb)
1586
1587
// Rewrite to control plane.
1587
1588
1588
1589
// Check outbound connectivity in specific ipversion and l4proto.
1589
- struct outbound_connectivity_query q = { 0 };
1590
+ struct outbound_connectivity_query q = {
1591
+ .outbound = routing_result .outbound ,
1592
+ .ipversion = skb -> protocol == bpf_htons (ETH_P_IP ) ? 4 :
1593
+ 6 ,
1594
+ .l4proto = l4proto
1595
+ };
1590
1596
1591
- q .outbound = routing_result .outbound ;
1592
- q .ipversion = skb -> protocol == bpf_htons (ETH_P_IP ) ? 4 : 6 ;
1593
- q .l4proto = l4proto ;
1594
1597
__u32 * alive ;
1595
1598
1596
1599
alive = bpf_map_lookup_elem (& outbound_connectivity_map , & q );
@@ -1766,9 +1769,9 @@ static __always_inline int update_map_elem_by_cookie(const __u64 cookie)
1766
1769
ret = _update_map_elem_by_cookie (cookie );
1767
1770
if (ret ) {
1768
1771
// Fallback to only write pid to avoid loop due to packets sent by dae.
1769
- struct pid_pname val = { 0 };
1772
+ struct pid_pname val = { .pid = bpf_get_current_pid_tgid () >>
1773
+ 32 };
1770
1774
1771
- val .pid = bpf_get_current_pid_tgid () >> 32 ;
1772
1775
__u32 (* pname )[TASK_COMM_LEN ] =
1773
1776
bpf_map_lookup_elem (& tgid_pname_map , & val .pid );
1774
1777
if (pname ) {
@@ -1844,11 +1847,12 @@ int local_tcp_sockops(struct bpf_sock_ops *skops)
1844
1847
if (pid == 0 )
1845
1848
return 0 ;
1846
1849
1847
- struct tuples_key tuple = {};
1850
+ struct tuples_key tuple = {
1851
+ .l4proto = IPPROTO_TCP ,
1852
+ .sport = bpf_htonl (skops -> local_port ) >> 16 ,
1853
+ .dport = skops -> remote_port >> 16 ,
1854
+ };
1848
1855
1849
- tuple .l4proto = IPPROTO_TCP ;
1850
- tuple .sport = bpf_htonl (skops -> local_port ) >> 16 ;
1851
- tuple .dport = skops -> remote_port >> 16 ;
1852
1856
if (skops -> family == AF_INET ) {
1853
1857
tuple .sip .u6_addr32 [2 ] = bpf_htonl (0x0000ffff );
1854
1858
tuple .sip .u6_addr32 [3 ] = skops -> local_ip4 ;
@@ -1870,17 +1874,14 @@ int local_tcp_sockops(struct bpf_sock_ops *skops)
1870
1874
switch (skops -> op ) {
1871
1875
case BPF_SOCK_OPS_PASSIVE_ESTABLISHED_CB : // dae sockets
1872
1876
{
1873
- struct tuples_key rev_tuple = {};
1877
+ struct tuples_key rev_tuple = { .l4proto = IPPROTO_TCP ,
1878
+ .sport = tuple .dport ,
1879
+ .dport = tuple .sport };
1874
1880
1875
- rev_tuple .l4proto = IPPROTO_TCP ;
1876
- rev_tuple .sport = tuple .dport ;
1877
- rev_tuple .dport = tuple .sport ;
1878
1881
__builtin_memcpy (& rev_tuple .sip , & tuple .dip , IPV6_BYTE_LENGTH );
1879
1882
__builtin_memcpy (& rev_tuple .dip , & tuple .sip , IPV6_BYTE_LENGTH );
1880
1883
1881
- struct routing_result * routing_result ;
1882
-
1883
- routing_result =
1884
+ struct routing_result * routing_result =
1884
1885
bpf_map_lookup_elem (& routing_tuples_map , & rev_tuple );
1885
1886
if (!routing_result || !routing_result -> pid )
1886
1887
break ;
@@ -1896,9 +1897,7 @@ int local_tcp_sockops(struct bpf_sock_ops *skops)
1896
1897
1897
1898
case BPF_SOCK_OPS_ACTIVE_ESTABLISHED_CB : // local client sockets
1898
1899
{
1899
- struct routing_result * routing_result ;
1900
-
1901
- routing_result =
1900
+ struct routing_result * routing_result =
1902
1901
bpf_map_lookup_elem (& routing_tuples_map , & tuple );
1903
1902
if (!routing_result || !routing_result -> pid )
1904
1903
break ;
@@ -1922,11 +1921,11 @@ int local_tcp_sockops(struct bpf_sock_ops *skops)
1922
1921
SEC ("sk_msg/fast_redirect" )
1923
1922
int sk_msg_fast_redirect (struct sk_msg_md * msg )
1924
1923
{
1925
- struct tuples_key rev_tuple = {};
1924
+ struct tuples_key rev_tuple = { .l4proto = IPPROTO_TCP ,
1925
+ .sport = msg -> remote_port >> 16 ,
1926
+ .dport = bpf_htonl (msg -> local_port ) >>
1927
+ 16 };
1926
1928
1927
- rev_tuple .l4proto = IPPROTO_TCP ;
1928
- rev_tuple .sport = msg -> remote_port >> 16 ;
1929
- rev_tuple .dport = bpf_htonl (msg -> local_port ) >> 16 ;
1930
1929
if (msg -> family == AF_INET ) {
1931
1930
rev_tuple .sip .u6_addr32 [2 ] = bpf_htonl (0x0000ffff );
1932
1931
rev_tuple .sip .u6_addr32 [3 ] = msg -> remote_ip4 ;
0 commit comments