@@ -132,7 +132,25 @@ int socket_bind_supported(void) {
132132 return can_link_bpf_program (obj -> progs .sd_bind4 );
133133}
134134
135- int socket_bind_install (Unit * u ) {
135+ int socket_bind_add_initial_link_fd (Unit * u , int fd ) {
136+ int r ;
137+
138+ assert (u );
139+
140+ if (!u -> initial_socket_bind_link_fds ) {
141+ u -> initial_socket_bind_link_fds = fdset_new ();
142+ if (!u -> initial_socket_bind_link_fds )
143+ return log_oom ();
144+ }
145+
146+ r = fdset_put (u -> initial_socket_bind_link_fds , fd );
147+ if (r < 0 )
148+ return log_unit_error_errno (u , r , "Failed to put socket-bind BPF link fd %d to initial fdset" , fd );
149+
150+ return 0 ;
151+ }
152+
153+ static int socket_bind_install_impl (Unit * u ) {
136154 _cleanup_ (bpf_link_freep ) struct bpf_link * ipv4 = NULL , * ipv6 = NULL ;
137155 _cleanup_ (socket_bind_bpf_freep ) struct socket_bind_bpf * obj = NULL ;
138156 _cleanup_free_ char * cgroup_path = NULL ;
@@ -177,14 +195,44 @@ int socket_bind_install(Unit *u) {
177195
178196 return 0 ;
179197}
198+
199+ int socket_bind_install (Unit * u ) {
200+ int r = socket_bind_install_impl (u );
201+ if (r == - ENOMEM )
202+ return r ;
203+
204+ fdset_close (u -> initial_socket_bind_link_fds );
205+
206+ return r ;
207+ }
208+
209+ int serialize_socket_bind (Unit * u , FILE * f , FDSet * fds ) {
210+ int r ;
211+
212+ assert (u );
213+
214+ r = serialize_bpf_link (f , fds , "ipv4-socket-bind-bpf-link" , u -> ipv4_socket_bind_link );
215+ if (r < 0 )
216+ return r ;
217+
218+ return serialize_bpf_link (f , fds , "ipv6-socket-bind-bpf-link" , u -> ipv6_socket_bind_link );
219+ }
220+
180221#else /* ! BPF_FRAMEWORK */
181222int socket_bind_supported (void ) {
182223 return 0 ;
183224}
184225
226+ int socket_bind_add_initial_link_fd (Unit * u , int fd ) {
227+ return 0 ;
228+ }
229+
185230int socket_bind_install (Unit * u ) {
186231 log_unit_debug (u , "Failed to install socket bind: BPF framework is not supported" );
187232 return 0 ;
188233}
189234
235+ int serialize_socket_bind (Unit * u , FILE * f , FDSet * fds ) {
236+ return 0 ;
237+ }
190238#endif
0 commit comments