@@ -235,34 +235,12 @@ static void log_neighbor_debug(const Neighbor *neighbor, const char *str, const
235235 "%s neighbor: lladdr: %s, dst: %s" ,
236236 str , strna (lladdr ), strna (dst ));
237237}
238+ static int neighbor_configure (
239+ const Neighbor * neighbor ,
240+ Link * link ,
241+ link_netlink_message_handler_t callback ,
242+ Neighbor * * ret ) {
238243
239- static int neighbor_configure_handler (sd_netlink * rtnl , sd_netlink_message * m , Link * link ) {
240- int r ;
241-
242- assert (m );
243- assert (link );
244- assert (link -> neighbor_messages > 0 );
245-
246- link -> neighbor_messages -- ;
247-
248- if (IN_SET (link -> state , LINK_STATE_FAILED , LINK_STATE_LINGER ))
249- return 1 ;
250-
251- r = sd_netlink_message_get_errno (m );
252- if (r < 0 && r != - EEXIST )
253- /* Neighbor may not exist yet. So, do not enter failed state here. */
254- log_link_message_warning_errno (link , m , r , "Could not set neighbor, ignoring" );
255-
256- if (link -> neighbor_messages == 0 ) {
257- log_link_debug (link , "Neighbors set" );
258- link -> neighbors_configured = true;
259- link_check_ready (link );
260- }
261-
262- return 1 ;
263- }
264-
265- static int neighbor_configure (Neighbor * neighbor , Link * link ) {
266244 _cleanup_ (sd_netlink_message_unrefp ) sd_netlink_message * req = NULL ;
267245 int r ;
268246
@@ -271,6 +249,7 @@ static int neighbor_configure(Neighbor *neighbor, Link *link) {
271249 assert (link -> ifindex > 0 );
272250 assert (link -> manager );
273251 assert (link -> manager -> rtnl );
252+ assert (callback );
274253
275254 log_neighbor_debug (neighbor , "Configuring" , link );
276255
@@ -291,21 +270,47 @@ static int neighbor_configure(Neighbor *neighbor, Link *link) {
291270 if (r < 0 )
292271 return log_link_error_errno (link , r , "Could not append NDA_DST attribute: %m" );
293272
294- r = netlink_call_async (link -> manager -> rtnl , NULL , req , neighbor_configure_handler ,
273+ r = netlink_call_async (link -> manager -> rtnl , NULL , req , callback ,
295274 link_netlink_destroy_callback , link );
296275 if (r < 0 )
297276 return log_link_error_errno (link , r , "Could not send rtnetlink message: %m" );
298277
299278 link -> neighbor_messages ++ ;
300279 link_ref (link );
301280
302- r = neighbor_add (link , neighbor , NULL );
281+ r = neighbor_add (link , neighbor , ret );
303282 if (r < 0 )
304283 return log_link_error_errno (link , r , "Could not add neighbor: %m" );
305284
306285 return r ;
307286}
308287
288+ static int static_neighbor_configure_handler (sd_netlink * rtnl , sd_netlink_message * m , Link * link ) {
289+ int r ;
290+
291+ assert (m );
292+ assert (link );
293+ assert (link -> neighbor_messages > 0 );
294+
295+ link -> neighbor_messages -- ;
296+
297+ if (IN_SET (link -> state , LINK_STATE_FAILED , LINK_STATE_LINGER ))
298+ return 1 ;
299+
300+ r = sd_netlink_message_get_errno (m );
301+ if (r < 0 && r != - EEXIST )
302+ /* Neighbor may not exist yet. So, do not enter failed state here. */
303+ log_link_message_warning_errno (link , m , r , "Could not set neighbor, ignoring" );
304+
305+ if (link -> neighbor_messages == 0 ) {
306+ log_link_debug (link , "Neighbors set" );
307+ link -> neighbors_configured = true;
308+ link_check_ready (link );
309+ }
310+
311+ return 1 ;
312+ }
313+
309314int link_set_neighbors (Link * link ) {
310315 Neighbor * neighbor ;
311316 int r ;
@@ -322,7 +327,7 @@ int link_set_neighbors(Link *link) {
322327 link -> neighbors_configured = false;
323328
324329 HASHMAP_FOREACH (neighbor , link -> network -> neighbors_by_section ) {
325- r = neighbor_configure (neighbor , link );
330+ r = neighbor_configure (neighbor , link , static_neighbor_configure_handler , NULL );
326331 if (r < 0 )
327332 return log_link_warning_errno (link , r , "Could not set neighbor: %m" );
328333 }
0 commit comments