On Fri, Jun 22, 2018 at 12:25:40AM +0200, Jeremie Courreges-Anglas wrote:
> On Tue, Jun 19 2018, Remi Locherer <remi.loche...@relo.ch> wrote:
> > On Tue, Jun 19, 2018 at 03:59:24PM +0100, Stuart Henderson wrote:
> >> On 2018/06/18 08:53, Remi Locherer wrote:
> >> > Index: ospfd.h
> >> > ===================================================================
> >> > RCS file: /cvs/src/usr.sbin/ospfd/ospfd.h,v
> >> > retrieving revision 1.100
> >> > diff -u -p -r1.100 ospfd.h
> >> > --- ospfd.h      11 Feb 2018 02:27:33 -0000      1.100
> >> > +++ ospfd.h      12 Jun 2018 20:41:43 -0000
> >> ...
> >> > -struct ifaddrdel {
> >> > +struct ifaddr {
> >> >          struct in_addr          addr;
> >> > +        struct in_addr          mask;
> >> > +        struct in_addr          dst;
> >> >          unsigned int            ifindex;
> >> >  };
> >> 
> >> I think it would be better to use a different name.
> >> 
> >> Even if there's no actual conflict as if_var.h isn't pulled in, this is
> >> renaming this struct to "struct ifaddr" is at least confusing.
> >
> > Oh yes, that is unfortunate.
> >
> > What would be a better name for this struct? 
> > iface_addr maybe? Or if_addrmask?
> 
> ospf6d uses struct ifaddrchange.

Updated diff with  "struct ifaddrchage" instead of "struct ifaddr".

OK?


Index: kroute.c
===================================================================
RCS file: /cvs/src/usr.sbin/ospfd/kroute.c,v
retrieving revision 1.109
diff -u -p -r1.109 kroute.c
--- kroute.c    11 Feb 2018 02:27:33 -0000      1.109
+++ kroute.c    25 Jun 2018 06:23:41 -0000
@@ -1072,8 +1072,9 @@ void
 if_newaddr(u_short ifindex, struct sockaddr_in *ifa, struct sockaddr_in *mask,
     struct sockaddr_in *brd)
 {
-       struct kif_node *kif;
-       struct kif_addr *ka;
+       struct kif_node         *kif;
+       struct kif_addr         *ka;
+       struct ifaddrchange      ifn;
 
        if (ifa == NULL || ifa->sin_family != AF_INET)
                return;
@@ -1094,15 +1095,21 @@ if_newaddr(u_short ifindex, struct socka
                ka->dstbrd.s_addr = INADDR_NONE;
 
        TAILQ_INSERT_TAIL(&kif->addrs, ka, entry);
+
+       ifn.addr = ka->addr;
+       ifn.mask = ka->mask;
+       ifn.dst = ka->dstbrd;
+       ifn.ifindex = ifindex;
+       main_imsg_compose_ospfe(IMSG_IFADDRADD, 0, &ifn, sizeof(ifn));
 }
 
 void
 if_deladdr(u_short ifindex, struct sockaddr_in *ifa, struct sockaddr_in *mask,
     struct sockaddr_in *brd)
 {
-       struct kif_node *kif;
-       struct kif_addr *ka, *nka;
-       struct ifaddrdel ifc;
+       struct kif_node         *kif;
+       struct kif_addr         *ka, *nka;
+       struct ifaddrchange      ifc;
 
        if (ifa == NULL || ifa->sin_family != AF_INET)
                return;
Index: ospfd.h
===================================================================
RCS file: /cvs/src/usr.sbin/ospfd/ospfd.h,v
retrieving revision 1.100
diff -u -p -r1.100 ospfd.h
--- ospfd.h     11 Feb 2018 02:27:33 -0000      1.100
+++ ospfd.h     25 Jun 2018 06:19:23 -0000
@@ -132,6 +132,7 @@ enum imsg_type {
        IMSG_RECONF_REDIST,
        IMSG_RECONF_END,
        IMSG_DEMOTE,
+       IMSG_IFADDRADD,
        IMSG_IFADDRDEL
 };
 
@@ -363,8 +364,10 @@ struct iface {
        u_int8_t                 passive;
 };
 
-struct ifaddrdel {
+struct ifaddrchange {
        struct in_addr          addr;
+       struct in_addr          mask;
+       struct in_addr          dst;
        unsigned int            ifindex;
 };
 
Index: ospfe.c
===================================================================
RCS file: /cvs/src/usr.sbin/ospfd/ospfe.c,v
retrieving revision 1.100
diff -u -p -r1.100 ospfe.c
--- ospfe.c     5 Feb 2018 12:11:28 -0000       1.100
+++ ospfe.c     25 Jun 2018 06:24:24 -0000
@@ -275,7 +275,7 @@ ospfe_dispatch_main(int fd, short event,
 {
        static struct area      *narea;
        static struct iface     *niface;
-       struct ifaddrdel        *ifc;
+       struct ifaddrchange     *ifc;
        struct imsg      imsg;
        struct imsgev   *iev = bula;
        struct imsgbuf  *ibuf = &iev->ibuf;
@@ -361,9 +361,38 @@ ospfe_dispatch_main(int fd, short event,
                                }
                        }
                        break;
+               case IMSG_IFADDRADD:
+                       if (imsg.hdr.len != IMSG_HEADER_SIZE +
+                           sizeof(struct ifaddrchange))
+                               fatalx("IFADDRADD imsg with wrong len");
+                       ifc = imsg.data;
+
+                       LIST_FOREACH(area, &oeconf->area_list, entry) {
+                               LIST_FOREACH(iface, &area->iface_list, entry) {
+                                       if (ifc->ifindex == iface->ifindex &&
+                                           ifc->addr.s_addr ==
+                                           iface->addr.s_addr) {
+                                               iface->mask = ifc->mask;
+                                               iface->dst = ifc->dst;
+                                               /*
+                                                * Previous down event might
+                                                * have failed if the address
+                                                * was not present at that
+                                                * time.
+                                                */
+                                               if_fsm(iface, IF_EVT_DOWN);
+                                               if_fsm(iface, IF_EVT_UP);
+                                               log_warnx("interface %s:%s "
+                                                   "returned", iface->name,
+                                                   inet_ntoa(iface->addr));
+                                               break;
+                                       }
+                               }
+                       }
+                       break;
                case IMSG_IFADDRDEL:
                        if (imsg.hdr.len != IMSG_HEADER_SIZE +
-                           sizeof(struct ifaddrdel))
+                           sizeof(struct ifaddrchange))
                                fatalx("IFADDRDEL imsg with wrong len");
                        ifc = imsg.data;
 

Reply via email to