For a diff I'm working on I need to have a peer id that is never used.
Because of this I changed the way we allocate peer ids a little bit by
introducing a few defines and using them instead.

OK?
-- 
:wq Claudio

Index: bgpd.h
===================================================================
RCS file: /cvs/src/usr.sbin/bgpd/bgpd.h,v
retrieving revision 1.387
diff -u -p -r1.387 bgpd.h
--- bgpd.h      17 Jun 2019 21:17:04 -0000      1.387
+++ bgpd.h      21 Jun 2019 07:52:34 -0000
@@ -397,6 +397,12 @@ struct peer_config {
        u_int8_t                 flags;
 };
 
+#define        PEER_ID_NONE            0
+#define        PEER_ID_SELF            1
+#define        PEER_ID_STATIC_MIN      2       /* exclude self */
+#define        PEER_ID_STATIC_MAX      (UINT_MAX / 2)
+#define        PEER_ID_DYN_MAX         UINT_MAX
+
 #define PEERFLAG_TRANS_AS      0x01
 #define PEERFLAG_LOG_UPDATES   0x02
 
Index: parse.y
===================================================================
RCS file: /cvs/src/usr.sbin/bgpd/parse.y,v
retrieving revision 1.391
diff -u -p -r1.391 parse.y
--- parse.y     17 Jun 2019 13:35:42 -0000      1.391
+++ parse.y     21 Jun 2019 07:49:58 -0000
@@ -3952,7 +3952,7 @@ find_prefixset(char *name, struct prefix
 int
 get_id(struct peer *newpeer)
 {
-       static u_int32_t id = 1;
+       static u_int32_t id = PEER_ID_STATIC_MIN;
        struct peer     *p = NULL;
 
        /* check if the peer already existed before */
@@ -3982,7 +3982,7 @@ get_id(struct peer *newpeer)
        }
 
        /* else new one */
-       if (id < UINT_MAX / 2) {
+       if (id < PEER_ID_STATIC_MAX) {
                newpeer->conf.id = id++;
                return (0);
        }
Index: rde.c
===================================================================
RCS file: /cvs/src/usr.sbin/bgpd/rde.c,v
retrieving revision 1.471
diff -u -p -r1.471 rde.c
--- rde.c       20 Jun 2019 13:18:19 -0000      1.471
+++ rde.c       21 Jun 2019 07:46:38 -0000
@@ -3322,7 +3322,7 @@ peer_init(u_int32_t hashsize)
        bzero(&pc, sizeof(pc));
        snprintf(pc.descr, sizeof(pc.descr), "LOCAL");
 
-       peerself = peer_add(0, &pc);
+       peerself = peer_add(PEER_ID_SELF, &pc);
        if (peerself == NULL)
                fatalx("peer_init add self");
 
Index: session.c
===================================================================
RCS file: /cvs/src/usr.sbin/bgpd/session.c,v
retrieving revision 1.385
diff -u -p -r1.385 session.c
--- session.c   17 Jun 2019 21:17:04 -0000      1.385
+++ session.c   21 Jun 2019 07:52:53 -0000
@@ -2947,7 +2947,7 @@ getpeerbyip(struct bgpd_config *c, struc
                if ((newpeer = malloc(sizeof(struct peer))) == NULL)
                        fatal(NULL);
                memcpy(newpeer, loose, sizeof(struct peer));
-               for (id = UINT_MAX; id > UINT_MAX / 2; id--) {
+               for (id = PEER_ID_DYN_MAX; id > PEER_ID_STATIC_MAX; id--) {
                        RB_FOREACH(p, peer_head, &conf->peers)
                                if (p->conf.id == id)
                                        break;

Reply via email to