@@ -29,24 +29,6 @@ struct {
2929 __uint (map_flags , 0 );
3030} map_of_kmesh_socket SEC (".maps" );
3131
32- static inline bool is_managed_by_kmesh (struct bpf_sock_ops * skops )
33- {
34- struct manager_key key = {0 };
35- if (skops -> family == AF_INET )
36- key .addr .ip4 = skops -> local_ip4 ;
37- if (skops -> family == AF_INET6 ) {
38- if (is_ipv4_mapped_addr (skops -> local_ip6 ))
39- key .addr .ip4 = skops -> local_ip6 [3 ];
40- else
41- IP6_COPY (key .addr .ip6 , skops -> local_ip6 );
42- }
43-
44- int * value = bpf_map_lookup_elem (& map_of_manager , & key );
45- if (!value )
46- return false;
47- return (* value == 0 );
48- }
49-
5032static inline bool skip_specific_probe (struct bpf_sock_ops * skops )
5133{
5234 struct kmesh_config * data = {0 };
@@ -182,70 +164,6 @@ static inline void enable_encoding_metadata(struct bpf_sock_ops *skops)
182164 BPF_LOG (ERR , SOCKOPS , "enable encoding metadata failed!, err is %d" , err );
183165}
184166
185- static inline void record_kmesh_managed_ip (__u32 family , __u32 ip4 , __u32 * ip6 )
186- {
187- int err ;
188- __u32 value = 0 ;
189- struct manager_key key = {0 };
190- if (family == AF_INET )
191- key .addr .ip4 = ip4 ;
192- if (family == AF_INET6 && ip6 )
193- IP6_COPY (key .addr .ip6 , ip6 );
194-
195- err = bpf_map_update_elem (& map_of_manager , & key , & value , BPF_ANY );
196- if (err )
197- BPF_LOG (ERR , KMESH , "record ip failed!, err is %d\n" , err );
198- }
199-
200- static inline void remove_kmesh_managed_ip (__u32 family , __u32 ip4 , __u32 * ip6 )
201- {
202- struct manager_key key = {0 };
203- if (family == AF_INET )
204- key .addr .ip4 = ip4 ;
205- if (family == AF_INET6 && ip6 )
206- IP6_COPY (key .addr .ip6 , ip6 );
207-
208- int err = bpf_map_delete_elem (& map_of_manager , & key );
209- if (err && err != - ENOENT )
210- BPF_LOG (ERR , KMESH , "remove ip failed!, err is %d\n" , err );
211- }
212-
213- static inline bool conn_from_sim (struct bpf_sock_ops * skops , __u32 ip , __u16 port )
214- {
215- __u16 remote_port = GET_SKOPS_REMOTE_PORT (skops );
216- if (bpf_ntohs (remote_port ) != port )
217- return false;
218-
219- if (skops -> family == AF_INET )
220- return (bpf_ntohl (skops -> remote_ip4 ) == ip );
221-
222- return (
223- skops -> remote_ip6 [0 ] == 0 && skops -> remote_ip6 [1 ] == 0 && skops -> remote_ip6 [2 ] == 0
224- && bpf_ntohl (skops -> remote_ip6 [3 ]) == ip );
225- }
226-
227- static inline bool skops_conn_from_cni_sim_add (struct bpf_sock_ops * skops )
228- {
229- // cni sim connect CONTROL_CMD_IP:929(0x3a1)
230- // 0x3a1 is the specific port handled by the cni to enable Kmesh
231- return conn_from_sim (skops , CONTROL_CMD_IP , ENABLE_KMESH_PORT );
232- }
233-
234- static inline bool skops_conn_from_cni_sim_delete (struct bpf_sock_ops * skops )
235- {
236- // cni sim connect CONTROL_CMD_IP:930(0x3a2)
237- // 0x3a2 is the specific port handled by the cni to disable Kmesh
238- return conn_from_sim (skops , CONTROL_CMD_IP , DISABLE_KMESH_PORT );
239- }
240-
241- static inline void skops_handle_kmesh_managed_process (struct bpf_sock_ops * skops )
242- {
243- if (skops_conn_from_cni_sim_add (skops ))
244- record_kmesh_managed_ip (skops -> family , skops -> local_ip4 , skops -> local_ip6 );
245- if (skops_conn_from_cni_sim_delete (skops ))
246- remove_kmesh_managed_ip (skops -> family , skops -> local_ip4 , skops -> local_ip6 );
247- }
248-
249167SEC ("sockops" )
250168int sockops_prog (struct bpf_sock_ops * skops )
251169{
0 commit comments