ifconfig: merge switch_status() into bridge_status()

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

ifconfig: merge switch_status() into bridge_status()

Klemens Nanni-2
This is to reduce duplicate code and pave the way for a single
bridge_status() that covers all bridge like interfaces: bridge(4),
switch(4) and tpmr(4).

Feedback? OK?

Index: brconfig.c
===================================================================
RCS file: /cvs/src/sbin/ifconfig/brconfig.c,v
retrieving revision 1.26
diff -u -p -r1.26 brconfig.c
--- brconfig.c 29 Jul 2020 12:13:28 -0000 1.26
+++ brconfig.c 29 Jul 2020 12:17:04 -0000
@@ -54,6 +54,7 @@ void bridge_ifclrflag(const char *, u_in
 
 void bridge_list(char *);
 void bridge_cfg(const char *);
+void switch_cfg(const char *);
 void bridge_badrule(int, char **, int);
 void bridge_showrule(struct ifbrlreq *);
 int is_switch(void);
@@ -778,10 +779,16 @@ void
 bridge_status(void)
 {
  struct ifbrparam bp1, bp2;
+ int isswitch = is_switch();
 
- if (!is_bridge() || is_switch())
+ if (!is_bridge())
  return;
 
+ if (isswitch)
+ switch_cfg("\t");
+ else
+ bridge_cfg("\t");
+
  bridge_cfg("\t");
 
  bridge_list("\t");
@@ -789,6 +796,9 @@ bridge_status(void)
  if (aflag && !ifaliases)
  return;
 
+ if (isswitch)
+ return;
+
  strlcpy(bp1.ifbrp_name, ifname, sizeof(bp1.ifbrp_name));
  if (ioctl(sock, SIOCBRDGGCACHE, (caddr_t)&bp1) == -1)
  return;
@@ -1146,8 +1156,8 @@ is_switch()
  return (1);
 }
 
-static void
-switch_cfg(char *delim)
+void
+switch_cfg(const char *delim)
 {
  struct ifbrparam bp;
 
@@ -1168,20 +1178,6 @@ switch_cfg(char *delim)
  err(1, "%s", ifname);
 
  printf(" maxgroup %d\n", bp.ifbrp_maxgroup);
-}
-
-void
-switch_status(void)
-{
- if (!is_switch())
- return;
-
- switch_cfg("\t");
-
- bridge_list("\t");
-
- if (aflag && !ifaliases)
- return;
 }
 
 void
Index: ifconfig.c
===================================================================
RCS file: /cvs/src/sbin/ifconfig/ifconfig.c,v
retrieving revision 1.424
diff -u -p -r1.424 ifconfig.c
--- ifconfig.c 3 Jul 2020 17:42:50 -0000 1.424
+++ ifconfig.c 29 Jul 2020 12:17:06 -0000
@@ -3507,7 +3507,6 @@ status(int link, struct sockaddr_dl *sdl
  phys_status(0);
 #ifndef SMALL
  bridge_status();
- switch_status();
 #endif
 }
 
Index: ifconfig.h
===================================================================
RCS file: /cvs/src/sbin/ifconfig/ifconfig.h,v
retrieving revision 1.2
diff -u -p -r1.2 ifconfig.h
--- ifconfig.h 24 Oct 2019 18:54:10 -0000 1.2
+++ ifconfig.h 29 Jul 2020 12:17:06 -0000
@@ -69,7 +69,6 @@ void bridge_flushrule(const char *, int)
 int is_bridge(void);
 void bridge_status(void);
 int bridge_rule(int, char **, int);
-void switch_status(void);
 void switch_datapathid(const char *, int);
 void switch_portno(const char *, const char *);
 

Reply | Threaded
Open this post in threaded view
|

Re: ifconfig: merge switch_status() into bridge_status()

Klemens Nanni-2
On Wed, Jul 29, 2020 at 02:21:42PM +0200, Klemens Nanni wrote:
> This is to reduce duplicate code and pave the way for a single
> bridge_status() that covers all bridge like interfaces: bridge(4),
> switch(4) and tpmr(4).
A duplicate bridge_cfg() call snuck in, fixed diff below.

Feedback? OK?

> + if (isswitch)
> + switch_cfg("\t");
> + else
> + bridge_cfg("\t");
> +
>   bridge_cfg("\t");
>  
>   bridge_list("\t");


Index: brconfig.c
===================================================================
RCS file: /cvs/src/sbin/ifconfig/brconfig.c,v
retrieving revision 1.26
diff -u -p -r1.26 brconfig.c
--- brconfig.c 29 Jul 2020 12:13:28 -0000 1.26
+++ brconfig.c 31 Jul 2020 06:32:54 -0000
@@ -54,6 +54,7 @@ void bridge_ifclrflag(const char *, u_in
 
 void bridge_list(char *);
 void bridge_cfg(const char *);
+void switch_cfg(const char *);
 void bridge_badrule(int, char **, int);
 void bridge_showrule(struct ifbrlreq *);
 int is_switch(void);
@@ -778,17 +779,24 @@ void
 bridge_status(void)
 {
  struct ifbrparam bp1, bp2;
+ int isswitch = is_switch();
 
- if (!is_bridge() || is_switch())
+ if (!is_bridge())
  return;
 
- bridge_cfg("\t");
+ if (isswitch)
+ switch_cfg("\t");
+ else
+ bridge_cfg("\t");
 
  bridge_list("\t");
 
  if (aflag && !ifaliases)
  return;
 
+ if (isswitch)
+ return;
+
  strlcpy(bp1.ifbrp_name, ifname, sizeof(bp1.ifbrp_name));
  if (ioctl(sock, SIOCBRDGGCACHE, (caddr_t)&bp1) == -1)
  return;
@@ -1146,8 +1154,8 @@ is_switch()
  return (1);
 }
 
-static void
-switch_cfg(char *delim)
+void
+switch_cfg(const char *delim)
 {
  struct ifbrparam bp;
 
@@ -1168,20 +1176,6 @@ switch_cfg(char *delim)
  err(1, "%s", ifname);
 
  printf(" maxgroup %d\n", bp.ifbrp_maxgroup);
-}
-
-void
-switch_status(void)
-{
- if (!is_switch())
- return;
-
- switch_cfg("\t");
-
- bridge_list("\t");
-
- if (aflag && !ifaliases)
- return;
 }
 
 void
Index: ifconfig.c
===================================================================
RCS file: /cvs/src/sbin/ifconfig/ifconfig.c,v
retrieving revision 1.424
diff -u -p -r1.424 ifconfig.c
--- ifconfig.c 3 Jul 2020 17:42:50 -0000 1.424
+++ ifconfig.c 31 Jul 2020 06:24:17 -0000
@@ -3507,7 +3507,6 @@ status(int link, struct sockaddr_dl *sdl
  phys_status(0);
 #ifndef SMALL
  bridge_status();
- switch_status();
 #endif
 }
 
Index: ifconfig.h
===================================================================
RCS file: /cvs/src/sbin/ifconfig/ifconfig.h,v
retrieving revision 1.2
diff -u -p -r1.2 ifconfig.h
--- ifconfig.h 24 Oct 2019 18:54:10 -0000 1.2
+++ ifconfig.h 31 Jul 2020 06:24:18 -0000
@@ -69,7 +69,6 @@ void bridge_flushrule(const char *, int)
 int is_bridge(void);
 void bridge_status(void);
 int bridge_rule(int, char **, int);
-void switch_status(void);
 void switch_datapathid(const char *, int);
 void switch_portno(const char *, const char *);
 

Reply | Threaded
Open this post in threaded view
|

Re: ifconfig: merge switch_status() into bridge_status()

David Gwynne-5


> On 31 Jul 2020, at 16:36, Klemens Nanni <[hidden email]> wrote:
>
> On Wed, Jul 29, 2020 at 02:21:42PM +0200, Klemens Nanni wrote:
>> This is to reduce duplicate code and pave the way for a single
>> bridge_status() that covers all bridge like interfaces: bridge(4),
>> switch(4) and tpmr(4).
> A duplicate bridge_cfg() call snuck in, fixed diff below.
>
> Feedback? OK?

ok.

>
>> + if (isswitch)
>> + switch_cfg("\t");
>> + else
>> + bridge_cfg("\t");
>> +
>> bridge_cfg("\t");
>>
>> bridge_list("\t");
>
>
> Index: brconfig.c
> ===================================================================
> RCS file: /cvs/src/sbin/ifconfig/brconfig.c,v
> retrieving revision 1.26
> diff -u -p -r1.26 brconfig.c
> --- brconfig.c 29 Jul 2020 12:13:28 -0000 1.26
> +++ brconfig.c 31 Jul 2020 06:32:54 -0000
> @@ -54,6 +54,7 @@ void bridge_ifclrflag(const char *, u_in
>
> void bridge_list(char *);
> void bridge_cfg(const char *);
> +void switch_cfg(const char *);
> void bridge_badrule(int, char **, int);
> void bridge_showrule(struct ifbrlreq *);
> int is_switch(void);
> @@ -778,17 +779,24 @@ void
> bridge_status(void)
> {
> struct ifbrparam bp1, bp2;
> + int isswitch = is_switch();
>
> - if (!is_bridge() || is_switch())
> + if (!is_bridge())
> return;
>
> - bridge_cfg("\t");
> + if (isswitch)
> + switch_cfg("\t");
> + else
> + bridge_cfg("\t");
>
> bridge_list("\t");
>
> if (aflag && !ifaliases)
> return;
>
> + if (isswitch)
> + return;
> +
> strlcpy(bp1.ifbrp_name, ifname, sizeof(bp1.ifbrp_name));
> if (ioctl(sock, SIOCBRDGGCACHE, (caddr_t)&bp1) == -1)
> return;
> @@ -1146,8 +1154,8 @@ is_switch()
> return (1);
> }
>
> -static void
> -switch_cfg(char *delim)
> +void
> +switch_cfg(const char *delim)
> {
> struct ifbrparam bp;
>
> @@ -1168,20 +1176,6 @@ switch_cfg(char *delim)
> err(1, "%s", ifname);
>
> printf(" maxgroup %d\n", bp.ifbrp_maxgroup);
> -}
> -
> -void
> -switch_status(void)
> -{
> - if (!is_switch())
> - return;
> -
> - switch_cfg("\t");
> -
> - bridge_list("\t");
> -
> - if (aflag && !ifaliases)
> - return;
> }
>
> void
> Index: ifconfig.c
> ===================================================================
> RCS file: /cvs/src/sbin/ifconfig/ifconfig.c,v
> retrieving revision 1.424
> diff -u -p -r1.424 ifconfig.c
> --- ifconfig.c 3 Jul 2020 17:42:50 -0000 1.424
> +++ ifconfig.c 31 Jul 2020 06:24:17 -0000
> @@ -3507,7 +3507,6 @@ status(int link, struct sockaddr_dl *sdl
> phys_status(0);
> #ifndef SMALL
> bridge_status();
> - switch_status();
> #endif
> }
>
> Index: ifconfig.h
> ===================================================================
> RCS file: /cvs/src/sbin/ifconfig/ifconfig.h,v
> retrieving revision 1.2
> diff -u -p -r1.2 ifconfig.h
> --- ifconfig.h 24 Oct 2019 18:54:10 -0000 1.2
> +++ ifconfig.h 31 Jul 2020 06:24:18 -0000
> @@ -69,7 +69,6 @@ void bridge_flushrule(const char *, int)
> int is_bridge(void);
> void bridge_status(void);
> int bridge_rule(int, char **, int);
> -void switch_status(void);
> void switch_datapathid(const char *, int);
> void switch_portno(const char *, const char *);
>