Fix some bugs in the handling of the RTM_GET and RTM_CHANGE messages
authorrenato <renato@openbsd.org>
Thu, 22 Oct 2015 23:17:45 +0000 (23:17 +0000)
committerrenato <renato@openbsd.org>
Thu, 22 Oct 2015 23:17:45 +0000 (23:17 +0000)
found when running eigrpd(8) and ldpd(8) together.

usr.sbin/eigrpd/kroute.c

index 869745f..88cb912 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: kroute.c,v 1.3 2015/10/21 03:52:12 renato Exp $ */
+/*     $OpenBSD: kroute.c,v 1.4 2015/10/22 23:17:45 renato Exp $ */
 
 /*
  * Copyright (c) 2015 Renato Westphal <renato@openbsd.org>
@@ -1537,8 +1537,8 @@ rtmsg_process_route(struct rt_msghdr *rtm, struct sockaddr *rti_info[RTAX_MAX])
                        kprio = kroute_find_prio(kp, kr.priority);
                        if (kprio) {
                                kn = TAILQ_FIRST(&kprio->nexthops);
-                               if (kn && (kn->r.flags & F_KERNEL))
-                                       kroute_remove(&kr);
+                               if (kn)
+                                       kroute_remove(&kn->r);
                        }
                }
        }
@@ -1563,14 +1563,6 @@ rtmsg_process_route(struct rt_msghdr *rtm, struct sockaddr *rti_info[RTAX_MAX])
                return (-1);
        }
 
-       if (kr.priority == eigrpd_conf->fib_priority_internal ||
-           kr.priority == eigrpd_conf->fib_priority_external ||
-           kr.priority == eigrpd_conf->fib_priority_summary) {
-               log_warnx("alien EIGRP route %s/%d", log_addr(kr.af, &kr.prefix),
-                   kr.prefixlen);
-               return (send_rtmsg(kr_state.fd, RTM_DELETE, &kr));
-       }
-
        if (kn != NULL) {
                /* update route */
                memcpy(&kn->r, &kr, sizeof(kn->r));
@@ -1581,8 +1573,18 @@ rtmsg_process_route(struct rt_msghdr *rtm, struct sockaddr *rti_info[RTAX_MAX])
                        kn->r.flags |= F_DOWN;
 
                kr_redistribute(kp);
-       } else
+       } else {
+               if ((rtm->rtm_type == RTM_ADD || rtm->rtm_type == RTM_GET) &&
+                   (kr.priority == eigrpd_conf->fib_priority_internal ||
+                   kr.priority == eigrpd_conf->fib_priority_external ||
+                   kr.priority == eigrpd_conf->fib_priority_summary)) {
+                       log_warnx("alien EIGRP route %s/%d", log_addr(kr.af,
+                           &kr.prefix), kr.prefixlen);
+                       return (send_rtmsg(kr_state.fd, RTM_DELETE, &kr));
+               }
+
                kroute_insert(&kr);
+       }
 
        return (0);
 }