Use struct kroute_full instead of a union of struct kroute & kroute6.
authorclaudio <claudio@openbsd.org>
Wed, 22 Jun 2022 14:48:51 +0000 (14:48 +0000)
committerclaudio <claudio@openbsd.org>
Wed, 22 Jun 2022 14:48:51 +0000 (14:48 +0000)
struct kroute_full is address family independent and so more portable.
Also struct kroute and struct kroute6 will be kroute.c internal soon.
OK tb@

usr.sbin/bgpd/bgpd.h
usr.sbin/bgpd/kroute.c

index cc190a3..ac1545b 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: bgpd.h,v 1.432 2022/06/19 10:30:09 claudio Exp $ */
+/*     $OpenBSD: bgpd.h,v 1.433 2022/06/22 14:48:51 claudio Exp $ */
 
 /*
  * Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@@ -769,10 +769,7 @@ struct ctl_show_interface {
 struct ctl_show_nexthop {
        struct bgpd_addr                addr;
        struct ctl_show_interface       iface;
-       union {
-               struct kroute           kr4;
-               struct kroute6          kr6;
-       } kr;
+       struct kroute_full              kr;
        uint8_t                         valid;
        uint8_t                         krvalid;
 };
index 25476db..70534b4 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: kroute.c,v 1.261 2022/06/22 12:28:33 claudio Exp $ */
+/*     $OpenBSD: kroute.c,v 1.262 2022/06/22 14:48:51 claudio Exp $ */
 
 /*
  * Copyright (c) 2022 Claudio Jeker <claudio@openbsd.org>
@@ -1149,16 +1149,14 @@ kr_show_route(struct imsg *imsg)
                                        kr = h->kroute;
                                        snh.valid = kroute_validate(&kr->r);
                                        snh.krvalid = 1;
-                                       memcpy(&snh.kr.kr4, &kr->r,
-                                           sizeof(snh.kr.kr4));
+                                       snh.kr = *kr_tofull(&kr->r);
                                        ifindex = kr->r.ifindex;
                                        break;
                                case AID_INET6:
                                        kr6 = h->kroute;
                                        snh.valid = kroute6_validate(&kr6->r);
                                        snh.krvalid = 1;
-                                       memcpy(&snh.kr.kr6, &kr6->r,
-                                           sizeof(snh.kr.kr6));
+                                       snh.kr = *kr6_tofull(&kr6->r);
                                        ifindex = kr6->r.ifindex;
                                        break;
                                }