Le Mon, Jan 04, 2021 at 05:04:51PM +0100, Claudio Jeker a écrit :
> bgpd will get a new process for RTR handling. Because of this it makes
> sense to cleanup the startup code a bit and not use flags to indicate
> which process to run but instead use the enum bgpd_process.
> Additionally change the PFD_PIPE_ROUTE to PFD_PIPE_RDE. The latter is less
> confusing since there is also PFD_SOCK_ROUTE.
> 
> OK?

Better readability, OK denis@

> -- 
> :wq Claudio
> 
> Index: bgpd.c
> ===================================================================
> RCS file: /cvs/src/usr.sbin/bgpd/bgpd.c,v
> retrieving revision 1.232
> diff -u -p -r1.232 bgpd.c
> --- bgpd.c    30 Dec 2020 07:00:54 -0000      1.232
> +++ bgpd.c    4 Jan 2021 16:00:30 -0000
> @@ -90,7 +90,7 @@ usage(void)
>  }
>  
>  #define PFD_PIPE_SESSION     0
> -#define PFD_PIPE_ROUTE               1
> +#define PFD_PIPE_RDE         1
>  #define PFD_SOCK_ROUTE               2
>  #define PFD_SOCK_PFKEY               3
>  #define POLL_MAX             4
> @@ -102,6 +102,7 @@ int
>  main(int argc, char *argv[])
>  {
>       struct bgpd_config      *conf;
> +     enum bgpd_process        proc = PROC_MAIN;
>       struct rde_rib          *rr;
>       struct peer             *p;
>       struct pollfd            pfd[POLL_MAX];
> @@ -110,7 +111,6 @@ main(int argc, char *argv[])
>       char                    *conffile;
>       char                    *saved_argv0;
>       int                      debug = 0;
> -     int                      rflag = 0, sflag = 0;
>       int                      rfd, keyfd;
>       int                      ch, status;
>       int                      pipe_m2s[2];
> @@ -151,10 +151,10 @@ main(int argc, char *argv[])
>                       cmd_opts |= BGPD_OPT_VERBOSE;
>                       break;
>               case 'R':
> -                     rflag = 1;
> +                     proc = PROC_RDE;
>                       break;
>               case 'S':
> -                     sflag = 1;
> +                     proc = PROC_SE;
>                       break;
>               default:
>                       usage();
> @@ -164,7 +164,7 @@ main(int argc, char *argv[])
>  
>       argc -= optind;
>       argv += optind;
> -     if (argc > 0 || (sflag && rflag))
> +     if (argc > 0)
>               usage();
>  
>       if (cmd_opts & BGPD_OPT_NOACTION) {
> @@ -184,10 +184,16 @@ main(int argc, char *argv[])
>               exit(0);
>       }
>  
> -     if (rflag)
> +     switch (proc) {
> +     case PROC_MAIN:
> +             break;
> +     case PROC_RDE:
>               rde_main(debug, cmd_opts & BGPD_OPT_VERBOSE);
> -     else if (sflag)
> +             /* NOTREACHED */
> +     case PROC_SE:
>               session_main(debug, cmd_opts & BGPD_OPT_VERBOSE);
> +             /* NOTREACHED */
> +     }
>  
>       if (geteuid())
>               errx(1, "need root privileges");
> @@ -278,7 +284,7 @@ BROKEN    if (pledge("stdio rpath wpath cpa
>               pfd[PFD_SOCK_PFKEY].events = POLLIN;
>  
>               set_pollfd(&pfd[PFD_PIPE_SESSION], ibuf_se);
> -             set_pollfd(&pfd[PFD_PIPE_ROUTE], ibuf_rde);
> +             set_pollfd(&pfd[PFD_PIPE_RDE], ibuf_rde);
>  
>               if (timeout < 0 || timeout > MAX_TIMEOUT)
>                       timeout = MAX_TIMEOUT;
> @@ -300,14 +306,14 @@ BROKEN  if (pledge("stdio rpath wpath cpa
>                               quit = 1;
>               }
>  
> -             if (handle_pollfd(&pfd[PFD_PIPE_ROUTE], ibuf_rde) == -1) {
> +             if (handle_pollfd(&pfd[PFD_PIPE_RDE], ibuf_rde) == -1) {
>                       log_warnx("main: Lost connection to RDE");
>                       msgbuf_clear(&ibuf_rde->w);
>                       free(ibuf_rde);
>                       ibuf_rde = NULL;
>                       quit = 1;
>               } else {
> -                     if (dispatch_imsg(ibuf_rde, PFD_PIPE_ROUTE, conf) ==
> +                     if (dispatch_imsg(ibuf_rde, PFD_PIPE_RDE, conf) ==
>                           -1)
>                               quit = 1;
>               }
> @@ -713,7 +719,7 @@ dispatch_imsg(struct imsgbuf *ibuf, int 
>  
>               switch (imsg.hdr.type) {
>               case IMSG_KROUTE_CHANGE:
> -                     if (idx != PFD_PIPE_ROUTE)
> +                     if (idx != PFD_PIPE_RDE)
>                               log_warnx("route request not from RDE");
>                       else if (imsg.hdr.len != IMSG_HEADER_SIZE +
>                           sizeof(struct kroute_full))
> @@ -723,7 +729,7 @@ dispatch_imsg(struct imsgbuf *ibuf, int 
>                               rv = -1;
>                       break;
>               case IMSG_KROUTE_DELETE:
> -                     if (idx != PFD_PIPE_ROUTE)
> +                     if (idx != PFD_PIPE_RDE)
>                               log_warnx("route request not from RDE");
>                       else if (imsg.hdr.len != IMSG_HEADER_SIZE +
>                           sizeof(struct kroute_full))
> @@ -733,7 +739,7 @@ dispatch_imsg(struct imsgbuf *ibuf, int 
>                               rv = -1;
>                       break;
>               case IMSG_KROUTE_FLUSH:
> -                     if (idx != PFD_PIPE_ROUTE)
> +                     if (idx != PFD_PIPE_RDE)
>                               log_warnx("route request not from RDE");
>                       else if (imsg.hdr.len != IMSG_HEADER_SIZE)
>                               log_warnx("wrong imsg len");
> @@ -741,7 +747,7 @@ dispatch_imsg(struct imsgbuf *ibuf, int 
>                               rv = -1;
>                       break;
>               case IMSG_NEXTHOP_ADD:
> -                     if (idx != PFD_PIPE_ROUTE)
> +                     if (idx != PFD_PIPE_RDE)
>                               log_warnx("nexthop request not from RDE");
>                       else if (imsg.hdr.len != IMSG_HEADER_SIZE +
>                           sizeof(struct bgpd_addr))
> @@ -751,7 +757,7 @@ dispatch_imsg(struct imsgbuf *ibuf, int 
>                               rv = -1;
>                       break;
>               case IMSG_NEXTHOP_REMOVE:
> -                     if (idx != PFD_PIPE_ROUTE)
> +                     if (idx != PFD_PIPE_RDE)
>                               log_warnx("nexthop request not from RDE");
>                       else if (imsg.hdr.len != IMSG_HEADER_SIZE +
>                           sizeof(struct bgpd_addr))
> @@ -761,7 +767,7 @@ dispatch_imsg(struct imsgbuf *ibuf, int 
>                                   conf);
>                       break;
>               case IMSG_PFTABLE_ADD:
> -                     if (idx != PFD_PIPE_ROUTE)
> +                     if (idx != PFD_PIPE_RDE)
>                               log_warnx("pftable request not from RDE");
>                       else
>                               if (imsg.hdr.len != IMSG_HEADER_SIZE +
> @@ -771,7 +777,7 @@ dispatch_imsg(struct imsgbuf *ibuf, int 
>                                       rv = -1;
>                       break;
>               case IMSG_PFTABLE_REMOVE:
> -                     if (idx != PFD_PIPE_ROUTE)
> +                     if (idx != PFD_PIPE_RDE)
>                               log_warnx("pftable request not from RDE");
>                       else
>                               if (imsg.hdr.len != IMSG_HEADER_SIZE +
> @@ -781,7 +787,7 @@ dispatch_imsg(struct imsgbuf *ibuf, int 
>                                       rv = -1;
>                       break;
>               case IMSG_PFTABLE_COMMIT:
> -                     if (idx != PFD_PIPE_ROUTE)
> +                     if (idx != PFD_PIPE_RDE)
>                               log_warnx("pftable request not from RDE");
>                       else if (imsg.hdr.len != IMSG_HEADER_SIZE)
>                               log_warnx("wrong imsg len");
> 

Reply via email to