@@ -133,11 +133,12 @@ local_notify_interface(struct interface *ifp, int kind)
133133{
134134 int i ;
135135 for (i = 0 ; i < num_local_sockets ; i ++ ) {
136- if (local_sockets [i ].monitor )
136+ if (local_sockets [i ].monitor & ( 0x01 << SHOW_INTERFACE ) )
137137 local_notify_interface_1 (& local_sockets [i ], ifp , kind );
138138 }
139139}
140140
141+
141142static void
142143local_notify_neighbour_1 (struct local_socket * s ,
143144 struct neighbour * neigh , int kind )
@@ -188,7 +189,7 @@ local_notify_neighbour(struct neighbour *neigh, int kind)
188189{
189190 int i ;
190191 for (i = 0 ; i < num_local_sockets ; i ++ ) {
191- if (local_sockets [i ].monitor )
192+ if (local_sockets [i ].monitor & ( 0x01 << SHOW_NEIGHBOUR ) )
192193 local_notify_neighbour_1 (& local_sockets [i ], neigh , kind );
193194 }
194195}
@@ -225,7 +226,7 @@ local_notify_xroute(struct xroute *xroute, int kind)
225226{
226227 int i ;
227228 for (i = 0 ; i < num_local_sockets ; i ++ ) {
228- if (local_sockets [i ].monitor )
229+ if (local_sockets [i ].monitor & ( 0x01 << SHOW_XROUTE ) )
229230 local_notify_xroute_1 (& local_sockets [i ], xroute , kind );
230231 }
231232}
@@ -270,26 +271,36 @@ local_notify_route(struct babel_route *route, int kind)
270271{
271272 int i ;
272273 for (i = 0 ; i < num_local_sockets ; i ++ ) {
273- if (local_sockets [i ].monitor )
274+ if (local_sockets [i ].monitor & ( 0x01 << SHOW_ROUTE ) )
274275 local_notify_route_1 (& local_sockets [i ], route , kind );
275276 }
276277}
277278
279+
278280static void
279- local_notify_all_1 (struct local_socket * s )
281+ local_notify_all_neighbour_1 (struct local_socket * s )
280282{
281- struct interface * ifp ;
282283 struct neighbour * neigh ;
283- struct xroute_stream * xroutes ;
284- struct route_stream * routes ;
284+
285+ FOR_ALL_NEIGHBOURS (neigh ) {
286+ local_notify_neighbour_1 (s , neigh , LOCAL_ADD );
287+ }
288+ }
289+
290+ static void
291+ local_notify_all_interface_1 (struct local_socket * s )
292+ {
293+ struct interface * ifp ;
285294
286295 FOR_ALL_INTERFACES (ifp ) {
287296 local_notify_interface_1 (s , ifp , LOCAL_ADD );
288297 }
298+ }
289299
290- FOR_ALL_NEIGHBOURS (neigh ) {
291- local_notify_neighbour_1 (s , neigh , LOCAL_ADD );
292- }
300+ static void
301+ local_notify_all_xroute_1 (struct local_socket * s )
302+ {
303+ struct xroute_stream * xroutes ;
293304
294305 xroutes = xroute_stream ();
295306 if (xroutes ) {
@@ -301,6 +312,12 @@ local_notify_all_1(struct local_socket *s)
301312 }
302313 xroute_stream_done (xroutes );
303314 }
315+ }
316+
317+ static void
318+ local_notify_all_route_1 (struct local_socket * s )
319+ {
320+ struct route_stream * routes ;
304321
305322 routes = route_stream (ROUTE_ALL );
306323 if (routes ) {
@@ -312,9 +329,60 @@ local_notify_all_1(struct local_socket *s)
312329 }
313330 route_stream_done (routes );
314331 }
315- return ;
316332}
317333
334+ static void
335+ local_notify_all (struct local_socket * s , unsigned int mask )
336+ {
337+ if (mask & (0x01 << SHOW_INTERFACE ))
338+ local_notify_all_interface_1 (s );
339+ if (mask & (0x01 << SHOW_NEIGHBOUR ))
340+ local_notify_all_neighbour_1 (s );
341+ if (mask & (0x01 << SHOW_ROUTE ))
342+ local_notify_all_route_1 (s );
343+ if (mask & (0x01 << SHOW_XROUTE ))
344+ local_notify_all_xroute_1 (s );
345+ }
346+
347+ static void
348+ local_notify_all_1 (struct local_socket * s )
349+ {
350+ local_notify_all_interface_1 (s );
351+ local_notify_all_neighbour_1 (s );
352+ local_notify_all_xroute_1 (s );
353+ local_notify_all_route_1 (s );
354+ }
355+
356+ static unsigned int
357+ show_flags_map (int rc )
358+ {
359+ switch (rc ) {
360+ case CONFIG_ACTION_MONITOR_ROUTE :
361+ case CONFIG_ACTION_UNMONITOR_ROUTE :
362+ case CONFIG_ACTION_DUMP_ROUTE :
363+ return 0x01 << SHOW_ROUTE ;
364+ case CONFIG_ACTION_MONITOR_INTERFACE :
365+ case CONFIG_ACTION_UNMONITOR_INTERFACE :
366+ case CONFIG_ACTION_DUMP_INTERFACE :
367+ return 0x01 << SHOW_INTERFACE ;
368+ case CONFIG_ACTION_MONITOR_XROUTE :
369+ case CONFIG_ACTION_UNMONITOR_XROUTE :
370+ case CONFIG_ACTION_DUMP_XROUTE :
371+ return 0x01 << SHOW_XROUTE ;
372+ case CONFIG_ACTION_MONITOR_NEIGHBOUR :
373+ case CONFIG_ACTION_UNMONITOR_NEIGHBOUR :
374+ case CONFIG_ACTION_DUMP_NEIGHBOUR :
375+ return 0x01 << SHOW_NEIGHBOUR ;
376+ case CONFIG_ACTION_MONITOR :
377+ case CONFIG_ACTION_UNMONITOR :
378+ case CONFIG_ACTION_DUMP :
379+ return 0xff ;
380+ }
381+ return 0 ;
382+ }
383+
384+
385+
318386int
319387local_read (struct local_socket * s )
320388{
@@ -352,19 +420,36 @@ local_read(struct local_socket *s)
352420 shutdown (s -> fd , 1 );
353421 reply [0 ] = '\0' ;
354422 break ;
423+ case CONFIG_ACTION_DUMP_INTERFACE :
424+ case CONFIG_ACTION_DUMP_ROUTE :
425+ case CONFIG_ACTION_DUMP_XROUTE :
426+ case CONFIG_ACTION_DUMP_NEIGHBOUR :
355427 case CONFIG_ACTION_DUMP :
356- local_notify_all_1 ( s );
428+ local_notify_all ( s , show_flags_map ( rc ) );
357429 break ;
358430 case CONFIG_ACTION_MONITOR :
431+ s -> monitor = 0xff ;
359432 local_notify_all_1 (s );
360- s -> monitor = 1 ;
433+ break ;
434+ case CONFIG_ACTION_MONITOR_NEIGHBOUR :
435+ case CONFIG_ACTION_MONITOR_INTERFACE :
436+ case CONFIG_ACTION_MONITOR_ROUTE :
437+ case CONFIG_ACTION_MONITOR_XROUTE :
438+ s -> monitor |= show_flags_map (rc );
439+ local_notify_all (s , show_flags_map (rc ));
440+ break ;
441+ case CONFIG_ACTION_UNMONITOR_NEIGHBOUR :
442+ case CONFIG_ACTION_UNMONITOR_INTERFACE :
443+ case CONFIG_ACTION_UNMONITOR_ROUTE :
444+ case CONFIG_ACTION_UNMONITOR_XROUTE :
445+ s -> monitor &= ~show_flags_map (rc );
361446 break ;
362447 case CONFIG_ACTION_UNMONITOR :
363- s -> monitor = 0 ;
448+ s -> monitor = 0x00 ;
364449 break ;
365450 case CONFIG_ACTION_NO :
366451 snprintf (reply , sizeof (reply ), "no%s%s\n" ,
367- message ? " " : "" , message ? message : "" );
452+ message ? " " : "" , message ? message : "" );
368453 break ;
369454 default :
370455 snprintf (reply , sizeof (reply ), "bad\n" );
0 commit comments