Re: [External] : Re: XCP-ng, OpenBSD and network interface changes

2021-02-01 Thread Denis Fondras
Le Mon, Feb 01, 2021 at 01:49:09PM +0100, Alexandr Nedvedicky a écrit :
> Hello Denis,
> 
> I think we need to refresh expected value in 'flags'
> with every loop iteration.  does diff below help?
> 

Thank you but it does not help. Same panic and also same panic if I test with
loop++ > 10.

If loop++ > 100, no more panic but I get :

xnf0 detached
xen0: failed to attach "device/vif/"


> regards
> sashan
> 
> 8<---8<---8<--8<
> diff --git a/sys/dev/pv/xen.c b/sys/dev/pv/xen.c
> index 11ce4ca99cd..c93e68614b4 100644
> --- a/sys/dev/pv/xen.c
> +++ b/sys/dev/pv/xen.c
> @@ -1202,20 +1202,22 @@ xen_grant_table_remove(struct xen_softc *sc, 
> grant_ref_t ref)
>   flags = (ge->ge_table[ref].flags & ~(GTF_reading|GTF_writing)) |
>   (ge->ge_table[ref].domid << 16);
>   loop = 0;
>   while (atomic_cas_uint(ptr, flags, GTF_invalid) != flags) {
>   if (loop++ > 10) {
>   panic("grant table reference %u is held "
>   "by domain %d: frame %#x flags %#x",
>   ref + ge->ge_start, ge->ge_table[ref].domid,
>   ge->ge_table[ref].frame, ge->ge_table[ref].flags);
>   }
> + flags = (ge->ge_table[ref].flags & ~(GTF_reading|GTF_writing)) |
> + (ge->ge_table[ref].domid << 16);
>  #if (defined(__amd64__) || defined(__i386__))
>   __asm volatile("pause": : : "memory");
>  #endif
>   }
>   ge->ge_table[ref].frame = 0x;
>  }
>  
>  int
>  xen_bus_dmamap_create(bus_dma_tag_t t, bus_size_t size, int nsegments,
>  bus_size_t maxsegsz, bus_size_t boundary, int flags, bus_dmamap_t *dmamp)



XCP-ng, OpenBSD and network interface changes

2021-01-31 Thread Denis Fondras
I am using XCP-ng with the latest OpenBSD snapshot.

Whenever I make an hardware change in networking on the VM (connect or
disconnect an interface, change associated network), the VM panics :

openbsd# panic: grant table reference 5912 is held by domain 0: frame 0x1f1a4 
flags 0x19
Stopped at   db_enter+0x10: popq %rbp
TID   PID  UIDPRFLAGS   PFLAGS CPU COMMAND
*349758 6557900x14000   0x200   0 xenwatch
db_enter() at db_enter+0x10
panic(81da7541) at panic+0x12a
xen_bus_dmamap_unload(820ede50,800e9380) at 
xen_bus_dmamap_unload+0x138
xnf_tx_ring_destroy(80162000) at xnf_tx_ring_destroy+0x104
xnf_detach(80162000,0) at xnf_detach+0x55
config_detach(80162000,0) at config_detach+0x140
xen_hotplug(8012e200) at xen_hotplug+0x181
taskq_thread(800dde00) at taskq_thread+0x66
end trace frame: 0x0, count: 7
https://www.openbsd.org/ddb.html describes the minimum info required in bug 
reports. Insufficient info makes it difficult to find and fix bugs.
ddb>

If I apply the following patch, it obviously does not panic and seems to work
correctly :

Index: xen.c
===
RCS file: /cvs/src/sys/dev/pv/xen.c,v
retrieving revision 1.97
diff -u -p -r1.97 xen.c
--- xen.c   29 Jun 2020 06:50:52 -  1.97
+++ xen.c   31 Jan 2021 13:13:07 -
@@ -1204,7 +1204,7 @@ xen_grant_table_remove(struct xen_softc 
loop = 0;
while (atomic_cas_uint(ptr, flags, GTF_invalid) != flags) {
if (loop++ > 10) {
-   panic("grant table reference %u is held "
+   printf("grant table reference %u is held "
"by domain %d: frame %#x flags %#x",
ref + ge->ge_start, ge->ge_table[ref].domid,
ge->ge_table[ref].frame, ge->ge_table[ref].flags);

Can someone give me a clue on what _atomic_cas_uint() is ?

Thank you in advance.

Denis

OpenBSD 6.8-current (GENERIC) #9: Sun Jan 31 14:08:42 CET 2021
r...@openbsd.lab.ledeuns.net:/sys/arch/amd64/compile/GENERIC
real mem = 1052770304 (1004MB)
avail mem = 1005694976 (959MB)
random: good seed from bootblocks
mpath0 at root
scsibus0 at mpath0: 256 targets
mainbus0 at root
bios0 at mainbus0: SMBIOS rev. 2.4 @ 0xeb01f (11 entries)
bios0: vendor Xen version "4.13" date 01/21/2021
bios0: Xen HVM domU
acpi0 at bios0: ACPI 4.0
acpi0: sleep states S5
acpi0: tables DSDT FACP APIC HPET WAET
acpi0: wakeup devices
acpitimer0 at acpi0: 3579545 Hz, 32 bits
acpimadt0 at acpi0 addr 0xfee0: PC-AT compat
ioapic0 at mainbus0: apid 1 pa 0xfec0, version 11, 48 pins, remapped
cpu0 at mainbus0: apid 0 (boot processor)
cpu0: Intel(R) Xeon(R) CPU E5-2407 v2 @ 2.40GHz, 2394.83 MHz, 06-3e-04
cpu0: 
FPU,VME,DE,PSE,TSC,MSR,PAE,MCE,CX8,APIC,SEP,MTRR,PGE,MCA,CMOV,PAT,PSE36,CFLUSH,ACPI,MMX,FXSR,SSE,SSE2,SS,SSE3,PCLMUL,SSSE3,CX16,PCID,SSE4.1,SSE4.2,x2APIC,POPCNT,DEADLINE,AES,XSAVE,AVX,F16C,RDRAND,HV,NXE,PAGE1GB,RDTSCP,LONG,LAHF,FSGSBASE,SMEP,ERMS,MD_CLEAR,IBRS,IBPB,STIBP,L1DF,SSBD,XSAVEOPT,MELTDOWN
cpu0: 256KB 64b/line 8-way L2 cache
cpu0: smt 0, core 0, package 0
mtrr: Pentium Pro MTRR support, 8 var ranges, 88 fixed ranges
cpu0: apic clock running at 100MHz
acpihpet0 at acpi0: 6250 Hz
acpiprt0 at acpi0: bus 0 (PCI0)
acpipci0 at acpi0 PCI0
acpicmos0 at acpi0
"ACPI0007" at acpi0 not configured
acpicpu0 at acpi0: C1(@1 halt!)
cpu0: using VERW MDS workaround (except on vmm entry)
pvbus0 at mainbus0: Hyper-V 0.0, Xen 4.13
xen0 at pvbus0: features 0x2705, 64 grant table frames, event channel 2
xbf0 at xen0 backend 0 channel 6: disk
scsibus1 at xbf0: 1 targets
sd0 at scsibus1 targ 0 lun 0: 
sd0: 10240MB, 512 bytes/sector, 20971520 sectors
xbf1 at xen0 backend 0 channel 7: cdrom
xbf1: timed out waiting for backend to connect
xnf0 at xen0 backend 0 channel 7: address 76:88:23:28:25:f4
xnf1 at xen0 backend 0 channel 8: address 62:36:ed:68:46:3c
xnf2 at xen0 backend 0 channel 9: address be:04:e2:f3:7d:75
pci0 at mainbus0 bus 0
pchb0 at pci0 dev 0 function 0 "Intel 82441FX" rev 0x02
pcib0 at pci0 dev 1 function 0 "Intel 82371SB ISA" rev 0x00
pciide0 at pci0 dev 1 function 1 "Intel 82371SB IDE" rev 0x00: DMA, channel 0 
wired to compatibility, channel 1 wired to compatibility
pciide0: channel 0 disabled (no drives)
atapiscsi0 at pciide0 channel 1 drive 1
scsibus2 at atapiscsi0: 2 targets
cd0 at scsibus2 targ 0 lun 0:  removable
cd0(pciide0:1:1): using PIO mode 4, DMA mode 2
uhci0 at pci0 dev 1 function 2 "Intel 82371SB USB" rev 0x01: apic 1 int 23
piixpm0 at pci0 dev 1 function 3 "Intel 82371AB Power" rev 0x01: SMBus disabled
vga1 at pci0 dev 2 function 0 "Cirrus Logic CL-GD5446" rev 0x00
wsdisplay0 at vga1 mux 1: console (80x25, vt100 emulation)
wsdisplay0: screen 1-5 added (80x25, vt100 emulation)
xspd0 at pci0 dev 3 function 0 "XenSource Platform Device" rev 0x01
isa0 at pcib0
isadma0 at isa0
fdc0 at isa0 port 0x3f0/6 irq 6 drq 2
com0 at 

Re: route sourceaddr: simplify code & get out of ART

2021-01-23 Thread Denis Fondras
Le Sat, Jan 09, 2021 at 06:50:50PM +0100, Denis Fondras a écrit :
> This diff place the user-set source address outside of struct art_root and 
> make
> the code more readable (to me).
> 
> Based on a concept by mpi@
> 

ping.

> Index: net/art.h
> ===
> RCS file: /cvs/src/sys/net/art.h,v
> retrieving revision 1.20
> diff -u -p -r1.20 art.h
> --- net/art.h 12 Nov 2020 15:25:28 -  1.20
> +++ net/art.h 9 Jan 2021 16:04:02 -
> @@ -42,7 +42,6 @@ struct art_root {
>   uint8_t  ar_nlvl;   /* [I] Number of levels */
>   uint8_t  ar_alen;   /* [I] Address length in bits */
>   uint8_t  ar_off;/* [I] Offset of key in bytes */
> - struct sockaddr *source;/* [K] optional src addr to use 
> */
>  };
>  
>  #define ISLEAF(e)(((unsigned long)(e) & 1) == 0)
> Index: net/route.c
> ===
> RCS file: /cvs/src/sys/net/route.c,v
> retrieving revision 1.397
> diff -u -p -r1.397 route.c
> --- net/route.c   29 Oct 2020 21:15:27 -  1.397
> +++ net/route.c   9 Jan 2021 16:04:02 -
> @@ -1192,9 +1192,9 @@ rt_ifa_del(struct ifaddr *ifa, int flags
>   if (flags & RTF_CONNECTED)
>   prio = ifp->if_priority + RTP_CONNECTED;
>  
> - rtable_clearsource(rdomain, ifa->ifa_addr);
>   error = rtrequest_delete(, prio, ifp, , rdomain);
>   if (error == 0) {
> + rt_sourceclear(rt, rdomain);
>   rtm_send(rt, RTM_DELETE, 0, rdomain);
>   if (flags & RTF_LOCAL)
>   rtm_addr(RTM_DELADDR, ifa);
> Index: net/route.h
> ===
> RCS file: /cvs/src/sys/net/route.h,v
> retrieving revision 1.183
> diff -u -p -r1.183 route.h
> --- net/route.h   29 Oct 2020 21:15:27 -  1.183
> +++ net/route.h   9 Jan 2021 16:04:02 -
> @@ -478,6 +478,9 @@ intrtrequest_delete(struct rt_addrinfo
>  int   rt_if_track(struct ifnet *);
>  int   rt_if_linkstate_change(struct rtentry *, void *, u_int);
>  int   rtdeletemsg(struct rtentry *, struct ifnet *, u_int);
> +
> +struct ifaddr*rt_get_ifa(struct rtentry *, unsigned int);
> +void  rt_sourceclear(struct rtentry *, unsigned int);
>  #endif /* _KERNEL */
>  
>  #endif /* _NET_ROUTE_H_ */
> Index: net/rtable.c
> ===
> RCS file: /cvs/src/sys/net/rtable.c,v
> retrieving revision 1.72
> diff -u -p -r1.72 rtable.c
> --- net/rtable.c  7 Nov 2020 09:51:40 -   1.72
> +++ net/rtable.c  9 Jan 2021 16:04:02 -
> @@ -365,44 +365,6 @@ rtable_alloc(unsigned int rtableid, unsi
>   return (art_alloc(rtableid, alen, off));
>  }
>  
> -int
> -rtable_setsource(unsigned int rtableid, int af, struct sockaddr *src)
> -{
> - struct art_root *ar;
> -
> - if ((ar = rtable_get(rtableid, af)) == NULL)
> - return (EAFNOSUPPORT);
> -
> - ar->source = src;
> -
> - return (0);
> -}
> -
> -struct sockaddr *
> -rtable_getsource(unsigned int rtableid, int af)
> -{
> - struct art_root *ar;
> -
> - ar = rtable_get(rtableid, af);
> - if (ar == NULL)
> - return (NULL);
> -
> - return (ar->source);
> -}
> -
> -void
> -rtable_clearsource(unsigned int rtableid, struct sockaddr *src)
> -{
> - struct sockaddr *addr;
> -
> - addr = rtable_getsource(rtableid, src->sa_family);
> - if (addr && (addr->sa_len == src->sa_len)) {
> - if (memcmp(src, addr, addr->sa_len) == 0) {
> - rtable_setsource(rtableid, src->sa_family, NULL);
> - }
> - }
> -}
> -
>  struct rtentry *
>  rtable_lookup(unsigned int rtableid, struct sockaddr *dst,
>  struct sockaddr *mask, struct sockaddr *gateway, uint8_t prio)
> Index: net/rtable.h
> ===
> RCS file: /cvs/src/sys/net/rtable.h,v
> retrieving revision 1.26
> diff -u -p -r1.26 rtable.h
> --- net/rtable.h  7 Nov 2020 09:51:40 -   1.26
> +++ net/rtable.h  9 Jan 2021 16:04:02 -
> @@ -39,9 +39,6 @@ unsigned int rtable_l2(unsigned int);
>  unsigned int  rtable_loindex(unsigned int);
>  void  rtable_l2set(unsigned int, unsigned int, unsigned int);
>  
> -int   rtable_setsource(unsigned int, int, struct sockaddr *);
> -struct sockaddr *rtable_getsource(unsigned int, int);
> -void

Re: bgpd adjust aspath_neighbor to follow RFC more closely

2021-01-14 Thread Denis Fondras
Le Thu, Jan 14, 2021 at 02:20:26PM +0100, Claudio Jeker a écrit :
> The aspath_neighbor function returns the first AS of a path. Now if the
> first element is an AS_SET then this does not really make sense.
> RFC4271 has this bit in section 9.1.2.2
> 
>  Similarly, neighborAS(n) is a function that returns the
>  neighbor AS from which the route was received.  If the route is
>  learned via IBGP, and the other IBGP speaker didn't originate
>  the route, it is the neighbor AS from which the other IBGP
>  speaker learned the route.  If the route is learned via IBGP,
>  and the other IBGP speaker either (a) originated the route, or
>  (b) created the route by aggregation and the AS_PATH attribute
>  of the aggregate route is either empty or begins with an
>  AS_SET, it is the local AS.
> 
> bgpd uses aspath_neighbor() in a few spots:
> - in the decision process to decide if MED should be compared or not
> - in filters using 'peer-as'
> - in the enforce neighbor-as check
> 
> I think the above mentioned behaviour is valid for all these cases and so
> here is a diff that adjust aspath_neighbor().
> 

OK denis@

> -- 
> :wq Claudio
> 
> Index: rde_attr.c
> ===
> RCS file: /cvs/src/usr.sbin/bgpd/rde_attr.c,v
> retrieving revision 1.123
> diff -u -p -r1.123 rde_attr.c
> --- rde_attr.c24 Jun 2019 06:39:49 -  1.123
> +++ rde_attr.c14 Jan 2021 13:13:15 -
> @@ -673,8 +673,13 @@ aspath_length(struct aspath *aspath)
>  u_int32_t
>  aspath_neighbor(struct aspath *aspath)
>  {
> - /* Empty aspath is OK -- internal AS route. */
> - if (aspath->len == 0)
> + /*
> +  * Empty aspath is OK -- internal AS route.
> +  * Additionally the RFC specifies that if the path starts with an
> +  * AS_SET the neighbor AS is also the local AS.
> +  */
> + if (aspath->len == 0 ||
> + aspath->data[0] != AS_SEQUENCE)
>   return (rde_local_as());
>   return (aspath_extract(aspath->data, 0));
>  }
> 



Re: Change bgpd_addr encoding of VPN v4 and v6 addresses

2021-01-14 Thread Denis Fondras
Le Tue, Jan 12, 2021 at 10:06:46AM +0100, Claudio Jeker a écrit :
> On Tue, Jan 05, 2021 at 11:17:22AM +0100, Claudio Jeker wrote:
> > While changing log_addr() I noticed that struct bgpd_addr could benefit
> > from changing the encoding of AID_VPN_IPv4 and AID_VPN_IPv6 addrs.
> > Instead of having independent route distinguishers and labelstacks use
> > common fields for those and use the v4 and v6 addresses for the prefix.
> > This is a bit more compact but also simplifies some code since the
> > handling of AID_VPN_IPv4 and AID_VPN_IPv6 can be handled in the same
> > switch case.
> > 
> > I reduced the labelstack size from 21 to 18 (6 instead of 7 labels). Now
> > in theory you could pack 7 labels into an IPv4 VPN NLRI (8bit prefixlen +
> > 64bit RD + 16bit prefix + 21 * 8bit label = 256) but that is quite silly.
> > Even 6 labels is more than enough. bgpd itself only allows a single MPLS
> > label when announcing such networks.
> 
> Ping
>  
> Index: bgpd/util.c
> ===
> RCS file: /cvs/src/usr.sbin/bgpd/util.c,v
> retrieving revision 1.58
> diff -u -p -r1.58 util.c
> --- bgpd/util.c   5 Jan 2021 10:00:28 -   1.58
> +++ bgpd/util.c   5 Jan 2021 10:05:15 -
> @@ -666,9 +669,17 @@ prefix_compare(const struct bgpd_addr *a
>   mask = htonl(prefixlen2mask(prefixlen));
>   aa = ntohl(a->v4.s_addr & mask);
>   ba = ntohl(b->v4.s_addr & mask);
> - if (aa != ba)
> - return (aa - ba);
> - return (0);
> + if (aa > ba)
> + return (1);
> + if (aa < ba)
> + return (1);

I guess it is -1 here.

Otherwise OK denis@



Re: bgpd refactor route decision process

2021-01-13 Thread Denis Fondras
Le Tue, Jan 12, 2021 at 05:39:02PM +0100, Claudio Jeker a écrit :
> This diff changes two things:
> - First, it move the kroute update into rde_generate_updates() simplifying
> prefix_evaluate a little bit.
> 
> - Second, it changes prefix_evaluate to take an additional argument for the
> old prefix (to be removed). Instead of doing this outside of
> prefix_evaluate() with some drawbacks in case the same prefix is removed
> and readded, the code is now in prefix_evaluate() and does all the magic
> itself.
> 
> Index: rde_decide.c
> ===
> RCS file: /cvs/src/usr.sbin/bgpd/rde_decide.c,v
> retrieving revision 1.78
> diff -u -p -r1.78 rde_decide.c
> --- rde_decide.c  9 Aug 2019 13:44:27 -   1.78
> +++ rde_decide.c  12 Jan 2021 16:24:36 -
> @@ -238,14 +238,16 @@ prefix_cmp(struct prefix *p1, struct pre
>   * The to evaluate prefix must not be in the prefix list.
>   */
>  void
> -prefix_evaluate(struct prefix *p, struct rib_entry *re)
> +prefix_evaluate(struct rib_entry *re, struct prefix *new, struct prefix *old)
>  {
>   struct prefix   *xp;
>  
>   if (re_rib(re)->flags & F_RIB_NOEVALUATE) {
>   /* decision process is turned off */
> - if (p != NULL)
> - LIST_INSERT_HEAD(>prefix_h, p, entry.list.rib);
> + if (old != NULL)
> + LIST_REMOVE(old, entry.list.rib);
> + if (new != NULL)
> + LIST_INSERT_HEAD(>prefix_h, new, entry.list.rib);

Would it be beneficial to have a p == new test ?

Otherwise OK denis@



route sourceaddr: simplify code & get out of ART

2021-01-09 Thread Denis Fondras
This diff place the user-set source address outside of struct art_root and make
the code more readable (to me).

Based on a concept by mpi@

Index: net/art.h
===
RCS file: /cvs/src/sys/net/art.h,v
retrieving revision 1.20
diff -u -p -r1.20 art.h
--- net/art.h   12 Nov 2020 15:25:28 -  1.20
+++ net/art.h   9 Jan 2021 16:04:02 -
@@ -42,7 +42,6 @@ struct art_root {
uint8_t  ar_nlvl;   /* [I] Number of levels */
uint8_t  ar_alen;   /* [I] Address length in bits */
uint8_t  ar_off;/* [I] Offset of key in bytes */
-   struct sockaddr *source;/* [K] optional src addr to use 
*/
 };
 
 #define ISLEAF(e)  (((unsigned long)(e) & 1) == 0)
Index: net/route.c
===
RCS file: /cvs/src/sys/net/route.c,v
retrieving revision 1.397
diff -u -p -r1.397 route.c
--- net/route.c 29 Oct 2020 21:15:27 -  1.397
+++ net/route.c 9 Jan 2021 16:04:02 -
@@ -1192,9 +1192,9 @@ rt_ifa_del(struct ifaddr *ifa, int flags
if (flags & RTF_CONNECTED)
prio = ifp->if_priority + RTP_CONNECTED;
 
-   rtable_clearsource(rdomain, ifa->ifa_addr);
error = rtrequest_delete(, prio, ifp, , rdomain);
if (error == 0) {
+   rt_sourceclear(rt, rdomain);
rtm_send(rt, RTM_DELETE, 0, rdomain);
if (flags & RTF_LOCAL)
rtm_addr(RTM_DELADDR, ifa);
Index: net/route.h
===
RCS file: /cvs/src/sys/net/route.h,v
retrieving revision 1.183
diff -u -p -r1.183 route.h
--- net/route.h 29 Oct 2020 21:15:27 -  1.183
+++ net/route.h 9 Jan 2021 16:04:02 -
@@ -478,6 +478,9 @@ int  rtrequest_delete(struct rt_addrinfo
 int rt_if_track(struct ifnet *);
 int rt_if_linkstate_change(struct rtentry *, void *, u_int);
 int rtdeletemsg(struct rtentry *, struct ifnet *, u_int);
+
+struct ifaddr  *rt_get_ifa(struct rtentry *, unsigned int);
+voidrt_sourceclear(struct rtentry *, unsigned int);
 #endif /* _KERNEL */
 
 #endif /* _NET_ROUTE_H_ */
Index: net/rtable.c
===
RCS file: /cvs/src/sys/net/rtable.c,v
retrieving revision 1.72
diff -u -p -r1.72 rtable.c
--- net/rtable.c7 Nov 2020 09:51:40 -   1.72
+++ net/rtable.c9 Jan 2021 16:04:02 -
@@ -365,44 +365,6 @@ rtable_alloc(unsigned int rtableid, unsi
return (art_alloc(rtableid, alen, off));
 }
 
-int
-rtable_setsource(unsigned int rtableid, int af, struct sockaddr *src)
-{
-   struct art_root *ar;
-
-   if ((ar = rtable_get(rtableid, af)) == NULL)
-   return (EAFNOSUPPORT);
-
-   ar->source = src;
-
-   return (0);
-}
-
-struct sockaddr *
-rtable_getsource(unsigned int rtableid, int af)
-{
-   struct art_root *ar;
-
-   ar = rtable_get(rtableid, af);
-   if (ar == NULL)
-   return (NULL);
-
-   return (ar->source);
-}
-
-void
-rtable_clearsource(unsigned int rtableid, struct sockaddr *src)
-{
-   struct sockaddr *addr;
-
-   addr = rtable_getsource(rtableid, src->sa_family);
-   if (addr && (addr->sa_len == src->sa_len)) {
-   if (memcmp(src, addr, addr->sa_len) == 0) {
-   rtable_setsource(rtableid, src->sa_family, NULL);
-   }
-   }
-}
-
 struct rtentry *
 rtable_lookup(unsigned int rtableid, struct sockaddr *dst,
 struct sockaddr *mask, struct sockaddr *gateway, uint8_t prio)
Index: net/rtable.h
===
RCS file: /cvs/src/sys/net/rtable.h,v
retrieving revision 1.26
diff -u -p -r1.26 rtable.h
--- net/rtable.h7 Nov 2020 09:51:40 -   1.26
+++ net/rtable.h9 Jan 2021 16:04:02 -
@@ -39,9 +39,6 @@ unsigned int   rtable_l2(unsigned int);
 unsigned intrtable_loindex(unsigned int);
 voidrtable_l2set(unsigned int, unsigned int, unsigned int);
 
-int rtable_setsource(unsigned int, int, struct sockaddr *);
-struct sockaddr *rtable_getsource(unsigned int, int);
-voidrtable_clearsource(unsigned int, struct sockaddr *);
 struct rtentry *rtable_lookup(unsigned int, struct sockaddr *,
 struct sockaddr *, struct sockaddr *, uint8_t);
 struct rtentry *rtable_match(unsigned int, struct sockaddr *, uint32_t *);
Index: net/rtsock.c
===
RCS file: /cvs/src/sys/net/rtsock.c,v
retrieving revision 1.304
diff -u -p -r1.304 rtsock.c
--- net/rtsock.c7 Nov 2020 09:51:40 -   1.304
+++ net/rtsock.c9 Jan 2021 16:04:02 -
@@ -138,7 +138,8 @@ int  sysctl_iflist(int, struct walkarg 
 int sysctl_ifnames(struct walkarg *);
 int 

Re: Port httpd(8) 'strip' directive to relayd(8)

2021-01-07 Thread Denis Fondras
Le Thu, Jan 07, 2021 at 12:03:54PM +0100, Hiltjo Posthuma a écrit :
> Hi Denis,
> 
> I like this feature. For example it would be useful for using relayd as a
> reverse-proxy to forward it to an internal network running a httpd with some
> service. Then the path can be stripped without having to touch this service
> configuration.
> 
> Like: https://example.com/myservice/ -> http://192.168.0.2/ .
> 
> I've noticed a small thing while testing the patch. When the path is "/" and
> "strip 1" is used it becomes "", the request becomes: "GET HTTP/1.0". Maybe
> this should be instead: "/". The same thing happens with a "strip number"
> higher than the amount of sub paths.
> 
> It could be worked-around by prefiltering with a match rule, but maybe it is
> more obvious to make the root "/" ? The way the function server_root_strip() 
> is
> used by OpenBSD httpd is that it first does a filesystem path check/open(2).
> 
> 

Thank you for testing.

Here is an update:

Index: parse.y
===
RCS file: /cvs/src/usr.sbin/relayd/parse.y,v
retrieving revision 1.250
diff -u -p -r1.250 parse.y
--- parse.y 29 Dec 2020 19:48:06 -  1.250
+++ parse.y 7 Jan 2021 15:08:28 -
@@ -175,7 +175,7 @@ typedef struct {
 %token LOOKUP METHOD MODE NAT NO DESTINATION NODELAY NOTHING ON PARENT PATH
 %token PFTAG PORT PREFORK PRIORITY PROTO QUERYSTR REAL REDIRECT RELAY REMOVE
 %token REQUEST RESPONSE RETRY QUICK RETURN ROUNDROBIN ROUTE SACK SCRIPT SEND
-%token SESSION SOCKET SPLICE SSL STICKYADDR STYLE TABLE TAG TAGGED TCP
+%token SESSION SOCKET SPLICE SSL STICKYADDR STRIP STYLE TABLE TAG TAGGED TCP
 %token TIMEOUT TLS TO ROUTER RTLABEL TRANSPARENT URL WITH TTL RTABLE
 %token MATCH PARAMS RANDOM LEASTSTATES SRCHASH KEY CERTIFICATE PASSWORD ECDHE
 %token EDH TICKETS CONNECTION CONNECTIONS CONTEXT ERRORS STATE CHANGES CHECKS
@@ -1549,6 +1549,20 @@ ruleopts : METHOD STRING 
{
rule->rule_kv[keytype].kv_option = $2;
rule->rule_kv[keytype].kv_type = keytype;
}
+   | PATH STRIP NUMBER {
+   char*strip = NULL;
+
+   if ($3 < 0 || $3 > INT_MAX) {
+   yyerror("invalid strip number");
+   YYERROR;
+   }
+   if (asprintf(, "%lld", $3) <= 0)
+   fatal("can't parse strip");
+   keytype = KEY_TYPE_PATH;
+   rule->rule_kv[keytype].kv_option = KEY_OPTION_STRIP;
+   rule->rule_kv[keytype].kv_value = strip;
+   rule->rule_kv[keytype].kv_type = keytype;
+   }
| QUERYSTR key_option STRING value  {
switch ($2) {
case KEY_OPTION_APPEND:
@@ -2481,6 +2495,7 @@ lookup(char *s)
{ "ssl",SSL },
{ "state",  STATE },
{ "sticky-address", STICKYADDR },
+   { "strip",  STRIP },
{ "style",  STYLE },
{ "table",  TABLE },
{ "tag",TAG },
Index: relay.c
===
RCS file: /cvs/src/usr.sbin/relayd/relay.c,v
retrieving revision 1.251
diff -u -p -r1.251 relay.c
--- relay.c 14 May 2020 17:27:38 -  1.251
+++ relay.c 7 Jan 2021 15:08:28 -
@@ -214,6 +214,9 @@ relay_ruledebug(struct relay_rule *rule)
case KEY_OPTION_LOG:
fprintf(stderr, "log ");
break;
+   case KEY_OPTION_STRIP:
+   fprintf(stderr, "strip ");
+   break;
case KEY_OPTION_NONE:
break;
}
@@ -227,13 +230,15 @@ relay_ruledebug(struct relay_rule *rule)
break;
}
 
+   int kvv = (kv->kv_option == KEY_OPTION_STRIP ||
+kv->kv_value == NULL);
fprintf(stderr, "%s%s%s%s%s%s ",
kv->kv_key == NULL ? "" : "\"",
kv->kv_key == NULL ? "" : kv->kv_key,
kv->kv_key == NULL ? "" : "\"",
-   kv->kv_value == NULL ? "" : " value \"",
+   kvv ? "" : " value \"",
kv->kv_value == NULL ? "" : kv->kv_value,
-   kv->kv_value == NULL ? "" : "\"");
+   kvv ? "" : "\"");
}
 
if (rule->rule_tablename[0])
Index: relay_http.c
===
RCS file: /cvs/src/usr.sbin/relayd/relay_http.c,v
retrieving revision 1.79
diff -u -p -r1.79 relay_http.c
--- relay_http.c4 Sep 2020 13:09:14 

Re: minor cleanup in bgpd's process startup

2021-01-04 Thread Denis Fondras
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.c30 Dec 2020 07:00:54 -  1.232
> +++ bgpd.c4 Jan 2021 16:00:30 -
> @@ -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_processproc = PROC_MAIN;
>   struct rde_rib  *rr;
>   struct peer *p;
>   struct pollfdpfd[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 @@ BROKENif (pledge("stdio rpath wpath cpa
>   pfd[PFD_SOCK_PFKEY].events = POLLIN;
>  
>   set_pollfd([PFD_PIPE_SESSION], ibuf_se);
> - set_pollfd([PFD_PIPE_ROUTE], ibuf_rde);
> + set_pollfd([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_PIPE_ROUTE], ibuf_rde) == -1) {
> + if (handle_pollfd([PFD_PIPE_RDE], ibuf_rde) == -1) {
>   log_warnx("main: Lost connection to RDE");
>   msgbuf_clear(_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 

Re: Port httpd(8) 'strip' directive to relayd(8)

2021-01-03 Thread Denis Fondras
Le Fri, Dec 11, 2020 at 10:53:56AM +, Olivier Cherrier a écrit :
> 
>   Hello tech@,
> 
> Is there any interest for this feature to be commited?
> I find it very useful. Thank you Denis!
> 

Here is an up to date diff, looking for OKs.

Index: parse.y
===
RCS file: /cvs/src/usr.sbin/relayd/parse.y,v
retrieving revision 1.250
diff -u -p -r1.250 parse.y
--- parse.y 29 Dec 2020 19:48:06 -  1.250
+++ parse.y 3 Jan 2021 10:38:26 -
@@ -175,7 +175,7 @@ typedef struct {
 %token LOOKUP METHOD MODE NAT NO DESTINATION NODELAY NOTHING ON PARENT PATH
 %token PFTAG PORT PREFORK PRIORITY PROTO QUERYSTR REAL REDIRECT RELAY REMOVE
 %token REQUEST RESPONSE RETRY QUICK RETURN ROUNDROBIN ROUTE SACK SCRIPT SEND
-%token SESSION SOCKET SPLICE SSL STICKYADDR STYLE TABLE TAG TAGGED TCP
+%token SESSION SOCKET SPLICE SSL STICKYADDR STRIP STYLE TABLE TAG TAGGED TCP
 %token TIMEOUT TLS TO ROUTER RTLABEL TRANSPARENT URL WITH TTL RTABLE
 %token MATCH PARAMS RANDOM LEASTSTATES SRCHASH KEY CERTIFICATE PASSWORD ECDHE
 %token EDH TICKETS CONNECTION CONNECTIONS CONTEXT ERRORS STATE CHANGES CHECKS
@@ -1549,6 +1549,20 @@ ruleopts : METHOD STRING 
{
rule->rule_kv[keytype].kv_option = $2;
rule->rule_kv[keytype].kv_type = keytype;
}
+   | PATH STRIP NUMBER {
+   char*strip = NULL;
+
+   if ($3 < 0 || $3 > INT_MAX) {
+   yyerror("invalid strip number");
+   YYERROR;
+   }
+   if (asprintf(, "%lld", $3) <= 0)
+   fatal("can't parse strip");
+   keytype = KEY_TYPE_PATH;
+   rule->rule_kv[keytype].kv_option = KEY_OPTION_STRIP;
+   rule->rule_kv[keytype].kv_value = strip;
+   rule->rule_kv[keytype].kv_type = keytype;
+   }
| QUERYSTR key_option STRING value  {
switch ($2) {
case KEY_OPTION_APPEND:
@@ -2481,6 +2495,7 @@ lookup(char *s)
{ "ssl",SSL },
{ "state",  STATE },
{ "sticky-address", STICKYADDR },
+   { "strip",  STRIP },
{ "style",  STYLE },
{ "table",  TABLE },
{ "tag",TAG },
Index: relay.c
===
RCS file: /cvs/src/usr.sbin/relayd/relay.c,v
retrieving revision 1.251
diff -u -p -r1.251 relay.c
--- relay.c 14 May 2020 17:27:38 -  1.251
+++ relay.c 3 Jan 2021 10:38:27 -
@@ -214,6 +214,9 @@ relay_ruledebug(struct relay_rule *rule)
case KEY_OPTION_LOG:
fprintf(stderr, "log ");
break;
+   case KEY_OPTION_STRIP:
+   fprintf(stderr, "strip ");
+   break;
case KEY_OPTION_NONE:
break;
}
@@ -227,13 +230,15 @@ relay_ruledebug(struct relay_rule *rule)
break;
}
 
+   int kvv = (kv->kv_option == KEY_OPTION_STRIP ||
+kv->kv_value == NULL);
fprintf(stderr, "%s%s%s%s%s%s ",
kv->kv_key == NULL ? "" : "\"",
kv->kv_key == NULL ? "" : kv->kv_key,
kv->kv_key == NULL ? "" : "\"",
-   kv->kv_value == NULL ? "" : " value \"",
+   kvv ? "" : " value \"",
kv->kv_value == NULL ? "" : kv->kv_value,
-   kv->kv_value == NULL ? "" : "\"");
+   kvv ? "" : "\"");
}
 
if (rule->rule_tablename[0])
Index: relay_http.c
===
RCS file: /cvs/src/usr.sbin/relayd/relay_http.c,v
retrieving revision 1.79
diff -u -p -r1.79 relay_http.c
--- relay_http.c4 Sep 2020 13:09:14 -   1.79
+++ relay_http.c3 Jan 2021 10:38:27 -
@@ -77,6 +77,7 @@ intrelay_match_actions(struct ctl_rel
struct relay_rule *, struct kvlist *, struct kvlist *,
struct relay_table **);
 voidrelay_httpdesc_free(struct http_descriptor *);
+char *  server_root_strip(char *, int);
 
 static struct relayd   *env = NULL;
 
@@ -1421,14 +1422,16 @@ relay_httppath_test(struct ctl_relay_eve
 
if (cre->dir == RELAY_DIR_RESPONSE || kv->kv_type != KEY_TYPE_PATH)
return (0);
-   else if (kv->kv_key == NULL)
-   return (0);
-   else if (fnmatch(kv->kv_key, desc->http_path, 0) == FNM_NOMATCH)
-   

Re: Rename SIMPLEQ_ to STAILQ_, diff 1/7

2020-12-30 Thread Denis Fondras
Le Tue, Dec 29, 2020 at 12:36:22PM -0700, Todd C. Miller a écrit :
> On Sat, 26 Dec 2020 15:07:36 -0700, "Theo de Raadt" wrote:
> 
> > Well in that case this should still be a multistep process.
> >
> > Add STAILQ
> >
> > Convert things, including everything in ports
> >
> > No diff should change a line of code before it's time
> 
> That looks something like this.  I used the FreeBSD macros which
> incorporate STAILQ_NEXT and STAILQ_FIRST but I can inline things
> if someone has a strong opinion on this.
> 
> If this is OK I will send an update to the man page.
> 

Sometime STAILQ_FIRST is used, sometime it is (head)->stqh_first.

Apart from that, OK denis@

>  - todd
> 
> Index: sys/sys/queue.h
> ===
> RCS file: /cvs/src/sys/sys/queue.h,v
> retrieving revision 1.45
> diff -u -p -u -r1.45 queue.h
> --- sys/sys/queue.h   12 Jul 2018 14:22:54 -  1.45
> +++ sys/sys/queue.h   29 Dec 2020 17:32:31 -
> @@ -533,4 +533,101 @@ struct {
> \
>   }   \
>  } while (0)
>  
> +/*
> + * Singly-linked Tail queue declarations.
> + */
> +#define  STAILQ_HEAD(name, type) 
> \
> +struct name {
> \
> + struct type *stqh_first;/* first element */ \
> + struct type **stqh_last;/* addr of last next element */ \
> +}
> +
> +#define  STAILQ_HEAD_INITIALIZER(head)   
> \
> + { NULL, &(head).stqh_first }
> +
> +#define  STAILQ_ENTRY(type)  
> \
> +struct { \
> + struct type *stqe_next; /* next element */  \
> +}
> +
> +/*
> + * Singly-linked Tail queue access methods.
> + */
> +#define  STAILQ_FIRST(head)  ((head)->stqh_first)
> +#define  STAILQ_END(head)NULL
> +#define  STAILQ_EMPTY(head)  (STAILQ_FIRST(head) == STAILQ_END(head))
> +#define  STAILQ_NEXT(elm, field) ((elm)->field.stqe_next)
> +
> +#define STAILQ_FOREACH(var, head, field) \
> + for ((var) = STAILQ_FIRST(head);\
> + (var) != STAILQ_END(head);  \
> + (var) = STAILQ_NEXT(var, field))
> +
> +#define  STAILQ_FOREACH_SAFE(var, head, field, tvar) 
> \
> + for ((var) = STAILQ_FIRST(head);\
> + (var) && ((tvar) = STAILQ_NEXT(var, field), 1); \
> + (var) = (tvar))
> +
> +/*
> + * Singly-linked Tail queue functions.
> + */
> +#define  STAILQ_INIT(head) do {  
> \
> + (head)->stqh_first = NULL;  \
> + (head)->stqh_last = &(head)->stqh_first;\
> +} while (0)
> +
> +#define  STAILQ_INSERT_HEAD(head, elm, field) do {   
> \
> + if ((STAILQ_NEXT((elm), field) = STAILQ_FIRST((head))) == NULL) \
> + (head)->stqh_last = _NEXT((elm), field); \
> + STAILQ_FIRST((head)) = (elm);   \
> +} while (0)
> +
> +#define  STAILQ_INSERT_TAIL(head, elm, field) do {   
> \
> + STAILQ_NEXT((elm), field) = NULL;   \
> + *(head)->stqh_last = (elm); \
> + (head)->stqh_last = _NEXT((elm), field); \
> +} while (0)
> +
> +#define  STAILQ_INSERT_AFTER(head, listelm, elm, field) do { 
> \
> + if ((STAILQ_NEXT((elm), field) = STAILQ_NEXT((elm), field)) == NULL)\
> + (head)->stqh_last = _NEXT((elm), field); \
> + STAILQ_NEXT((elm), field) = (elm);  \
> +} while (0)
> +
> +#define STAILQ_REMOVE_HEAD(head, field) do {\
> + if ((STAILQ_FIRST((head)) = \
> + STAILQ_NEXT(STAILQ_FIRST((head)), field)) == NULL)  \
> + (head)->stqh_last = _FIRST((head));  \
> +} while (0)
> +
> +#define STAILQ_REMOVE_AFTER(head, elm, field) do {  \
> + if ((STAILQ_NEXT(elm, field) =  \
> + STAILQ_NEXT(STAILQ_NEXT(elm, field), field)) == NULL)   \
> + (head)->stqh_last = _NEXT((elm), field); \
> +} while (0)
> +
> +#define  STAILQ_REMOVE(head, elm, type, field) do {  
> \
> + if ((head)->stqh_first == (elm)) {  \
> + STAILQ_REMOVE_HEAD((head), field);  \
> + } else {\
> + 

Re: Rename SIMPLEQ_ to STAILQ_, diff 1/7

2020-12-26 Thread Denis Fondras
Le Sat, Dec 26, 2020 at 06:55:09PM +0100, Mark Kettenis a écrit :
> > Date: Sat, 26 Dec 2020 18:39:36 +0100
> > From: Denis Fondras 
> > 
> > Le Sat, Dec 26, 2020 at 06:23:41PM +0100, Mark Kettenis a écrit :
> > > > > This diff renames SIMPLEQ_* to STAILQ_* in /usr/src/sys/sys to unify 
> > > > > with FreeBSD and Linux.
> > > > > 
> > > > > I added aliases at the end of queue.h to avoid breaking base too 
> > > > > much. they will
> > > > > be removed as soon as diff 2,3,4,5,6,7 are commited.
> > > > 
> > > > We'll need to run a ports bulk build without the aliases.  (I can
> > > > do that.) There will be some breakage.
> > > 
> > > NetBSD and Solaris both provide SIMPLEQ_* and STAILQ_*.  I'm not sure
> > > removing one in favour of the other is helpful.
> > >
> > 
> > The "problem" is OpenBSD does not provide STAILQ_*. This difference forces
> > OpenBSD porters to patch linux/freebsd-centered programs.
> > NetBSD added STAILQ_* following FreeBSD.
> 
> Right.  But ports written for OpenBSD/NetBSD/Solaris might use
> SIMPLEQ_*.  My point is that removing one in favour of the other is
> going to break stuff.  So maybe we should provide both like NetBSD and
> Solaris do?
> 
> Which raises the question why STAILQ_* is better than SIMPLEQ_*?  And
> at which point I'd argue against the churn of doing
> s/SIMPLEQ_*/STAILQ_*/ in base.

>From the discussion that happened in april
(https://marc.info/?l=openbsd-tech=158765582816198=2) with Todd C. Miller, I
understood we had some kind of consensus to s/SIMPLEQ_*/STAILQ_*/. I might have
gone too far with the numerous diffs and embedding unrelated changes.



Re: Rename SIMPLEQ_ to STAILQ_, diff 1/7

2020-12-26 Thread Denis Fondras
Le Sat, Dec 26, 2020 at 06:23:41PM +0100, Mark Kettenis a écrit :
> > > This diff renames SIMPLEQ_* to STAILQ_* in /usr/src/sys/sys to unify with 
> > > FreeBSD and Linux.
> > > 
> > > I added aliases at the end of queue.h to avoid breaking base too much. 
> > > they will
> > > be removed as soon as diff 2,3,4,5,6,7 are commited.
> > 
> > We'll need to run a ports bulk build without the aliases.  (I can
> > do that.) There will be some breakage.
> 
> NetBSD and Solaris both provide SIMPLEQ_* and STAILQ_*.  I'm not sure
> removing one in favour of the other is helpful.
>

The "problem" is OpenBSD does not provide STAILQ_*. This difference forces
OpenBSD porters to patch linux/freebsd-centered programs.
NetBSD added STAILQ_* following FreeBSD.



Rename SIMPLEQ_ to STAILQ_, diff 6/7 (usr.bin)

2020-12-26 Thread Denis Fondras
Rename SIMPLEQ_* to STAILQ_* in /usr/src/usr.bin

Index: ctfconv/dw.c
===
RCS file: /cvs/src/usr.bin/ctfconv/dw.c,v
retrieving revision 1.4
diff -u -p -r1.4 dw.c
--- ctfconv/dw.c27 Sep 2017 08:59:38 -  1.4
+++ ctfconv/dw.c25 Dec 2020 16:23:20 -
@@ -372,7 +372,7 @@ dw_attr_parse(struct dwbuf *dwbuf, struc
return error;
}
 
-   SIMPLEQ_INSERT_TAIL(davq, dav, dav_next);
+   STAILQ_INSERT_TAIL(davq, dav, dav_next);
return 0;
 }
 
@@ -381,12 +381,12 @@ dw_attr_purge(struct dwaval_queue *davq)
 {
struct dwaval   *dav;
 
-   while ((dav = SIMPLEQ_FIRST(davq)) != NULL) {
-   SIMPLEQ_REMOVE_HEAD(davq, dav_next);
+   while ((dav = STAILQ_FIRST(davq)) != NULL) {
+   STAILQ_REMOVE_HEAD(davq, dav_next);
pfree(_pool, dav);
}
 
-   SIMPLEQ_INIT(davq);
+   STAILQ_INIT(davq);
 }
 
 static int
@@ -412,7 +412,7 @@ dw_die_parse(struct dwbuf *dwbuf, size_t
continue;
}
 
-   SIMPLEQ_FOREACH(dab, dabq, dab_next) {
+   STAILQ_FOREACH(dab, dabq, dab_next) {
if (dab->dab_code == code)
break;
}
@@ -426,9 +426,9 @@ dw_die_parse(struct dwbuf *dwbuf, size_t
die->die_lvl = lvl;
die->die_dab = dab;
die->die_offset = doff;
-   SIMPLEQ_INIT(>die_avals);
+   STAILQ_INIT(>die_avals);
 
-   SIMPLEQ_FOREACH(dat, >dab_attrs, dat_next) {
+   STAILQ_FOREACH(dat, >dab_attrs, dat_next) {
error = dw_attr_parse(dwbuf, dat, psz, >die_avals);
if (error != 0) {
dw_attr_purge(>die_avals);
@@ -439,7 +439,7 @@ dw_die_parse(struct dwbuf *dwbuf, size_t
if (dab->dab_children == DW_CHILDREN_yes)
lvl++;
 
-   SIMPLEQ_INSERT_TAIL(dieq, die, die_next);
+   STAILQ_INSERT_TAIL(dieq, die, die_next);
}
 
return 0;
@@ -450,13 +450,13 @@ dw_die_purge(struct dwdie_queue *dieq)
 {
struct dwdie*die;
 
-   while ((die = SIMPLEQ_FIRST(dieq)) != NULL) {
-   SIMPLEQ_REMOVE_HEAD(dieq, die_next);
+   while ((die = STAILQ_FIRST(dieq)) != NULL) {
+   STAILQ_REMOVE_HEAD(dieq, die_next);
dw_attr_purge(>die_avals);
pfree(_pool, die);
}
 
-   SIMPLEQ_INIT(dieq);
+   STAILQ_INIT(dieq);
 }
 
 int
@@ -484,9 +484,9 @@ dw_ab_parse(struct dwbuf *abseg, struct 
dab->dab_code = code;
dab->dab_tag = tag;
dab->dab_children = children;
-   SIMPLEQ_INIT(>dab_attrs);
+   STAILQ_INIT(>dab_attrs);
 
-   SIMPLEQ_INSERT_TAIL(dabq, dab, dab_next);
+   STAILQ_INSERT_TAIL(dabq, dab, dab_next);
 
for (;;) {
struct dwattr *dat;
@@ -506,7 +506,7 @@ dw_ab_parse(struct dwbuf *abseg, struct 
dat->dat_attr = attr;
dat->dat_form = form;
 
-   SIMPLEQ_INSERT_TAIL(>dab_attrs, dat, dat_next);
+   STAILQ_INSERT_TAIL(>dab_attrs, dat, dat_next);
}
}
 
@@ -518,19 +518,19 @@ dw_dabq_purge(struct dwabbrev_queue *dab
 {
struct dwabbrev *dab;
 
-   while ((dab = SIMPLEQ_FIRST(dabq)) != NULL) {
+   while ((dab = STAILQ_FIRST(dabq)) != NULL) {
struct dwattr *dat;
 
-   SIMPLEQ_REMOVE_HEAD(dabq, dab_next);
-   while ((dat = SIMPLEQ_FIRST(>dab_attrs)) != NULL) {
-   SIMPLEQ_REMOVE_HEAD(>dab_attrs, dat_next);
+   STAILQ_REMOVE_HEAD(dabq, dab_next);
+   while ((dat = STAILQ_FIRST(>dab_attrs)) != NULL) {
+   STAILQ_REMOVE_HEAD(>dab_attrs, dat_next);
pfree(_pool, dat);
}
 
pfree(_pool, dab);
}
 
-   SIMPLEQ_INIT(dabq);
+   STAILQ_INIT(dabq);
 }
 
 int
@@ -599,8 +599,8 @@ dw_cu_parse(struct dwbuf *info, struct d
dcu->dcu_version = version;
dcu->dcu_abbroff = abbroff;
dcu->dcu_psize = psz;
-   SIMPLEQ_INIT(>dcu_abbrevs);
-   SIMPLEQ_INIT(>dcu_dies);
+   STAILQ_INIT(>dcu_abbrevs);
+   STAILQ_INIT(>dcu_dies);
 
error = dw_ab_parse(, >dcu_abbrevs);
if (error != 0) {
Index: ctfconv/dw.h
===
RCS file: /cvs/src/usr.bin/ctfconv/dw.h,v
retrieving revision 1.2
diff -u -p -r1.2 dw.h
--- ctfconv/dw.h11 Aug 2017 14:58:56 -  1.2
+++ ctfconv/dw.h25 Dec 2020 16:23:20 -
@@ -25,13 +25,13 @@ struct dwbuf {
 };
 
 struct dwattr {
-   SIMPLEQ_ENTRY(dwattr)dat_next;
+   

Rename SIMPLEQ_ to STAILQ_, diff 5/7 (usr.sbin)

2020-12-26 Thread Denis Fondras
Rename SIMPLEQ_* to STAILQ_* in /usr/src/usr.sbin

Index: bgpd/bgpd.c
===
RCS file: /cvs/src/usr.sbin/bgpd/bgpd.c,v
retrieving revision 1.230
diff -u -p -r1.230 bgpd.c
--- bgpd/bgpd.c 5 Nov 2020 11:52:59 -   1.230
+++ bgpd/bgpd.c 25 Dec 2020 16:21:29 -
@@ -57,7 +57,7 @@ pid_t  reconfpid;
 int reconfpending;
 struct imsgbuf *ibuf_se;
 struct imsgbuf *ibuf_rde;
-struct rib_namesribnames = SIMPLEQ_HEAD_INITIALIZER(ribnames);
+struct rib_namesribnames = STAILQ_HEAD_INITIALIZER(ribnames);
 char   *cname;
 char   *rcname;
 
@@ -176,8 +176,8 @@ main(int argc, char *argv[])
else
fprintf(stderr, "configuration OK\n");
 
-   while ((rr = SIMPLEQ_FIRST()) != NULL) {
-   SIMPLEQ_REMOVE_HEAD(, entry);
+   while ((rr = STAILQ_FIRST()) != NULL) {
+   STAILQ_REMOVE_HEAD(, entry);
free(rr);
}
free_config(conf);
@@ -380,8 +380,8 @@ BROKEN  if (pledge("stdio rpath wpath cpa
RB_FOREACH(p, peer_head, >peers)
pfkey_remove(p);
 
-   while ((rr = SIMPLEQ_FIRST()) != NULL) {
-   SIMPLEQ_REMOVE_HEAD(, entry);
+   while ((rr = STAILQ_FIRST()) != NULL) {
+   STAILQ_REMOVE_HEAD(, entry);
free(rr);
}
free_config(conf);
@@ -528,8 +528,8 @@ send_config(struct bgpd_config *conf)
ktable_preload();
 
/* RIBs for the RDE */
-   while ((rr = SIMPLEQ_FIRST())) {
-   SIMPLEQ_REMOVE_HEAD(, entry);
+   while ((rr = STAILQ_FIRST())) {
+   STAILQ_REMOVE_HEAD(, entry);
if (ktable_update(rr->rtableid, rr->name, rr->flags,
conf->fib_priority) == -1) {
log_warnx("failed to load rdomain %d",
@@ -557,8 +557,8 @@ send_config(struct bgpd_config *conf)
kr_net_reload(conf->default_tableid, 0, >networks);
 
/* prefixsets for filters in the RDE */
-   while ((ps = SIMPLEQ_FIRST(>prefixsets)) != NULL) {
-   SIMPLEQ_REMOVE_HEAD(>prefixsets, entry);
+   while ((ps = STAILQ_FIRST(>prefixsets)) != NULL) {
+   STAILQ_REMOVE_HEAD(>prefixsets, entry);
if (imsg_compose(ibuf_rde, IMSG_RECONF_PREFIX_SET, 0, 0, -1,
ps->name, sizeof(ps->name)) == -1)
return (-1);
@@ -574,8 +574,8 @@ send_config(struct bgpd_config *conf)
}
 
/* originsets for filters in the RDE */
-   while ((ps = SIMPLEQ_FIRST(>originsets)) != NULL) {
-   SIMPLEQ_REMOVE_HEAD(>originsets, entry);
+   while ((ps = STAILQ_FIRST(>originsets)) != NULL) {
+   STAILQ_REMOVE_HEAD(>originsets, entry);
if (imsg_compose(ibuf_rde, IMSG_RECONF_ORIGIN_SET, 0, 0, -1,
ps->name, sizeof(ps->name)) == -1)
return (-1);
@@ -625,12 +625,12 @@ send_config(struct bgpd_config *conf)
}
 
/* as-sets for filters in the RDE */
-   while ((aset = SIMPLEQ_FIRST(>as_sets)) != NULL) {
+   while ((aset = STAILQ_FIRST(>as_sets)) != NULL) {
struct ibuf *wbuf;
u_int32_t *as;
size_t i, l, n;
 
-   SIMPLEQ_REMOVE_HEAD(>as_sets, entry);
+   STAILQ_REMOVE_HEAD(>as_sets, entry);
 
as = set_get(aset->set, );
if ((wbuf = imsg_create(ibuf_rde, IMSG_RECONF_AS_SET, 0, 0,
@@ -668,8 +668,8 @@ send_config(struct bgpd_config *conf)
free(r);
}
 
-   while ((vpn = SIMPLEQ_FIRST(>l3vpns)) != NULL) {
-   SIMPLEQ_REMOVE_HEAD(>l3vpns, entry);
+   while ((vpn = STAILQ_FIRST(>l3vpns)) != NULL) {
+   STAILQ_REMOVE_HEAD(>l3vpns, entry);
if (ktable_update(vpn->rtableid, vpn->descr, vpn->flags,
conf->fib_priority) == -1) {
log_warnx("failed to load rdomain %d",
Index: bgpd/bgpd.h
===
RCS file: /cvs/src/usr.sbin/bgpd/bgpd.h,v
retrieving revision 1.406
diff -u -p -r1.406 bgpd.h
--- bgpd/bgpd.h 23 Dec 2020 13:20:47 -  1.406
+++ bgpd/bgpd.h 25 Dec 2020 16:21:30 -
@@ -237,13 +237,13 @@ struct peer;
 RB_HEAD(peer_head, peer);
 
 struct l3vpn;
-SIMPLEQ_HEAD(l3vpn_head, l3vpn);
+STAILQ_HEAD(l3vpn_head, l3vpn);
 
 struct network;
 TAILQ_HEAD(network_head, network);
 
 struct prefixset;
-SIMPLEQ_HEAD(prefixset_head, prefixset);
+STAILQ_HEAD(prefixset_head, prefixset);
 struct prefixset_item;
 RB_HEAD(prefixset_tree, prefixset_item);
 
@@ -259,14 +259,14 @@ struct trie_head {
 struct rde_prefixset {
charname[SET_NAME_LEN];
struct trie_headth;
-   

Rename SIMPLEQ_ to STAILQ_, diff 7/7 (man+regress)

2020-12-26 Thread Denis Fondras
Rename SIMPLEQ_* to STAILQ_* in /usr/src/share and /usr/src/regress

Index: regress/usr.sbin/bgpd/unittests/rde_sets_test.c
===
RCS file: /cvs/src/regress/usr.sbin/bgpd/unittests/rde_sets_test.c,v
retrieving revision 1.7
diff -u -p -r1.7 rde_sets_test.c
--- regress/usr.sbin/bgpd/unittests/rde_sets_test.c 17 Dec 2019 11:57:16 
-  1.7
+++ regress/usr.sbin/bgpd/unittests/rde_sets_test.c 25 Dec 2020 16:40:36 
-
@@ -54,7 +54,7 @@ main(int argc, char **argv)
struct as_set *a, *aa, *b, *c, *empty;
size_t i;
 
-   SIMPLEQ_INIT(_sets);
+   STAILQ_INIT(_sets);
 
a = build_set("a", va, sizeof(va) / sizeof(va[0]),
sizeof(va) / sizeof(va[0]));
Index: share/man/man3/queue.3
===
RCS file: /cvs/src/share/man/man3/queue.3,v
retrieving revision 1.67
diff -u -p -r1.67 queue.3
--- share/man/man3/queue.3  13 Jul 2020 01:28:10 -  1.67
+++ share/man/man3/queue.3  25 Dec 2020 16:40:36 -
@@ -62,21 +62,21 @@
 .Nm LIST_INSERT_HEAD ,
 .Nm LIST_REMOVE ,
 .Nm LIST_REPLACE ,
-.Nm SIMPLEQ_ENTRY ,
-.Nm SIMPLEQ_HEAD ,
-.Nm SIMPLEQ_HEAD_INITIALIZER ,
-.Nm SIMPLEQ_FIRST ,
-.Nm SIMPLEQ_NEXT ,
-.Nm SIMPLEQ_EMPTY ,
-.Nm SIMPLEQ_FOREACH ,
-.Nm SIMPLEQ_FOREACH_SAFE ,
-.Nm SIMPLEQ_INIT ,
-.Nm SIMPLEQ_INSERT_AFTER ,
-.Nm SIMPLEQ_INSERT_HEAD ,
-.Nm SIMPLEQ_INSERT_TAIL ,
-.Nm SIMPLEQ_REMOVE_AFTER ,
-.Nm SIMPLEQ_REMOVE_HEAD ,
-.Nm SIMPLEQ_CONCAT ,
+.Nm STAILQ_ENTRY ,
+.Nm STAILQ_HEAD ,
+.Nm STAILQ_HEAD_INITIALIZER ,
+.Nm STAILQ_FIRST ,
+.Nm STAILQ_NEXT ,
+.Nm STAILQ_EMPTY ,
+.Nm STAILQ_FOREACH ,
+.Nm STAILQ_FOREACH_SAFE ,
+.Nm STAILQ_INIT ,
+.Nm STAILQ_INSERT_AFTER ,
+.Nm STAILQ_INSERT_HEAD ,
+.Nm STAILQ_INSERT_TAIL ,
+.Nm STAILQ_REMOVE_AFTER ,
+.Nm STAILQ_REMOVE_HEAD ,
+.Nm STAILQ_CONCAT ,
 .Nm TAILQ_ENTRY ,
 .Nm TAILQ_HEAD ,
 .Nm TAILQ_HEAD_INITIALIZER ,
@@ -97,7 +97,7 @@
 .Nm TAILQ_REMOVE ,
 .Nm TAILQ_REPLACE ,
 .Nm TAILQ_CONCAT
-.Nd intrusive singly-linked and doubly-linked lists, simple queues, and tail 
queues
+.Nd intrusive singly-linked and doubly-linked lists, singly-linked tail 
queues, and tail queues
 .Sh SYNOPSIS
 .In sys/queue.h
 .Pp
@@ -149,30 +149,30 @@
 .Ft void
 .Fn LIST_REPLACE "struct TYPE *elm" "struct TYPE *elm2" "FIELDNAME"
 .Pp
-.Fn SIMPLEQ_ENTRY "TYPE"
-.Fn SIMPLEQ_HEAD "HEADNAME" "TYPE"
-.Fn SIMPLEQ_HEAD_INITIALIZER "SIMPLEQ_HEAD head"
+.Fn STAILQ_ENTRY "TYPE"
+.Fn STAILQ_HEAD "HEADNAME" "TYPE"
+.Fn STAILQ_HEAD_INITIALIZER "STAILQ_HEAD head"
 .Ft "struct TYPE *"
-.Fn SIMPLEQ_FIRST "SIMPLEQ_HEAD *head"
+.Fn STAILQ_FIRST "STAILQ_HEAD *head"
 .Ft "struct TYPE *"
-.Fn SIMPLEQ_NEXT "struct TYPE *listelm" "FIELDNAME"
+.Fn STAILQ_NEXT "struct TYPE *listelm" "FIELDNAME"
 .Ft int
-.Fn SIMPLEQ_EMPTY "SIMPLEQ_HEAD *head"
-.Fn SIMPLEQ_FOREACH "VARNAME" "SIMPLEQ_HEAD *head" "FIELDNAME"
-.Fn SIMPLEQ_FOREACH_SAFE "VARNAME" "SIMPLEQ_HEAD *head" "FIELDNAME" 
"TEMP_VARNAME"
+.Fn STAILQ_EMPTY "STAILQ_HEAD *head"
+.Fn STAILQ_FOREACH "VARNAME" "STAILQ_HEAD *head" "FIELDNAME"
+.Fn STAILQ_FOREACH_SAFE "VARNAME" "STAILQ_HEAD *head" "FIELDNAME" 
"TEMP_VARNAME"
 .Ft void
-.Fn SIMPLEQ_INIT "SIMPLEQ_HEAD *head"
+.Fn STAILQ_INIT "STAILQ_HEAD *head"
 .Ft void
-.Fn SIMPLEQ_INSERT_AFTER "SIMPLEQ_HEAD *head" "struct TYPE *listelm" "struct 
TYPE *elm" "FIELDNAME"
+.Fn STAILQ_INSERT_AFTER "STAILQ_HEAD *head" "struct TYPE *listelm" "struct 
TYPE *elm" "FIELDNAME"
 .Ft void
-.Fn SIMPLEQ_INSERT_HEAD "SIMPLEQ_HEAD *head" "struct TYPE *elm" "FIELDNAME"
+.Fn STAILQ_INSERT_HEAD "STAILQ_HEAD *head" "struct TYPE *elm" "FIELDNAME"
 .Ft void
-.Fn SIMPLEQ_INSERT_TAIL "SIMPLEQ_HEAD *head" "struct TYPE *elm" "FIELDNAME"
+.Fn STAILQ_INSERT_TAIL "STAILQ_HEAD *head" "struct TYPE *elm" "FIELDNAME"
 .Ft void
-.Fn SIMPLEQ_REMOVE_AFTER "SIMPLEQ_HEAD *head" "struct TYPE *elm" "FIELDNAME"
+.Fn STAILQ_REMOVE_AFTER "STAILQ_HEAD *head" "struct TYPE *elm" "FIELDNAME"
 .Ft void
-.Fn SIMPLEQ_REMOVE_HEAD "SIMPLEQ_HEAD *head" "FIELDNAME"
-.Fn SIMPLEQ_CONCAT "SIMPLEQ_HEAD *head1" "SIMPLEQ_HEAD *head2"
+.Fn STAILQ_REMOVE_HEAD "STAILQ_HEAD *head" "FIELDNAME"
+.Fn STAILQ_CONCAT "STAILQ_HEAD *head1" "STAILQ_HEAD *head2"
 .Pp
 .Fn TAILQ_ENTRY "TYPE"
 .Fn TAILQ_HEAD "HEADNAME" "TYPE"
@@ -208,7 +208,7 @@
 .Fn TAILQ_CONCAT "TAILQ_HEAD *head1" "TAILQ_HEAD *head2" "FIELDNAME"
 .Sh DESCRIPTION
 These macros define and operate on four types of data structures:
-singly-linked lists, simple queues, lists, and tail queues.
+singly-linked lists, singly-linked tail queues, lists, and tail queues.
 All four structures support the following functionality:
 .Pp
 .Bl -enum -compact -offset indent
@@ -237,7 +237,7 @@ and support only the above functionality
 Singly-linked lists are ideal for applications with large datasets
 and few or no removals, or for implementing a LIFO queue.
 .Pp
-Simple queues add the following functionality:
+Singly-linked tail queues add the following functionality:
 .Pp
 .Bl 

Rename SIMPLEQ_ to STAILQ_, diff 4/7 (sbin)

2020-12-26 Thread Denis Fondras
Rename SIMPLEQ_* to STAILQ_* in /usr/src/sbin

Index: iked/iked.h
===
RCS file: /cvs/src/sbin/iked/iked.h,v
retrieving revision 1.179
diff -u -p -r1.179 iked.h
--- iked/iked.h 21 Dec 2020 22:49:36 -  1.179
+++ iked/iked.h 25 Dec 2020 16:19:24 -
@@ -531,9 +531,9 @@ RB_HEAD(iked_addrpool6, iked_sa);
 struct iked_certreq {
struct ibuf *cr_data;
uint8_t  cr_type;
-   SIMPLEQ_ENTRY(iked_certreq)  cr_entry;
+   STAILQ_ENTRY(iked_certreq)   cr_entry;
 };
-SIMPLEQ_HEAD(iked_certreqs, iked_certreq);
+STAILQ_HEAD(iked_certreqs, iked_certreq);
 
 #define EAP_STATE_IDENTITY (1)
 #define EAP_STATE_MSCHAPV2_CHALLENGE   (2)
Index: iked/ikev2.c
===
RCS file: /cvs/src/sbin/iked/ikev2.c,v
retrieving revision 1.292
diff -u -p -r1.292 ikev2.c
--- iked/ikev2.c21 Dec 2020 22:49:36 -  1.292
+++ iked/ikev2.c25 Dec 2020 16:19:24 -
@@ -3404,7 +3404,7 @@ ikev2_handle_certreq(struct iked* env, s
 * We could alternatively extract the CA from the peer certificate
 * to find a matching local one.
 */
-   if (SIMPLEQ_EMPTY(>msg_certreqs)) {
+   if (STAILQ_EMPTY(>msg_certreqs)) {
if (sa->sa_policy->pol_certreqtype)
crtype = sa->sa_policy->pol_certreqtype;
else
@@ -3413,8 +3413,8 @@ ikev2_handle_certreq(struct iked* env, s
crtype, 0, ibuf_data(env->sc_certreq),
ibuf_size(env->sc_certreq), PROC_CERT);
} else {
-   while ((cr = SIMPLEQ_FIRST(>msg_certreqs))) {
-   if (SIMPLEQ_NEXT(cr, cr_entry) != NULL)
+   while ((cr = STAILQ_FIRST(>msg_certreqs))) {
+   if (STAILQ_NEXT(cr, cr_entry) != NULL)
more = 1;
else
more = 0;
@@ -3425,7 +3425,7 @@ ikev2_handle_certreq(struct iked* env, s
PROC_CERT);
 
ibuf_release(cr->cr_data);
-   SIMPLEQ_REMOVE_HEAD(>msg_certreqs, cr_entry);
+   STAILQ_REMOVE_HEAD(>msg_certreqs, cr_entry);
free(cr);
}
}
Index: iked/ikev2_msg.c
===
RCS file: /cvs/src/sbin/iked/ikev2_msg.c,v
retrieving revision 1.77
diff -u -p -r1.77 ikev2_msg.c
--- iked/ikev2_msg.c29 Oct 2020 21:49:58 -  1.77
+++ iked/ikev2_msg.c25 Dec 2020 16:19:24 -
@@ -95,7 +95,7 @@ ikev2_msg_cb(int fd, short event, void *
return;
 
TAILQ_INIT(_proposals);
-   SIMPLEQ_INIT(_certreqs);
+   STAILQ_INIT(_certreqs);
msg.msg_fd = fd;
 
if (hdr.ike_version == IKEV1_VERSION)
@@ -211,9 +211,9 @@ ikev2_msg_cleanup(struct iked *env, stru
msg->msg_cp_addr6 = NULL;
 
config_free_proposals(>msg_proposals, 0);
-   while ((cr = SIMPLEQ_FIRST(>msg_certreqs))) {
+   while ((cr = STAILQ_FIRST(>msg_certreqs))) {
ibuf_release(cr->cr_data);
-   SIMPLEQ_REMOVE_HEAD(>msg_certreqs, cr_entry);
+   STAILQ_REMOVE_HEAD(>msg_certreqs, cr_entry);
free(cr);
}
}
Index: iked/ikev2_pld.c
===
RCS file: /cvs/src/sbin/iked/ikev2_pld.c,v
retrieving revision 1.114
diff -u -p -r1.114 ikev2_pld.c
--- iked/ikev2_pld.c25 Nov 2020 22:17:14 -  1.114
+++ iked/ikev2_pld.c25 Dec 2020 16:19:24 -
@@ -899,7 +899,7 @@ ikev2_pld_certreq(struct iked *env, stru
return (-1);
}
cr->cr_type = cert.cert_type;
-   SIMPLEQ_INSERT_TAIL(>msg_parent->msg_certreqs, cr, cr_entry);
+   STAILQ_INSERT_TAIL(>msg_parent->msg_certreqs, cr, cr_entry);
 
return (0);
 }
Index: iked/pfkey.c
===
RCS file: /cvs/src/sbin/iked/pfkey.c,v
retrieving revision 1.74
diff -u -p -r1.74 pfkey.c
--- iked/pfkey.c4 Dec 2020 16:18:14 -   1.74
+++ iked/pfkey.c25 Dec 2020 16:19:24 -
@@ -57,13 +57,13 @@ static struct event pfkey_timer_ev;
 static struct timeval pfkey_timer_tv;
 
 struct pfkey_message {
-   SIMPLEQ_ENTRY(pfkey_message)
+   STAILQ_ENTRY(pfkey_message)
 pm_entry;
uint8_t *pm_data;
ssize_t  pm_length;
 };
-SIMPLEQ_HEAD(, pfkey_message) pfkey_retry, pfkey_postponed =
-SIMPLEQ_HEAD_INITIALIZER(pfkey_postponed);
+STAILQ_HEAD(, pfkey_message) pfkey_retry, pfkey_postponed =
+STAILQ_HEAD_INITIALIZER(pfkey_postponed);
 
 struct pfkey_constmap {
uint8_t  pfkey_id;
@@ -1316,7 

Rename SIMPLEQ_ to STAILQ_, diff 3/7 (lib)

2020-12-26 Thread Denis Fondras
Rename SIMPLEQ_ to STAILQ_ in /usr/src/lib

Index: libc/gen/posix_spawn.c
===
RCS file: /cvs/src/lib/libc/gen/posix_spawn.c,v
retrieving revision 1.10
diff -u -p -r1.10 posix_spawn.c
--- libc/gen/posix_spawn.c  28 Jun 2019 13:32:41 -  1.10
+++ libc/gen/posix_spawn.c  25 Dec 2020 16:17:01 -
@@ -46,11 +46,11 @@ struct __posix_spawnattr {
 };
 
 struct __posix_spawn_file_actions {
-   SIMPLEQ_HEAD(, __posix_spawn_file_actions_entry) fa_list;
+   STAILQ_HEAD(, __posix_spawn_file_actions_entry) fa_list;
 };
 
 typedef struct __posix_spawn_file_actions_entry {
-   SIMPLEQ_ENTRY(__posix_spawn_file_actions_entry) fae_list;
+   STAILQ_ENTRY(__posix_spawn_file_actions_entry) fae_list;
enum { FAE_OPEN, FAE_DUP2, FAE_CLOSE } fae_action;
 
int fae_fildes;
@@ -182,7 +182,7 @@ process_file_actions(const posix_spawn_f
int error;
 
/* Replay all file descriptor modifications */
-   SIMPLEQ_FOREACH(fae, >fa_list, fae_list) {
+   STAILQ_FOREACH(fae, >fa_list, fae_list) {
error = process_file_actions_entry(fae);
if (error)
return (error);
@@ -258,7 +258,7 @@ posix_spawn_file_actions_init(posix_spaw
if (fa == NULL)
return (errno);
 
-   SIMPLEQ_INIT(>fa_list);
+   STAILQ_INIT(>fa_list);
*ret = fa;
return (0);
 }
@@ -268,9 +268,9 @@ posix_spawn_file_actions_destroy(posix_s
 {
posix_spawn_file_actions_entry_t *fae;
 
-   while ((fae = SIMPLEQ_FIRST(&(*fa)->fa_list)) != NULL) {
+   while ((fae = STAILQ_FIRST(&(*fa)->fa_list)) != NULL) {
/* Remove file action entry from the queue */
-   SIMPLEQ_REMOVE_HEAD(&(*fa)->fa_list, fae_list);
+   STAILQ_REMOVE_HEAD(&(*fa)->fa_list, fae_list);
 
/* Deallocate file action entry */
if (fae->fae_action == FAE_OPEN)
@@ -309,7 +309,7 @@ posix_spawn_file_actions_addopen(posix_s
fae->fae_oflag = oflag;
fae->fae_mode = mode;
 
-   SIMPLEQ_INSERT_TAIL(&(*fa)->fa_list, fae, fae_list);
+   STAILQ_INSERT_TAIL(&(*fa)->fa_list, fae, fae_list);
return (0);
 }
 
@@ -332,7 +332,7 @@ posix_spawn_file_actions_adddup2(posix_s
fae->fae_fildes = fildes;
fae->fae_newfildes = newfildes;
 
-   SIMPLEQ_INSERT_TAIL(&(*fa)->fa_list, fae, fae_list);
+   STAILQ_INSERT_TAIL(&(*fa)->fa_list, fae, fae_list);
return (0);
 }
 
@@ -354,7 +354,7 @@ posix_spawn_file_actions_addclose(posix_
fae->fae_action = FAE_CLOSE;
fae->fae_fildes = fildes;
 
-   SIMPLEQ_INSERT_TAIL(&(*fa)->fa_list, fae, fae_list);
+   STAILQ_INSERT_TAIL(&(*fa)->fa_list, fae, fae_list);
return (0);
 }
 
Index: libfuse/fuse_private.h
===
RCS file: /cvs/src/lib/libfuse/fuse_private.h,v
retrieving revision 1.22
diff -u -p -r1.22 fuse_private.h
--- libfuse/fuse_private.h  16 Nov 2018 02:16:17 -  1.22
+++ libfuse/fuse_private.h  25 Dec 2020 16:17:01 -
@@ -38,7 +38,7 @@ struct fuse_vnode {
 
char path[NAME_MAX + 1];
 
-   SIMPLEQ_ENTRY(fuse_vnode) node; /* for dict */
+   STAILQ_ENTRY(fuse_vnode) node; /* for dict */
 };
 
 struct fuse_dirhandle {
@@ -52,7 +52,7 @@ struct fuse_dirhandle {
off_t off;
 };
 
-SIMPLEQ_HEAD(fuse_vn_head, fuse_vnode);
+STAILQ_HEAD(fuse_vn_head, fuse_vnode);
 SPLAY_HEAD(dict, dictentry);
 SPLAY_HEAD(tree, treeentry);
 
Index: libfuse/fuse_subr.c
===
RCS file: /cvs/src/lib/libfuse/fuse_subr.c,v
retrieving revision 1.12
diff -u -p -r1.12 fuse_subr.c
--- libfuse/fuse_subr.c 21 May 2018 11:47:46 -  1.12
+++ libfuse/fuse_subr.c 25 Dec 2020 16:17:01 -
@@ -94,19 +94,19 @@ set_vn(struct fuse *f, struct fuse_vnode
vn_head = malloc(sizeof(*vn_head));
if (vn_head == NULL)
return (0);
-   SIMPLEQ_INIT(vn_head);
+   STAILQ_INIT(vn_head);
} else {
vn_head = dict_get(>name_tree, v->path);
if (vn_head == NULL)
return (0);
}
 
-   SIMPLEQ_FOREACH(vn, vn_head, node) {
+   STAILQ_FOREACH(vn, vn_head, node) {
if (v->parent == vn->parent && v->ino == vn->ino)
return (1);
}
 
-   SIMPLEQ_INSERT_TAIL(vn_head, v, node);
+   STAILQ_INSERT_TAIL(vn_head, v, node);
dict_set(>name_tree, v->path, vn_head);
 
return (1);
@@ -124,7 +124,7 @@ remove_vnode_from_name_tree(struct fuse 
return;
 
lastv = NULL;
-   SIMPLEQ_FOREACH(v, vn_head, node) {
+   STAILQ_FOREACH(v, vn_head, node) {
if (v->parent == vn->parent)
break;
 
@@ -134,13 +134,13 @@ 

Rename SIMPLEQ_ to STAILQ_, diff 1/7

2020-12-26 Thread Denis Fondras
mpi@ reminded me I had this diff cooking.

This diff renames SIMPLEQ_* to STAILQ_* in /usr/src/sys/sys to unify with 
FreeBSD and Linux.

I added aliases at the end of queue.h to avoid breaking base too much. they will
be removed as soon as diff 2,3,4,5,6,7 are commited.

net/sniproxy has a patch to define STAILQ_*, it may be removed later.

Index: buf.h
===
RCS file: /cvs/src/sys/sys/buf.h,v
retrieving revision 1.112
diff -u -p -r1.112 buf.h
--- buf.h   29 Nov 2019 01:04:08 -  1.112
+++ buf.h   25 Dec 2020 14:24:08 -
@@ -105,15 +105,15 @@ void   bufq_quiesce(void);
 voidbufq_restart(void);
 
 /* fifo */
-SIMPLEQ_HEAD(bufq_fifo_head, buf);
+STAILQ_HEAD(bufq_fifo_head, buf);
 struct bufq_fifo {
-   SIMPLEQ_ENTRY(buf)  bqf_entries;
+   STAILQ_ENTRY(buf)   bqf_entries;
 };
 
 /* nscan */
-SIMPLEQ_HEAD(bufq_nscan_head, buf);
+STAILQ_HEAD(bufq_nscan_head, buf);
 struct bufq_nscan {
-   SIMPLEQ_ENTRY(buf)  bqf_entries;
+   STAILQ_ENTRY(buf)   bqf_entries;
 };
 
 /* bufq link in struct buf */
Index: fusebuf.h
===
RCS file: /cvs/src/sys/sys/fusebuf.h,v
retrieving revision 1.13
diff -u -p -r1.13 fusebuf.h
--- fusebuf.h   19 Jun 2018 11:27:54 -  1.13
+++ fusebuf.h   25 Dec 2020 14:24:08 -
@@ -27,7 +27,7 @@
 
 /* header at beginning of each fusebuf: */
 struct fb_hdr {
-   SIMPLEQ_ENTRY(fusebuf)  fh_next;/* next buffer in chain */
+   STAILQ_ENTRY(fusebuf)   fh_next;/* next buffer in chain */
size_t  fh_len; /* Amount of data */
int fh_err; /* errno to pass back */
int fh_type;/* type of data */
Index: pool.h
===
RCS file: /cvs/src/sys/sys/pool.h,v
retrieving revision 1.77
diff -u -p -r1.77 pool.h
--- pool.h  19 Jul 2019 09:03:03 -  1.77
+++ pool.h  25 Dec 2020 14:24:08 -
@@ -152,7 +152,7 @@ struct pool {
union pool_lock pr_lock;
const struct pool_lock_ops *
pr_lock_ops;
-   SIMPLEQ_ENTRY(pool)
+   STAILQ_ENTRY(pool)
pr_poollist;
struct pool_pagelist
pr_emptypages;  /* Empty pages */
Index: queue.h
===
RCS file: /cvs/src/sys/sys/queue.h,v
retrieving revision 1.45
diff -u -p -r1.45 queue.h
--- queue.h 12 Jul 2018 14:22:54 -  1.45
+++ queue.h 25 Dec 2020 14:24:08 -
@@ -96,7 +96,7 @@ struct name { 
\
struct type *slh_first; /* first element */ \
 }
 
-#defineSLIST_HEAD_INITIALIZER(head)
\
+#define SLIST_HEAD_INITIALIZER(head)   \
{ NULL }
 
 #define SLIST_ENTRY(type)  \
@@ -107,43 +107,43 @@ struct {  
\
 /*
  * Singly-linked List access methods.
  */
-#defineSLIST_FIRST(head)   ((head)->slh_first)
-#defineSLIST_END(head) NULL
-#defineSLIST_EMPTY(head)   (SLIST_FIRST(head) == SLIST_END(head))
-#defineSLIST_NEXT(elm, field)  ((elm)->field.sle_next)
+#define SLIST_FIRST(head)  ((head)->slh_first)
+#define SLIST_END(head)NULL
+#define SLIST_EMPTY(head)  (SLIST_FIRST(head) == SLIST_END(head))
+#define SLIST_NEXT(elm, field) ((elm)->field.sle_next)
 
-#defineSLIST_FOREACH(var, head, field) 
\
+#define SLIST_FOREACH(var, head, field)
\
for((var) = SLIST_FIRST(head);  \
(var) != SLIST_END(head);   \
(var) = SLIST_NEXT(var, field))
 
-#defineSLIST_FOREACH_SAFE(var, head, field, tvar)  
\
-   for ((var) = SLIST_FIRST(head); \
+#define SLIST_FOREACH_SAFE(var, head, field, tvar) \
+   for ((var) = SLIST_FIRST(head); \
(var) && ((tvar) = SLIST_NEXT(var, field), 1);  \
(var) = (tvar))
 
 /*
  * Singly-linked List functions.
  */
-#defineSLIST_INIT(head) {  
\
+#define SLIST_INIT(head) { \
SLIST_FIRST(head) = SLIST_END(head);\
 }
 
-#defineSLIST_INSERT_AFTER(slistelm, elm, field) do {   
\
+#define SLIST_INSERT_AFTER(slistelm, elm, field) do {  \
(elm)->field.sle_next = (slistelm)->field.sle_next; 

Re: Document art locking fields

2020-11-11 Thread Denis Fondras
On Wed, Nov 11, 2020 at 05:25:25AM -0300, Martin Pieuchot wrote:
> While discussing the new source address mechanism with denis@, I figured
> those ought to be documented.
> 
> Note that `ar_rtableid' is unused and can die.  The ART code is actually
> free from any network knowledge.
> 
> ok?
> 

it seems sound.
OK denis@

> Index: net/art.c
> ===
> RCS file: /cvs/src/sys/net/art.c,v
> retrieving revision 1.28
> diff -u -p -r1.28 art.c
> --- net/art.c 31 Mar 2019 19:29:27 -  1.28
> +++ net/art.c 9 Nov 2020 19:52:48 -
> @@ -115,7 +115,6 @@ art_alloc(unsigned int rtableid, unsigne
>   }
>  
>   ar->ar_off = off;
> - ar->ar_rtableid = rtableid;
>   rw_init(>ar_lock, "art");
>  
>   return (ar);
> Index: net/art.h
> ===
> RCS file: /cvs/src/sys/net/art.h,v
> retrieving revision 1.19
> diff -u -p -r1.19 art.h
> --- net/art.h 29 Oct 2020 21:15:27 -  1.19
> +++ net/art.h 9 Nov 2020 19:52:42 -
> @@ -27,16 +27,22 @@
>  
>  /*
>   * Root of the ART tables, equivalent to the radix head.
> + *
> + *  Locks used to protect struct members in this file:
> + *   I   immutable after creation
> + *   l   root's `ar_lock'
> + *   K   kernel lock
> + *  For SRP related structures that allow lock-free reads, the write lock
> + *  is indicated below.
>   */
>  struct art_root {
> - struct srp   ar_root;   /* First table */
> - struct rwlockar_lock;   /* Serialise modifications */
> - uint8_t  ar_bits[ART_MAXLVL];   /* Per level stride */
> - uint8_t  ar_nlvl;   /* Number of levels */
> - uint8_t  ar_alen;   /* Address length in bits */
> - uint8_t  ar_off;/* Offset of the key in bytes */
> - unsigned int ar_rtableid;   /* ID of this routing table */
> - struct sockaddr *source;/* optional src addr to use */
> + struct srp   ar_root;   /* [l] First table */
> + struct rwlockar_lock;   /* [] Serialise modifications */
> + uint8_t  ar_bits[ART_MAXLVL]; /* [I] Per level stride */
> + uint8_t  ar_nlvl;   /* [I] Number of levels */
> + uint8_t  ar_alen;   /* [I] Address length in bits */
> + uint8_t  ar_off;/* [I] Offset of key in bytes */
> + struct sockaddr *source;/* [K] optional src addr to use 
> */
>  };
>  
>  #define ISLEAF(e)(((unsigned long)(e) & 1) == 0)
> 



Use selected source IP when replying to reflecting ICMP

2020-11-08 Thread Denis Fondras
ICMP error replies are sent from the IP of the interface the packet came in even
when the source IP was forced with route(8).

Index: netinet/ip_icmp.c
===
RCS file: /cvs/src/sys/netinet/ip_icmp.c,v
retrieving revision 1.183
diff -u -p -r1.183 ip_icmp.c
--- netinet/ip_icmp.c   22 Aug 2020 17:55:54 -  1.183
+++ netinet/ip_icmp.c   8 Nov 2020 16:48:15 -
@@ -689,6 +689,8 @@ icmp_reflect(struct mbuf *m, struct mbuf
struct mbuf *opts = NULL;
struct sockaddr_in sin;
struct rtentry *rt = NULL;
+   struct sockaddr *ip4_source = NULL;
+   struct in_addr src;
int optlen = (ip->ip_hl << 2) - sizeof(struct ip);
u_int rtableid;
 
@@ -707,6 +709,7 @@ icmp_reflect(struct mbuf *m, struct mbuf
m_resethdr(m);
m->m_pkthdr.ph_rtableid = rtableid;
 
+   memset(, 0, sizeof(struct in_addr));
/*
 * If the incoming packet was addressed directly to us,
 * use dst as the src for the reply.  For broadcast, use
@@ -721,7 +724,7 @@ icmp_reflect(struct mbuf *m, struct mbuf
rt = rtalloc(sintosa(), 0, rtableid);
if (rtisvalid(rt) &&
ISSET(rt->rt_flags, RTF_LOCAL|RTF_BROADCAST))
-   ia = ifatoia(rt->rt_ifa);
+   src = ifatoia(rt->rt_ifa)->ia_addr.sin_addr;
}
 
/*
@@ -729,7 +732,7 @@ icmp_reflect(struct mbuf *m, struct mbuf
 * Use the new source address and do a route lookup. If it fails
 * drop the packet as there is no path to the host.
 */
-   if (ia == NULL) {
+   if (src.s_addr == 0) {
rtfree(rt);
 
memset(, 0, sizeof(sin));
@@ -745,14 +748,23 @@ icmp_reflect(struct mbuf *m, struct mbuf
return (EHOSTUNREACH);
}
 
-   ia = ifatoia(rt->rt_ifa);
+   ip4_source = rtable_getsource(rtableid, AF_INET);
+   if (ip4_source != NULL) {
+   struct ifaddr *ifa;
+   if ((ifa = ifa_ifwithaddr(ip4_source, rtableid)) !=
+   NULL && ISSET(ifa->ifa_ifp->if_flags, IFF_UP)) {
+   src = satosin(ip4_source)->sin_addr;
+   }
+   }
+   if (src.s_addr == 0)
+   src = ifatoia(rt->rt_ifa)->ia_addr.sin_addr;
}
 
ip->ip_dst = ip->ip_src;
ip->ip_ttl = MAXTTL;
 
/* It is safe to dereference ``ia'' iff ``rt'' is valid. */
-   ip->ip_src = ia->ia_addr.sin_addr;
+   ip->ip_src = src;
rtfree(rt);
 
if (optlen > 0) {
Index: netinet6/icmp6.c
===
RCS file: /cvs/src/sys/netinet6/icmp6.c,v
retrieving revision 1.233
diff -u -p -r1.233 icmp6.c
--- netinet6/icmp6.c28 Oct 2020 17:27:35 -  1.233
+++ netinet6/icmp6.c8 Nov 2020 16:48:15 -
@@ -1146,6 +1146,7 @@ icmp6_reflect(struct mbuf **mp, size_t o
 
if (src == NULL) {
struct in6_ifaddr *ia6;
+   struct sockaddr *ip6_source = NULL;
 
/*
 * This case matches to multicasts, our anycast, or unicasts
@@ -1164,7 +1165,15 @@ icmp6_reflect(struct mbuf **mp, size_t o
goto bad;
}
ia6 = in6_ifawithscope(rt->rt_ifa->ifa_ifp, , rtableid);
-   if (ia6 != NULL)
+   ip6_source = rtable_getsource(rtableid, AF_INET6);
+   if (ip6_source != NULL) {
+   struct ifaddr *ifa;
+   if ((ifa = ifa_ifwithaddr(ip6_source, rtableid)) !=
+   NULL && ISSET(ifa->ifa_ifp->if_flags, IFF_UP)) {
+   src = (ip6_source)->sin6_addr;
+   }
+   }
+   if (src == NULL && ia6 != NULL)
src = >ia_addr.sin6_addr;
if (src == NULL)
src = (rt->rt_ifa)->ia_addr.sin6_addr;



route sourceaddr works with p2p interfaces

2020-11-02 Thread Denis Fondras
Hi,

route(8) sourceaddr is not used with p2p interfaces.
My initial fear was about tunnel interfaces but after some more testing, there
is no need to be so.

Here is the diff:

Index: sbin/route/route.8
===
RCS file: /cvs/src/sbin/route/route.8,v
retrieving revision 1.93
diff -u -p -r1.93 route.8
--- sbin/route/route.8  30 Oct 2020 14:30:51 -  1.93
+++ sbin/route/route.8  2 Nov 2020 19:53:34 -
@@ -234,8 +234,6 @@ The preferred source will not be used wh
 .It
 destination is on-link
 .It
-output interface is point-to-point
-.It
 source address is assigned to a disabled interface
 .El
 .El
Index: sys/netinet/in_pcb.c
===
RCS file: /cvs/src/sys/netinet/in_pcb.c,v
retrieving revision 1.250
diff -u -p -r1.250 in_pcb.c
--- sys/netinet/in_pcb.c29 Oct 2020 21:15:27 -  1.250
+++ sys/netinet/in_pcb.c2 Nov 2020 19:53:36 -
@@ -960,12 +960,10 @@ in_pcbselsrc(struct in_addr **insrc, str
/*
 * Use preferred source address if :
 * - destination is not onlink
-* - output interface is not PtoP
 * - preferred source addresss is set
 * - output interface is UP
 */
-   if ((ro->ro_rt && !(ro->ro_rt->rt_flags & RTF_LLINFO)) &&
-   (ia && !(ia->ia_ifp->if_flags & IFF_POINTOPOINT))) {
+   if (ro->ro_rt && !(ro->ro_rt->rt_flags & RTF_LLINFO)) {
ip4_source = rtable_getsource(rtableid, AF_INET);
if (ip4_source != NULL) {
struct ifaddr *ifa;
Index: sys/netinet6/in6_src.c
===
RCS file: /cvs/src/sys/netinet6/in6_src.c,v
retrieving revision 1.82
diff -u -p -r1.82 in6_src.c
--- sys/netinet6/in6_src.c  29 Oct 2020 21:15:27 -  1.82
+++ sys/netinet6/in6_src.c  2 Nov 2020 19:53:36 -
@@ -220,12 +220,10 @@ in6_pcbselsrc(struct in6_addr **in6src, 
/*
 * Use preferred source address if :
 * - destination is not onlink
-* - output interface is not PtoP
 * - preferred source addresss is set
 * - output interface is UP
 */
-   if ((ro->ro_rt && !(ro->ro_rt->rt_flags & RTF_LLINFO)) &&
-   (ia6 && !(ia6->ia_ifp->if_flags & IFF_POINTOPOINT))) {
+   if (ro->ro_rt && !(ro->ro_rt->rt_flags & RTF_LLINFO)) {
ip6_source = rtable_getsource(rtableid, AF_INET6);
if (ip6_source != NULL) {
struct ifaddr *ifa;



Re: Minor tweak relayd agentx manpage

2020-10-30 Thread Denis Fondras
On Fri, Oct 30, 2020 at 09:53:08AM +0100, Martijn van Duren wrote:
> I think metrics is a better word than statistics and it might help
> people if they knew where to query for these metrics.
> 
> OK?

I also find it more accurate.
OK denis@

> martijn@
> 
> Index: relayd.conf.5
> ===
> RCS file: /cvs/src/usr.sbin/relayd/relayd.conf.5,v
> retrieving revision 1.201
> diff -u -p -r1.201 relayd.conf.5
> --- relayd.conf.5 22 Oct 2020 08:00:24 -  1.201
> +++ relayd.conf.5 30 Oct 2020 08:48:23 -
> @@ -121,10 +121,12 @@ Here are the settings that can be set gl
>  .It Ic agentx Oo Ic context Ar context Oc Oo Ic path Ar path Oc
>  Export
>  .Xr relayd 8
> -statistics via an agentx compatible
> +metrics via an agentx compatible
>  .Pq snmp
>  daemon by connecting to
>  .Ar path .
> +Metrics can be found under the relaydMIBObjects subtree
> +.Pq enterprises.30155.3 .
>  If
>  .Ar path
>  is omitted it will default to
> 



Re: relayd(8) remove snmp keyword

2020-10-30 Thread Denis Fondras
On Thu, Oct 29, 2020 at 03:51:24PM +0100, Martijn van Duren wrote:
> 6.8 is out in the wild. I guess this is as good a time as any to remove
> the old snmp keyword.
> 
> OK?
> 

OK denis@

And while it is fresh, is this the right time to update plus.html and
current.html ?



Re: httpd(8): add location access tests

2020-10-27 Thread Denis Fondras
On Tue, Oct 27, 2020 at 12:02:18PM +0100, Matthias Pressfreund wrote:
> True. Updated patch below.
> 

Thanks, I have been using the diff (from your GH account) since a few weeks.

OK denis@

I will commit tonight if nobody stands against.


> 
> 
> Index: usr.sbin/httpd/httpd.conf.5
> ===
> RCS file: /cvs/src/usr.sbin/httpd/httpd.conf.5,v
> retrieving revision 1.113
> diff -u -p -u -p -r1.113 httpd.conf.5
> --- usr.sbin/httpd/httpd.conf.5   5 Sep 2020 11:49:38 -   1.113
> +++ usr.sbin/httpd/httpd.conf.5   27 Oct 2020 10:59:35 -
> @@ -1,5 +1,6 @@
>  .\"  $OpenBSD: httpd.conf.5,v 1.113 2020/09/05 11:49:38 tb Exp $
>  .\"
> +.\" Copyright (c) 2020 Matthias Pressfreund 
>  .\" Copyright (c) 2014, 2015 Reyk Floeter 
>  .\"
>  .\" Permission to use, copy, modify, and distribute this software for any
> @@ -14,7 +15,7 @@
>  .\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
>  .\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
>  .\"
> -.Dd $Mdocdate: September 5 2020 $
> +.Dd $Mdocdate: October 27 2020 $
>  .Dt HTTPD.CONF 5
>  .Os
>  .Sh NAME
> @@ -399,11 +400,16 @@ of the host's domain should be considere
>  .It Ic listen on Ar address Oo Ic tls Oc Ic port Ar number
>  Set the listen address and port.
>  This statement can be specified multiple times.
> -.It Ic location Ar path Brq ...
> +.It Ic location Oo Oo Ic not Oc Ic found Oc Ar path Brq ...
>  Specify server configuration rules for a specific location.
>  The
>  .Ar path
>  argument will be matched against the request path with shell globbing rules.
> +Optionally, it is also possible to match for
> +.Ic found
> +(i.e. accessible) or
> +.Ic not found
> +request paths only.
>  In case of multiple location statements in the same context, the
>  first matching location statement will be put into effect, while all
>  later ones will be ignored.
> @@ -419,7 +425,7 @@ except
>  .Ic tcp
>  and
>  .Ic tls .
> -.It Ic location match Ar path Brq ...
> +.It Ic location Oo Oo Ic not Oc Ic found Oc Ic match Ar path Brq ...
>  Like the
>  .Ic location
>  option,
> Index: usr.sbin/httpd/httpd.h
> ===
> RCS file: /cvs/src/usr.sbin/httpd/httpd.h,v
> retrieving revision 1.152
> diff -u -p -u -p -r1.152 httpd.h
> --- usr.sbin/httpd/httpd.h29 Aug 2020 07:53:48 -  1.152
> +++ usr.sbin/httpd/httpd.h27 Oct 2020 05:59:05 -
> @@ -1,6 +1,7 @@
>  /*   $OpenBSD: httpd.h,v 1.152 2020/08/29 07:53:48 florian Exp $ */
>  
>  /*
> + * Copyright (c) 2020 Matthias Pressfreund 
>   * Copyright (c) 2006 - 2015 Reyk Floeter 
>   * Copyright (c) 2006, 2007 Pierre-Yves Ritschard 
>   * Copyright (c) 2003, 2004 Henning Brauer 
> @@ -391,13 +392,16 @@ SPLAY_HEAD(client_tree, client);
>  #define SRVFLAG_DEFAULT_TYPE 0x0080
>  #define SRVFLAG_PATH_REWRITE 0x0100
>  #define SRVFLAG_NO_PATH_REWRITE  0x0200
> +#define SRVFLAG_LOCATION_FOUND   0x4000
> +#define SRVFLAG_LOCATION_NOT_FOUND 0x8000
>  
>  #define SRVFLAG_BITS \
>   "\10\01INDEX\02NO_INDEX\03AUTO_INDEX\04NO_AUTO_INDEX"   \
>   "\05ROOT\06LOCATION\07FCGI\10NO_FCGI\11LOG\12NO_LOG"\
>   "\14SYSLOG\15NO_SYSLOG\16TLS\17ACCESS_LOG\20ERROR_LOG"  \
>   "\21AUTH\22NO_AUTH\23BLOCK\24NO_BLOCK\25LOCATION_MATCH" \
> - "\26SERVER_MATCH\27SERVER_HSTS\30DEFAULT_TYPE\31PATH\32NO_PATH"
> + "\26SERVER_MATCH\27SERVER_HSTS\30DEFAULT_TYPE\31PATH\32NO_PATH" \
> + "\37LOCATION_FOUND\40LOCATION_NOT_FOUND"
>  
>  #define TCPFLAG_NODELAY  0x01
>  #define TCPFLAG_NNODELAY 0x02
> @@ -690,6 +694,7 @@ const char *
>server_root_strip(const char *, int);
>  struct server_config *
>server_getlocation(struct client *, const char *);
> +int   server_locationaccesstest(struct server_config *, const char *);
>  const char *
>server_http_host(struct sockaddr_storage *, char *, size_t);
>  char *server_http_parsehost(char *, char *, size_t, int *);
> Index: usr.sbin/httpd/parse.y
> ===
> RCS file: /cvs/src/usr.sbin/httpd/parse.y,v
> retrieving revision 1.119
> diff -u -p -u -p -r1.119 parse.y
> --- usr.sbin/httpd/parse.y26 Oct 2020 19:31:22 -  1.119
> +++ usr.sbin/httpd/parse.y27 Oct 2020 05:59:05 -
> @@ -143,12 +143,12 @@ typedef struct {
>  %token   PROTOCOLS REQUESTS ROOT SACK SERVER SOCKET STRIP STYLE SYSLOG 
> TCP TICKET
>  %token   TIMEOUT TLS TYPE TYPES HSTS MAXAGE SUBDOMAINS DEFAULT PRELOAD 
> REQUEST
>  %token   ERROR INCLUDE AUTHENTICATE WITH BLOCK DROP RETURN PASS REWRITE
> -%token   CA CLIENT CRL OPTIONAL PARAM FORWARDED
> +%token   CA CLIENT CRL OPTIONAL PARAM FORWARDED FOUND NOT
>  %token STRING
>  %token NUMBER
>  %typeport
>  %type  

Re: httpd(8): add location access tests

2020-10-27 Thread Denis Fondras
Thanks Matthias,

comment below.

On Tue, Oct 27, 2020 at 08:37:39AM +0100, Matthias Pressfreund wrote:
> Index: usr.sbin/httpd/httpd.conf.5
> ===
> RCS file: /cvs/src/usr.sbin/httpd/httpd.conf.5,v
> retrieving revision 1.113
> diff -u -p -u -p -r1.113 httpd.conf.5
> --- usr.sbin/httpd/httpd.conf.5   5 Sep 2020 11:49:38 -   1.113
> +++ usr.sbin/httpd/httpd.conf.5   27 Oct 2020 05:59:05 -
> @@ -1,5 +1,6 @@
>  .\"  $OpenBSD: httpd.conf.5,v 1.113 2020/09/05 11:49:38 tb Exp $
>  .\"
> +.\" Copyright (c) 2020 Matthias Pressfreund 
>  .\" Copyright (c) 2014, 2015 Reyk Floeter 
>  .\"
>  .\" Permission to use, copy, modify, and distribute this software for any
> @@ -14,7 +15,7 @@
>  .\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
>  .\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
>  .\"
> -.Dd $Mdocdate: September 5 2020 $
> +.Dd $Mdocdate: October 27 2020 $
>  .Dt HTTPD.CONF 5
>  .Os
>  .Sh NAME
> @@ -399,11 +400,16 @@ of the host's domain should be considere
>  .It Ic listen on Ar address Oo Ic tls Oc Ic port Ar number
>  Set the listen address and port.
>  This statement can be specified multiple times.
> -.It Ic location Ar path Brq ...
> +.It Ic location Oo Oo Ic not Oc Ic found Oc Ar path Brq ...
>  Specify server configuration rules for a specific location.
>  The
>  .Ar path
>  argument will be matched against the request path with shell globbing rules.
> +Optionally, it is also possible to match for
> +.Ar found
> +(i.e. accessible) or
> +.Ar not found

.Ic seems best suited here.



relayd: allow mix of TLS and non-TLS backend

2020-10-26 Thread Denis Fondras
With this config :

---
relay "proxy" {
  listen on {{publicip}} port 443 tls
  protocol "httpproxy"

  forward with tls to  port 443
  forward to  port 10100
}
---

relayd(8) will currently use TLS for all backends.

This diff will use TLS only if 'with tls' is used. In the example above, relayd
will forward to web with HTTPS and to app with HTTP.

While at it, add a field in "relayctl sh" to display TLS state :

---
# relayctl sh su
Id  TypeNameAvlblty Status  TLS
1   relay   proxy   active  yes
1   table   psono_web:443   empty   yes
1   host127.0.0.1   unknown
2   table   psono_server:10100  empty   no
2   host127.0.0.1   unknown
---

Regress still pass.

Comments ?


Index: relayctl/relayctl.c
===
RCS file: /cvs/src/usr.sbin/relayctl/relayctl.c,v
retrieving revision 1.58
diff -u -p -r1.58 relayctl.c
--- relayctl/relayctl.c 29 Nov 2017 15:24:50 -  1.58
+++ relayctl/relayctl.c 26 Oct 2020 17:03:55 -
@@ -47,6 +47,7 @@ intshow_session_msg(struct imsg *);
 int show_command_output(struct imsg *);
 char   *print_rdr_status(int);
 char   *print_host_status(int, int);
+char   *print_tls_status(int);
 char   *print_table_status(int, int);
 char   *print_relay_status(int);
 voidprint_statistics(struct ctl_stats[PROC_MAX_INSTANCES + 1]);
@@ -162,8 +163,8 @@ main(int argc, char *argv[])
case SHOW_RELAYS:
case SHOW_ROUTERS:
imsg_compose(ibuf, IMSG_CTL_SHOW_SUM, 0, 0, -1, NULL, 0);
-   printf("%-4s\t%-8s\t%-24s\t%-7s\tStatus\n",
-   "Id", "Type", "Name", "Avlblty");
+   printf("%-4s\t%-8s\t%-24s\t%-7s\t%s\t%s\n",
+   "Id", "Type", "Name", "Avlblty", "Status", "TLS");
break;
case SHOW_SESSIONS:
imsg_compose(ibuf, IMSG_CTL_SESSION, 0, 0, -1, NULL, 0);
@@ -365,9 +366,10 @@ show_summary_msg(struct imsg *imsg, int 
if (!(type == SHOW_SUM || type == SHOW_HOSTS))
break;
table = imsg->data;
-   printf("%-4u\t%-8s\t%-24s\t%-7s\t%s\n",
+   printf("%-4u\t%-8s\t%-24s\t%-7s\t%s\t%s\n",
table->conf.id, "table", table->conf.name, "",
-   print_table_status(table->up, table->conf.flags));
+   print_table_status(table->up, table->conf.flags),
+   print_tls_status(table->conf.flags));
break;
case IMSG_CTL_HOST:
if (!(type == SHOW_SUM || type == SHOW_HOSTS))
@@ -378,7 +380,7 @@ show_summary_msg(struct imsg *imsg, int 
host->conf.name, host->conf.parentid);
else
strlcpy(name, host->conf.name, sizeof(name));
-   printf("%-4u\t%-8s\t%-24s\t%-7s\t%s\n",
+   printf("%-4u\t%-8s\t%-24s\t%-7s\t%s\t\n",
host->conf.id, "host", name,
print_availability(host->check_cnt, host->up_cnt),
print_host_status(host->up, host->flags));
@@ -396,9 +398,10 @@ show_summary_msg(struct imsg *imsg, int 
if (!(type == SHOW_SUM || type == SHOW_RELAYS))
break;
rlay = imsg->data;
-   printf("%-4u\t%-8s\t%-24s\t%-7s\t%s\n",
+   printf("%-4u\t%-8s\t%-24s\t%-7s\t%s\t%s\n",
rlay->rl_conf.id, "relay", rlay->rl_conf.name, "",
-   print_relay_status(rlay->rl_conf.flags));
+   print_relay_status(rlay->rl_conf.flags),
+   print_tls_status(rlay->rl_conf.flags));
break;
case IMSG_CTL_RDR_STATS:
if (type != SHOW_RDRS)
@@ -543,6 +546,15 @@ print_host_status(int status, int fl)
default:
errx(1, "invalid status: %d", status);
}
+}
+
+char *
+print_tls_status(int flags)
+{
+   if (flags & F_TLSCLIENT)
+   return ("yes");
+   else
+   return ("no");
 }
 
 char *
Index: relayd/parse.y
===
RCS file: /cvs/src/usr.sbin/relayd/parse.y,v
retrieving revision 1.247
diff -u -p -r1.247 parse.y
--- relayd/parse.y  25 Oct 2020 10:17:49 -  1.247
+++ relayd/parse.y  26 Oct 2020 17:03:55 -
@@ -109,6 +109,7 @@ objid_t  last_nr_id = 0;
 
 static struct rdr  *rdr = NULL;
 static struct table*table = NULL;
+static struct relay_table *rlayt = NULL;
 static struct relay*rlay = NULL;
 static struct host *hst = NULL;
 struct relaylistrelays;
@@ -1953,6 +1954,16 @@ relayoptsl   : 

Re: httpd(8): fix location duplicate detection

2020-10-26 Thread Denis Fondras
On Mon, Oct 26, 2020 at 09:28:54AM +0100, m...@fn.de wrote:
> Ping. Latest diff below.
> 

OK denis@

I will commit tonight if nobody stands against.
Thank you.

> Index: usr.sbin/httpd/parse.y
> ===
> RCS file: /cvs/src/usr.sbin/httpd/parse.y,v
> retrieving revision 1.118
> diff -u -p -u -p -r1.118 parse.y
> --- usr.sbin/httpd/parse.y11 Oct 2020 03:21:44 -  1.118
> +++ usr.sbin/httpd/parse.y26 Oct 2020 08:26:48 -
> @@ -587,8 +587,10 @@ serveroptsl  : LISTEN ON STRING opttls po
>   struct server   *s = NULL;
>  
>   TAILQ_FOREACH(s, conf->sc_servers, srv_entry) {
> + /* Compare locations of same parent server */
>   if ((s->srv_conf.flags & SRVFLAG_LOCATION) &&
> - s->srv_conf.id == srv_conf->id &&
> + s->srv_conf.parent_id ==
> + srv_conf->parent_id &&
>   strcmp(s->srv_conf.location,
>   srv_conf->location) == 0)
>   break;
> 
> 
> On 2020-10-11 12:00, m...@fn.de wrote:
> > Ping. Updated diff below.
> > 
> > ---
> > Index: usr.sbin/httpd/parse.y
> > ===
> > RCS file: /cvs/src/usr.sbin/httpd/parse.y,v
> > retrieving revision 1.118
> > diff -u -p -u -p -r1.118 parse.y
> > --- usr.sbin/httpd/parse.y  11 Oct 2020 03:21:44 -  1.118
> > +++ usr.sbin/httpd/parse.y  11 Oct 2020 09:52:34 -
> > @@ -588,7 +588,8 @@ serveroptsl : LISTEN ON STRING opttls po
> >  
> > TAILQ_FOREACH(s, conf->sc_servers, srv_entry) {
> > if ((s->srv_conf.flags & SRVFLAG_LOCATION) &&
> > -   s->srv_conf.id == srv_conf->id &&
> > +   s->srv_conf.parent_id ==
> > +   srv_conf->parent_id &&
> > strcmp(s->srv_conf.location,
> > srv_conf->location) == 0)
> > break;
> > ---
> > 
> > On 2020-09-26 08:57, m...@fn.de wrote:
> >> During httpd setup I realized that duplicate location names are not
> >> being detected even though I remembered having seen a corresponding
> >> piece of code in 'usr.sbin/httpd/parse.y' the other day.  As far
> >> as I understand, the comparison 's->srv_conf.id == srv_conf->id'
> >> can never be true as a newly created location ID would never match
> >> the ID of any existing location.
> >>
> >> To check whether or not I was right, I recompiled httpd with DEBUG
> >> enabled and tried to start the server with the following (actually
> >> invalid) httpd.conf:
> >>
> >> 
> >> server "testserver" {
> >>  listen on 127.0.0.1 port www
> >>  location "/foo" { block }
> >>  location "/foo" { block }
> >> }
> >> 
> >>
> >> # httpd -vvd
> >> startup
> >> adding location "/foo" for "testserver[2]"
> >> adding location "/foo" for "testserver[3]"
> >> adding server "testserver[1]"
> >> 
> >> (httpd running)
> >>
> >> I guess the intention was to compare the new location name with all
> >> other location names available under the same parent server.  I
> >> accomplished this by applying the patch at the bottom of this
> >> message.  After recompiling, httpd startup terminates as expected.
> >>
> >> # httpd -vvd
> >> startup
> >> adding location "/foo" for "testserver[2]"
> >> /etc/httpd.conf:4: location "/foo" defined twice
> >> .
> >> logger exiting, pid 98967
> >> server exiting, pid 27723
> >> server exiting, pid 78507
> >> server exiting, pid 25743
> >>
> >>
> >> comments? OK?
> >>
> >> ---
> >>
> >> Index: usr.sbin/httpd/parse.y
> >> ===
> >> RCS file: /cvs/src/usr.sbin/httpd/parse.y,v
> >> retrieving revision 1.117
> >> diff -u -p -u -p -r1.117 parse.y
> >> --- usr.sbin/httpd/parse.y 26 Aug 2020 06:50:20 -  1.117
> >> +++ usr.sbin/httpd/parse.y 26 Sep 2020 06:03:52 -
> >> @@ -581,7 +581,8 @@ serveroptsl: LISTEN ON STRING opttls po
> >>  
> >>TAILQ_FOREACH(s, conf->sc_servers, srv_entry) {
> >>if ((s->srv_conf.flags & SRVFLAG_LOCATION) &&
> >> -  s->srv_conf.id == srv_conf->id &&
> >> +  s->srv_conf.parent_id ==
> >> +  srv_conf->parent_id &&
> >>strcmp(s->srv_conf.location,
> >>

Re: Port httpd(8) 'strip' directive to relayd(8)

2020-10-25 Thread Denis Fondras
Previous one had a typo... :/

On Sat, Oct 24, 2020 at 08:01:36PM +0200, Hiltjo Posthuma wrote:
> Thanks for working on this.  I haven't tested the patch yet except compiling,
> but this feature would be very nice to have imho.
> 
> I find the current "path replace" syntax confusing and it doesn't work for 
> this
> use-case.
> 
> Some comments below:
> 

Thank you for the comments Hiltjo.

Here is an updated diff :

Index: parse.y
===
RCS file: /cvs/src/usr.sbin/relayd/parse.y,v
retrieving revision 1.246
diff -u -p -r1.246 parse.y
--- parse.y 14 Sep 2020 11:30:25 -  1.246
+++ parse.y 25 Oct 2020 09:20:53 -
@@ -175,8 +175,8 @@ typedef struct {
 %token LOOKUP METHOD MODE NAT NO DESTINATION NODELAY NOTHING ON PARENT PATH
 %token PFTAG PORT PREFORK PRIORITY PROTO QUERYSTR REAL REDIRECT RELAY REMOVE
 %token REQUEST RESPONSE RETRY QUICK RETURN ROUNDROBIN ROUTE SACK SCRIPT SEND
-%token SESSION SNMP SOCKET SPLICE SSL STICKYADDR STYLE TABLE TAG TAGGED TCP
-%token TIMEOUT TLS TO ROUTER RTLABEL TRANSPARENT TRAP URL WITH TTL RTABLE
+%token SESSION SNMP SOCKET SPLICE SSL STICKYADDR STRIP STYLE TABLE TAG TAGGED
+%token TCP TIMEOUT TLS TO ROUTER RTLABEL TRANSPARENT TRAP URL WITH TTL RTABLE
 %token MATCH PARAMS RANDOM LEASTSTATES SRCHASH KEY CERTIFICATE PASSWORD ECDHE
 %token EDH TICKETS CONNECTION CONNECTIONS CONTEXT ERRORS STATE CHANGES CHECKS
 %token WEBSOCKETS
@@ -1569,6 +1569,20 @@ ruleopts : METHOD STRING 
{
rule->rule_kv[keytype].kv_option = $2;
rule->rule_kv[keytype].kv_type = keytype;
}
+   | PATH STRIP NUMBER {
+   char*strip = NULL;
+
+   if ($3 < 0 || $3 > INT_MAX) {
+   yyerror("invalid strip number");
+   YYERROR;
+   }
+   if (asprintf(, "%lld", $3) <= 0)
+   fatal("can't parse strip");
+   keytype = KEY_TYPE_PATH;
+   rule->rule_kv[keytype].kv_option = KEY_OPTION_STRIP;
+   rule->rule_kv[keytype].kv_value = strip;
+   rule->rule_kv[keytype].kv_type = keytype;
+   }
| QUERYSTR key_option STRING value  {
switch ($2) {
case KEY_OPTION_APPEND:
@@ -2506,6 +2520,7 @@ lookup(char *s)
{ "ssl",SSL },
{ "state",  STATE },
{ "sticky-address", STICKYADDR },
+   { "strip",  STRIP },
{ "style",  STYLE },
{ "table",  TABLE },
{ "tag",TAG },
Index: relay.c
===
RCS file: /cvs/src/usr.sbin/relayd/relay.c,v
retrieving revision 1.251
diff -u -p -r1.251 relay.c
--- relay.c 14 May 2020 17:27:38 -  1.251
+++ relay.c 25 Oct 2020 09:20:53 -
@@ -214,6 +214,9 @@ relay_ruledebug(struct relay_rule *rule)
case KEY_OPTION_LOG:
fprintf(stderr, "log ");
break;
+   case KEY_OPTION_STRIP:
+   fprintf(stderr, "strip ");
+   break;
case KEY_OPTION_NONE:
break;
}
@@ -227,13 +230,15 @@ relay_ruledebug(struct relay_rule *rule)
break;
}
 
+   int kvv = (kv->kv_option == KEY_OPTION_STRIP ||
+kv->kv_value == NULL);
fprintf(stderr, "%s%s%s%s%s%s ",
kv->kv_key == NULL ? "" : "\"",
kv->kv_key == NULL ? "" : kv->kv_key,
kv->kv_key == NULL ? "" : "\"",
-   kv->kv_value == NULL ? "" : " value \"",
+   kvv ? "" : " value \"",
kv->kv_value == NULL ? "" : kv->kv_value,
-   kv->kv_value == NULL ? "" : "\"");
+   kvv ? "" : "\"");
}
 
if (rule->rule_tablename[0])
Index: relay_http.c
===
RCS file: /cvs/src/usr.sbin/relayd/relay_http.c,v
retrieving revision 1.79
diff -u -p -r1.79 relay_http.c
--- relay_http.c4 Sep 2020 13:09:14 -   1.79
+++ relay_http.c25 Oct 2020 09:20:53 -
@@ -77,6 +77,7 @@ intrelay_match_actions(struct ctl_rel
struct relay_rule *, struct kvlist *, struct kvlist *,
struct relay_table **);
 voidrelay_httpdesc_free(struct http_descriptor *);
+char *  server_root_strip(char *, int);
 
 static struct relayd   *env = NULL;
 
@@ -1421,14 +1422,16 @@ 

Re: Port httpd(8) 'strip' directive to relayd(8)

2020-10-25 Thread Denis Fondras
On Sat, Oct 24, 2020 at 08:01:36PM +0200, Hiltjo Posthuma wrote:
> Thanks for working on this.  I haven't tested the patch yet except compiling,
> but this feature would be very nice to have imho.
> 
> I find the current "path replace" syntax confusing and it doesn't work for 
> this
> use-case.
> 
> Some comments below:
> 

Thank you for the comments Hiltjo.

Here is an updated diff :

Index: parse.y
===
RCS file: /cvs/src/usr.sbin/relayd/parse.y,v
retrieving revision 1.246
diff -u -p -r1.246 parse.y
--- parse.y 14 Sep 2020 11:30:25 -  1.246
+++ parse.y 25 Oct 2020 09:20:53 -
@@ -175,8 +175,8 @@ typedef struct {
 %token LOOKUP METHOD MODE NAT NO DESTINATION NODELAY NOTHING ON PARENT PATH
 %token PFTAG PORT PREFORK PRIORITY PROTO QUERYSTR REAL REDIRECT RELAY REMOVE
 %token REQUEST RESPONSE RETRY QUICK RETURN ROUNDROBIN ROUTE SACK SCRIPT SEND
-%token SESSION SNMP SOCKET SPLICE SSL STICKYADDR STYLE TABLE TAG TAGGED TCP
-%token TIMEOUT TLS TO ROUTER RTLABEL TRANSPARENT TRAP URL WITH TTL RTABLE
+%token SESSION SNMP SOCKET SPLICE SSL STICKYADDR STRIP STYLE TABLE TAG TAGGED
+%token TCP TIMEOUT TLS TO ROUTER RTLABEL TRANSPARENT TRAP URL WITH TTL RTABLE
 %token MATCH PARAMS RANDOM LEASTSTATES SRCHASH KEY CERTIFICATE PASSWORD ECDHE
 %token EDH TICKETS CONNECTION CONNECTIONS CONTEXT ERRORS STATE CHANGES CHECKS
 %token WEBSOCKETS
@@ -1569,6 +1569,20 @@ ruleopts : METHOD STRING 
{
rule->rule_kv[keytype].kv_option = $2;
rule->rule_kv[keytype].kv_type = keytype;
}
+   | PATH STRIP NUMBER {
+   char*strip = NULL;
+
+   if ($3 < 0 || $3 > INT_MAX) {
+   yyerror("invalid strip number");
+   YYERROR;
+   }
+   if (asprintf(, "%lld", $3) <= 1)
+   fatal("can't parse strip");
+   keytype = KEY_TYPE_PATH;
+   rule->rule_kv[keytype].kv_option = KEY_OPTION_STRIP;
+   rule->rule_kv[keytype].kv_value = strip;
+   rule->rule_kv[keytype].kv_type = keytype;
+   }
| QUERYSTR key_option STRING value  {
switch ($2) {
case KEY_OPTION_APPEND:
@@ -2506,6 +2520,7 @@ lookup(char *s)
{ "ssl",SSL },
{ "state",  STATE },
{ "sticky-address", STICKYADDR },
+   { "strip",  STRIP },
{ "style",  STYLE },
{ "table",  TABLE },
{ "tag",TAG },
Index: relay.c
===
RCS file: /cvs/src/usr.sbin/relayd/relay.c,v
retrieving revision 1.251
diff -u -p -r1.251 relay.c
--- relay.c 14 May 2020 17:27:38 -  1.251
+++ relay.c 25 Oct 2020 09:20:53 -
@@ -214,6 +214,9 @@ relay_ruledebug(struct relay_rule *rule)
case KEY_OPTION_LOG:
fprintf(stderr, "log ");
break;
+   case KEY_OPTION_STRIP:
+   fprintf(stderr, "strip ");
+   break;
case KEY_OPTION_NONE:
break;
}
@@ -227,13 +230,15 @@ relay_ruledebug(struct relay_rule *rule)
break;
}
 
+   int kvv = (kv->kv_option == KEY_OPTION_STRIP ||
+kv->kv_value == NULL);
fprintf(stderr, "%s%s%s%s%s%s ",
kv->kv_key == NULL ? "" : "\"",
kv->kv_key == NULL ? "" : kv->kv_key,
kv->kv_key == NULL ? "" : "\"",
-   kv->kv_value == NULL ? "" : " value \"",
+   kvv ? "" : " value \"",
kv->kv_value == NULL ? "" : kv->kv_value,
-   kv->kv_value == NULL ? "" : "\"");
+   kvv ? "" : "\"");
}
 
if (rule->rule_tablename[0])
Index: relay_http.c
===
RCS file: /cvs/src/usr.sbin/relayd/relay_http.c,v
retrieving revision 1.79
diff -u -p -r1.79 relay_http.c
--- relay_http.c4 Sep 2020 13:09:14 -   1.79
+++ relay_http.c25 Oct 2020 09:20:53 -
@@ -77,6 +77,7 @@ intrelay_match_actions(struct ctl_rel
struct relay_rule *, struct kvlist *, struct kvlist *,
struct relay_table **);
 voidrelay_httpdesc_free(struct http_descriptor *);
+char *  server_root_strip(char *, int);
 
 static struct relayd   *env = NULL;
 
@@ -1421,14 +1422,16 @@ relay_httppath_test(struct 

Port httpd(8) 'strip' directive to relayd(8)

2020-10-24 Thread Denis Fondras
The 'strip' directive from httpd(8) is useful when forwarding to another server.

This diff adds the feature to relayd(8).

With :

  match request path "/server/*" tag psonoserver
  match request tagged psonoserver path strip 1
  match request tagged psonoserver forward to 


https://psono.pw/server/info/ is forwarded as /info

Comments ? OK ?

Index: parse.y
===
RCS file: /cvs/src/usr.sbin/relayd/parse.y,v
retrieving revision 1.246
diff -u -p -r1.246 parse.y
--- parse.y 14 Sep 2020 11:30:25 -  1.246
+++ parse.y 24 Oct 2020 14:52:36 -
@@ -175,8 +175,8 @@ typedef struct {
 %token LOOKUP METHOD MODE NAT NO DESTINATION NODELAY NOTHING ON PARENT PATH
 %token PFTAG PORT PREFORK PRIORITY PROTO QUERYSTR REAL REDIRECT RELAY REMOVE
 %token REQUEST RESPONSE RETRY QUICK RETURN ROUNDROBIN ROUTE SACK SCRIPT SEND
-%token SESSION SNMP SOCKET SPLICE SSL STICKYADDR STYLE TABLE TAG TAGGED TCP
-%token TIMEOUT TLS TO ROUTER RTLABEL TRANSPARENT TRAP URL WITH TTL RTABLE
+%token SESSION SNMP SOCKET SPLICE SSL STICKYADDR STRIP STYLE TABLE TAG TAGGED
+%token TCP TIMEOUT TLS TO ROUTER RTLABEL TRANSPARENT TRAP URL WITH TTL RTABLE
 %token MATCH PARAMS RANDOM LEASTSTATES SRCHASH KEY CERTIFICATE PASSWORD ECDHE
 %token EDH TICKETS CONNECTION CONNECTIONS CONTEXT ERRORS STATE CHANGES CHECKS
 %token WEBSOCKETS
@@ -1569,6 +1569,23 @@ ruleopts : METHOD STRING 
{
rule->rule_kv[keytype].kv_option = $2;
rule->rule_kv[keytype].kv_type = keytype;
}
+   | PATH STRIP NUMBER {
+   char*strip = NULL;
+
+   if ($3 < 0 || $3 > INT_MAX) {
+   yyerror("invalid strip number");
+   YYERROR;
+   }
+   if ((strip = calloc(11, sizeof(char))) == NULL) {
+   yyerror("calloc() failed");
+   YYERROR;
+   }
+   sprintf(strip, "%lld", $3);
+   keytype = KEY_TYPE_PATH;
+   rule->rule_kv[keytype].kv_option = KEY_OPTION_STRIP;
+   rule->rule_kv[keytype].kv_value = strip;
+   rule->rule_kv[keytype].kv_type = keytype;
+   }
| QUERYSTR key_option STRING value  {
switch ($2) {
case KEY_OPTION_APPEND:
@@ -2506,6 +2523,7 @@ lookup(char *s)
{ "ssl",SSL },
{ "state",  STATE },
{ "sticky-address", STICKYADDR },
+   { "strip",  STRIP },
{ "style",  STYLE },
{ "table",  TABLE },
{ "tag",TAG },
Index: relay.c
===
RCS file: /cvs/src/usr.sbin/relayd/relay.c,v
retrieving revision 1.251
diff -u -p -r1.251 relay.c
--- relay.c 14 May 2020 17:27:38 -  1.251
+++ relay.c 24 Oct 2020 14:52:36 -
@@ -214,6 +214,9 @@ relay_ruledebug(struct relay_rule *rule)
case KEY_OPTION_LOG:
fprintf(stderr, "log ");
break;
+   case KEY_OPTION_STRIP:
+   fprintf(stderr, "strip ");
+   break;
case KEY_OPTION_NONE:
break;
}
@@ -227,13 +230,15 @@ relay_ruledebug(struct relay_rule *rule)
break;
}
 
+   int kvv = (kv->kv_option == KEY_OPTION_STRIP ||
+kv->kv_value == NULL);
fprintf(stderr, "%s%s%s%s%s%s ",
kv->kv_key == NULL ? "" : "\"",
kv->kv_key == NULL ? "" : kv->kv_key,
kv->kv_key == NULL ? "" : "\"",
-   kv->kv_value == NULL ? "" : " value \"",
+   kvv ? "" : " value \"",
kv->kv_value == NULL ? "" : kv->kv_value,
-   kv->kv_value == NULL ? "" : "\"");
+   kvv ? "" : "\"");
}
 
if (rule->rule_tablename[0])
Index: relay_http.c
===
RCS file: /cvs/src/usr.sbin/relayd/relay_http.c,v
retrieving revision 1.79
diff -u -p -r1.79 relay_http.c
--- relay_http.c4 Sep 2020 13:09:14 -   1.79
+++ relay_http.c24 Oct 2020 14:52:36 -
@@ -77,6 +77,7 @@ intrelay_match_actions(struct ctl_rel
struct relay_rule *, struct kvlist *, struct kvlist *,
struct relay_table **);
 voidrelay_httpdesc_free(struct http_descriptor *);
+char *  server_root_strip(char *, int);
 
 

Re: net.inet.ip.forwarding=0 vs lo(4)

2020-10-18 Thread Denis Fondras
On Sun, Oct 18, 2020 at 02:04:31PM +1000, David Gwynne wrote:
> or is there a way i can do this without a diff already?
>

I am also curious...

> thoughts?
> 

The diff works as advertise.



Diff to allow selection of source IP address

2020-10-13 Thread Denis Fondras
Is anyone interested in this ?

This diff allows to select the default source IP address (for TCP/UDP
connections) on multi-homed & "multi-addressed" machines.

Looking for feedbacks on what I broke.
Do not test with ping(8) as it uses another source address selection codepath.
`curl ifconfig.co` is a good candidate to check if source is set correctly.

Example usage :
Set 2001:db8::1 as source : route source 2001:db8::1
Unset previously set IPv6 address on rdomain 10 : route -T10 source -inet6 
default
Show set address : route source

Comments ? OK ?

Denis

Index: sbin/route/keywords.h
===
RCS file: /cvs/src/sbin/route/keywords.h,v
retrieving revision 1.34
diff -u -p -r1.34 keywords.h
--- sbin/route/keywords.h   10 Aug 2017 13:44:48 -  1.34
+++ sbin/route/keywords.h   17 Sep 2020 09:59:25 -
@@ -1,4 +1,4 @@
-/* $OpenBSD: keywords.h,v 1.34 2017/08/10 13:44:48 benno Exp $ */
+/* $OpenBSD$ */
 
 /* WARNING!  This file was generated by keywords.sh  */
 
@@ -66,6 +66,7 @@ enum {
K_SA,
K_SENDPIPE,
K_SHOW,
+   K_SOURCE,
K_SSTHRESH,
K_STATIC,
K_SWAP,
@@ -129,6 +130,7 @@ struct keytab keywords[] = {
{ "sa", K_SA },
{ "sendpipe",   K_SENDPIPE },
{ "show",   K_SHOW },
+   { "source", K_SOURCE },
{ "ssthresh",   K_SSTHRESH },
{ "static", K_STATIC },
{ "swap",   K_SWAP },
Index: sbin/route/keywords.sh
===
RCS file: /cvs/src/sbin/route/keywords.sh,v
retrieving revision 1.32
diff -u -p -r1.32 keywords.sh
--- sbin/route/keywords.sh  10 Aug 2017 13:44:48 -  1.32
+++ sbin/route/keywords.sh  17 Sep 2020 09:59:25 -
@@ -67,6 +67,7 @@ rttvar
 sa
 sendpipe
 show
+source
 ssthresh
 static
 swap
Index: sbin/route/route.8
===
RCS file: /cvs/src/sbin/route/route.8,v
retrieving revision 1.91
diff -u -p -r1.91 route.8
--- sbin/route/route.8  19 Jan 2020 18:22:31 -  1.91
+++ sbin/route/route.8  17 Sep 2020 09:59:25 -
@@ -195,6 +195,17 @@ or
 .Cm bgp .
 If the priority is negative, then routes that do not match the numeric
 priority are shown.
+.It Xo
+.Nm route
+.Op Fl T Ar rtable
+.Tg
+.Cm source
+.Ar address
+.Xc
+Set the preferred source address.  If
+.Ar address
+is the word "default", 0.0.0.0 or ::, source address will be chosen by
+the kernel for the matching address family.
 .El
 .Pp
 .Tg destination
Index: sbin/route/route.c
===
RCS file: /cvs/src/sbin/route/route.c,v
retrieving revision 1.248
diff -u -p -r1.248 route.c
--- sbin/route/route.c  7 Jul 2020 14:53:36 -   1.248
+++ sbin/route/route.c  17 Sep 2020 09:59:25 -
@@ -68,7 +68,8 @@
 const struct if_status_description
if_status_descriptions[] = LINK_STATE_DESCRIPTIONS;
 
-union sockunion so_dst, so_gate, so_mask, so_ifa, so_ifp, so_src, so_label;
+union sockunion so_dst, so_gate, so_mask, so_ifa, so_ifp, so_src, so_label,
+so_source;
 
 typedef union sockunion *sup;
 pid_t  pid;
@@ -85,6 +86,7 @@ struct rt_metrics rt_metrics;
 
 int flushroutes(int, char **);
 int newroute(int, char **);
+int setsource(int, char **);
 int show(int, char *[]);
 int keycmp(const void *, const void *);
 int keyword(char *);
@@ -132,7 +134,8 @@ usage(char *cp)
"usage: %s [-dnqtv] [-T rtable] command [[modifiers] args]\n",
__progname);
fprintf(stderr,
-   "commands: add, change, delete, exec, flush, get, monitor, show\n");
+   "commands: add, change, delete, exec, flush, get, monitor, show, "
+   "source\n");
exit(1);
 }
 
@@ -258,6 +261,10 @@ main(int argc, char **argv)
case K_FLUSH:
exit(flushroutes(argc, argv));
break;
+   case K_SOURCE:
+   nflag = 1;
+   exit(setsource(argc, argv));
+   break;
}
 
if (pledge("stdio dns", NULL) == -1)
@@ -450,6 +457,52 @@ set_metric(char *value, int key)
locking = 0;
 }
 
+
+int
+setsource(int argc, char **argv)
+{
+   char *cmd, *srcaddr = "";
+   int af = AF_UNSPEC, ret = 0;
+   struct hostent *hp = NULL;
+   int key;
+
+   if (uid)
+   errx(1, "must be root to alter source address");
+   cmd = argv[0];
+   while (--argc > 0) {
+   if (**(++argv)== '-') {
+   switch (key = keyword(1 + *argv)) {
+   case K_INET:
+   af = AF_INET;
+   aflen = sizeof(struct sockaddr_in);
+   break;
+   case K_INET6:
+   af = AF_INET6;
+   aflen = sizeof(struct 

Re: /etc/daily: use find -delete

2020-10-08 Thread Denis Fondras
On Thu, Oct 08, 2020 at 05:32:15AM -0600, Todd C. Miller wrote:
> We can use find's built-in -delete primary to remove old /tmp files
> and directories.  This is somewhat less error-prone than execing
> rm or rmdir.
> 

OK denis@

>  - todd
> 
> Index: etc/daily
> ===
> RCS file: /cvs/src/etc/daily,v
> retrieving revision 1.93
> diff -u -p -u -r1.93 daily
> --- etc/daily 9 Sep 2019 20:02:26 -   1.93
> +++ etc/daily 22 Aug 2020 01:21:16 -
> @@ -50,17 +50,17 @@ if [ -d /tmp -a ! -L /tmp ]; then
>   find -x . \
>   \( -path './ssh-*' -o -path ./.X11-unix -o -path ./.ICE-unix \
>   -o -path './tmux-*' \) \
> - -prune -o -type f -atime +7 -execdir rm -f -- {} \; 2>/dev/null
> + -prune -o -type f -atime +7 -delete 2>/dev/null
>   find -x . -type d -mtime +1 ! -path ./vi.recover ! -path ./.X11-unix \
>   ! -path ./.ICE-unix ! -name . \
> - -execdir rmdir -- {} \; >/dev/null 2>&1; }
> + -delete >/dev/null 2>&1; }
>  fi
>  
>  # Additional junk directory cleanup would go like this:
>  #if [ -d /scratch -a ! -L /scratch ]; then
>  #cd /scratch && {
> -#find . ! -name . -atime +1 -execdir rm -f -- {} \;
> -#find . ! -name . -type d -mtime +1 -execdir rmdir -- {} \; \
> +#find . ! -name . -atime +1 -delete
> +#find . ! -name . -type d -mtime +1 -delete \
>  #>/dev/null 2>&1; }
>  #fi
>  
> 



Re: ifconfig: consistent display of P2P link

2020-10-07 Thread Denis Fondras
On Wed, Oct 07, 2020 at 01:01:29PM +0200, Claudio Jeker wrote:
> On Wed, Oct 07, 2020 at 12:27:04PM +0200, Denis Fondras wrote:
> > All tunnels & point-to-point addresses are separated by "->" but inet.
> > 
> > Before :
> > gre0: flags=8051 mtu 1476
> > index 6 priority 0 llprio 6
> > encap: vnetid none txprio payload rxprio packet
> > groups: gre
> > tunnel: inet 192.0.2.1 -> 198.51.100.1 ttl 64 nodf ecn
> > inet 172.16.0.1 --> 172.16.0.2 netmask 0x
> > inet6 fe80::c23f:d5ff:fe63:ffe3%gre0 ->  prefixlen 64 scopeid 0x6
> > inet6 2001:db8::1 -> 2001:db8::2 prefixlen 128
> > 
> > After :
> > gre0: flags=8051 mtu 1476
> > index 6 priority 0 llprio 6
> > encap: vnetid none txprio payload rxprio packet
> > groups: gre
> > tunnel: inet 192.0.2.1 -> 198.51.100.1 ttl 64 nodf ecn
> > inet 172.16.0.1 -> 172.16.0.2 netmask 0x
> > inet6 fe80::c23f:d5ff:fe63:ffe3%gre0 ->  prefixlen 64 scopeid 0x6
> > inet6 2001:db8::1 -> 2001:db8::2 prefixlen 128
> > 
> > OK ?
> 
> Isn't it the other way around, that originally --> was used but then IPv6
> came and introduced -> which was copied around?
> 
> I like --> a bit better since it stands a bit more out.
> 

I am totally fine with going for "-->"


Index: ifconfig.c
===
RCS file: /cvs/src/sbin/ifconfig/ifconfig.c,v
retrieving revision 1.426
diff -u -p -r1.426 ifconfig.c
--- ifconfig.c  15 Sep 2020 15:23:11 -  1.426
+++ ifconfig.c  7 Oct 2020 11:54:12 -
@@ -3219,7 +3219,7 @@ print_tunnel(const struct if_laddrreq *r
0, 0, niflag) != 0)
strlcpy(pdstaddr, "", sizeof(pdstaddr));
 
-   printf(" -> %s", pdstaddr);
+   printf(" --> %s", pdstaddr);
 
switch (req->dstaddr.ss_family) {
case AF_INET:
@@ -3635,7 +3635,7 @@ in6_alias(struct in6_ifreq *creq)
if (getnameinfo((struct sockaddr *)sin6, sin6->sin6_len,
hbuf, sizeof(hbuf), NULL, 0, niflag) != 0)
strlcpy(hbuf, "", sizeof hbuf);
-   printf(" -> %s", hbuf);
+   printf(" --> %s", hbuf);
}
 
(void) memset(, 0, sizeof(ifr6));



ifconfig: consistent display of P2P link

2020-10-07 Thread Denis Fondras
All tunnels & point-to-point addresses are separated by "->" but inet.

Before :
gre0: flags=8051 mtu 1476
index 6 priority 0 llprio 6
encap: vnetid none txprio payload rxprio packet
groups: gre
tunnel: inet 192.0.2.1 -> 198.51.100.1 ttl 64 nodf ecn
inet 172.16.0.1 --> 172.16.0.2 netmask 0x
inet6 fe80::c23f:d5ff:fe63:ffe3%gre0 ->  prefixlen 64 scopeid 0x6
inet6 2001:db8::1 -> 2001:db8::2 prefixlen 128

After :
gre0: flags=8051 mtu 1476
index 6 priority 0 llprio 6
encap: vnetid none txprio payload rxprio packet
groups: gre
tunnel: inet 192.0.2.1 -> 198.51.100.1 ttl 64 nodf ecn
inet 172.16.0.1 -> 172.16.0.2 netmask 0x
inet6 fe80::c23f:d5ff:fe63:ffe3%gre0 ->  prefixlen 64 scopeid 0x6
inet6 2001:db8::1 -> 2001:db8::2 prefixlen 128

OK ?

Denis

Index: ifconfig.c
===
RCS file: /cvs/src/sbin/ifconfig/ifconfig.c,v
retrieving revision 1.426
diff -u -p -r1.426 ifconfig.c
--- ifconfig.c  15 Sep 2020 15:23:11 -  1.426
+++ ifconfig.c  17 Sep 2020 14:41:34 -
@@ -3552,7 +3552,7 @@ in_status(int force)
}
(void) strlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
sin = (struct sockaddr_in *)_dstaddr;
-   printf(" --> %s", inet_ntoa(sin->sin_addr));
+   printf(" -> %s", inet_ntoa(sin->sin_addr));
}
printf(" netmask 0x%x", ntohl(netmask.sin_addr.s_addr));
if (flags & IFF_BROADCAST) {



Re: fix: ospf6d(8): wrong intra area announcement

2020-10-03 Thread Denis Fondras
On Fri, Oct 02, 2020 at 02:01:09AM +0200, Jan Klemkow wrote:
> Hi,
> 
> The new intra area db entry has to be saved into the tree before
> orig_intra_area_prefix_lsas() is called.  If not, the ospf6d will not
> announce the new intra area db for a newly learned link from another
> ospf router of the broadcast domain.
> 
> This bug is triggered, if you add new addresses an ospf interface while
> the ospf6d is already running as a backup designated router.  The
> opposite designated ospf6d will get your new link announcement and
> return an old intra area db without the new address.
> 
> Beside of the fix, the diff removes redundant code.  I made the same
> diff for the ospfd to keep code in sync and remove redundant code there,
> too.  ospfd does not have the bug explained above, as far as I know.
> 
> Both regression tests passes with this diff.
> 
> OK?
> 

OK denis@ for ospf6d (it reverses a change a made).

> Bye,
> Jan
> 
> Index: ospf6d/rde_lsdb.c
> ===
> RCS file: /cvs//src/usr.sbin/ospf6d/rde_lsdb.c,v
> retrieving revision 1.45
> diff -u -p -r1.45 rde_lsdb.c
> --- ospf6d/rde_lsdb.c 21 Aug 2020 10:17:35 -  1.45
> +++ ospf6d/rde_lsdb.c 1 Oct 2020 23:09:38 -
> @@ -467,6 +467,7 @@ lsa_add(struct rde_nbr *nbr, struct lsa 
>   struct lsa_tree *tree;
>   struct vertex   *new, *old;
>   struct timeval   tv, now, res;
> + int update = 1;
>  
>   if (LSA_IS_SCOPE_AS(ntohs(lsa->hdr.type)))
>   tree = _tree;
> @@ -495,16 +496,13 @@ lsa_add(struct rde_nbr *nbr, struct lsa 
>   fatal("lsa_add");
>   return (1);
>   }
> - if (!lsa_equal(new->lsa, old->lsa)) {
> - if (ntohs(lsa->hdr.type) == LSA_TYPE_LINK)
> - orig_intra_area_prefix_lsas(nbr->area);
> - if (ntohs(lsa->hdr.type) != LSA_TYPE_EXTERNAL)
> - nbr->area->dirty = 1;
> - start_spf_timer();
> - }
> + if (lsa_equal(new->lsa, old->lsa))
> + update = 0;
>   vertex_free(old);
>   RB_INSERT(lsa_tree, tree, new);
> - } else {
> + }
> +
> + if (update) {
>   if (ntohs(lsa->hdr.type) == LSA_TYPE_LINK)
>   orig_intra_area_prefix_lsas(nbr->area);
>   if (ntohs(lsa->hdr.type) != LSA_TYPE_EXTERNAL)
> Index: ospfd/rde_lsdb.c
> ===
> RCS file: /cvs//src/usr.sbin/ospfd/rde_lsdb.c,v
> retrieving revision 1.50
> diff -u -p -r1.50 rde_lsdb.c
> --- ospfd/rde_lsdb.c  22 Nov 2015 13:09:10 -  1.50
> +++ ospfd/rde_lsdb.c  1 Oct 2020 23:06:57 -
> @@ -383,6 +383,7 @@ lsa_add(struct rde_nbr *nbr, struct lsa 
>   struct lsa_tree *tree;
>   struct vertex   *new, *old;
>   struct timeval   tv, now, res;
> + int update = 1;
>  
>   if (lsa->hdr.type == LSA_TYPE_EXTERNAL ||
>   lsa->hdr.type == LSA_TYPE_AS_OPAQ)
> @@ -410,15 +411,13 @@ lsa_add(struct rde_nbr *nbr, struct lsa 
>   fatal("lsa_add");
>   return (1);
>   }
> - if (!lsa_equal(new->lsa, old->lsa)) {
> - if (lsa->hdr.type != LSA_TYPE_EXTERNAL &&
> - lsa->hdr.type != LSA_TYPE_AS_OPAQ)
> - nbr->area->dirty = 1;
> - start_spf_timer();
> - }
> + if (lsa_equal(new->lsa, old->lsa))
> + update = 0;
>   vertex_free(old);
>   RB_INSERT(lsa_tree, tree, new);
> - } else {
> + }
> +
> + if (update) {
>   if (lsa->hdr.type != LSA_TYPE_EXTERNAL &&
>   lsa->hdr.type != LSA_TYPE_AS_OPAQ)
>   nbr->area->dirty = 1;
> 



[diff] Allow preferred source IP selection

2020-10-01 Thread Denis Fondras
This updated diff unbreak P2P links where local address was not the same as
preferred source address.

Sending to tech@ may help get more feedback on what I broke.

Example usage :
Set 2001:db8::1 as source : route source 2001:db8::1
Unset previously set IPv6 address on rdomain 10 : route -T10 source -inet6 
default
Show set address : route source

Comments ? OK ?

Denis

Index: sbin/route/keywords.h
===
RCS file: /cvs/src/sbin/route/keywords.h,v
retrieving revision 1.34
diff -u -p -r1.34 keywords.h
--- sbin/route/keywords.h   10 Aug 2017 13:44:48 -  1.34
+++ sbin/route/keywords.h   17 Sep 2020 09:59:25 -
@@ -1,4 +1,4 @@
-/* $OpenBSD: keywords.h,v 1.34 2017/08/10 13:44:48 benno Exp $ */
+/* $OpenBSD$ */
 
 /* WARNING!  This file was generated by keywords.sh  */
 
@@ -66,6 +66,7 @@ enum {
K_SA,
K_SENDPIPE,
K_SHOW,
+   K_SOURCE,
K_SSTHRESH,
K_STATIC,
K_SWAP,
@@ -129,6 +130,7 @@ struct keytab keywords[] = {
{ "sa", K_SA },
{ "sendpipe",   K_SENDPIPE },
{ "show",   K_SHOW },
+   { "source", K_SOURCE },
{ "ssthresh",   K_SSTHRESH },
{ "static", K_STATIC },
{ "swap",   K_SWAP },
Index: sbin/route/keywords.sh
===
RCS file: /cvs/src/sbin/route/keywords.sh,v
retrieving revision 1.32
diff -u -p -r1.32 keywords.sh
--- sbin/route/keywords.sh  10 Aug 2017 13:44:48 -  1.32
+++ sbin/route/keywords.sh  17 Sep 2020 09:59:25 -
@@ -67,6 +67,7 @@ rttvar
 sa
 sendpipe
 show
+source
 ssthresh
 static
 swap
Index: sbin/route/route.8
===
RCS file: /cvs/src/sbin/route/route.8,v
retrieving revision 1.91
diff -u -p -r1.91 route.8
--- sbin/route/route.8  19 Jan 2020 18:22:31 -  1.91
+++ sbin/route/route.8  17 Sep 2020 09:59:25 -
@@ -195,6 +195,17 @@ or
 .Cm bgp .
 If the priority is negative, then routes that do not match the numeric
 priority are shown.
+.It Xo
+.Nm route
+.Op Fl T Ar rtable
+.Tg
+.Cm source
+.Ar address
+.Xc
+Set the preferred source address.  If
+.Ar address
+is the word "default", 0.0.0.0 or ::, source address will be chosen by
+the kernel for the matching address family.
 .El
 .Pp
 .Tg destination
Index: sbin/route/route.c
===
RCS file: /cvs/src/sbin/route/route.c,v
retrieving revision 1.248
diff -u -p -r1.248 route.c
--- sbin/route/route.c  7 Jul 2020 14:53:36 -   1.248
+++ sbin/route/route.c  17 Sep 2020 09:59:25 -
@@ -68,7 +68,8 @@
 const struct if_status_description
if_status_descriptions[] = LINK_STATE_DESCRIPTIONS;
 
-union sockunion so_dst, so_gate, so_mask, so_ifa, so_ifp, so_src, so_label;
+union sockunion so_dst, so_gate, so_mask, so_ifa, so_ifp, so_src, so_label,
+so_source;
 
 typedef union sockunion *sup;
 pid_t  pid;
@@ -85,6 +86,7 @@ struct rt_metrics rt_metrics;
 
 int flushroutes(int, char **);
 int newroute(int, char **);
+int setsource(int, char **);
 int show(int, char *[]);
 int keycmp(const void *, const void *);
 int keyword(char *);
@@ -132,7 +134,8 @@ usage(char *cp)
"usage: %s [-dnqtv] [-T rtable] command [[modifiers] args]\n",
__progname);
fprintf(stderr,
-   "commands: add, change, delete, exec, flush, get, monitor, show\n");
+   "commands: add, change, delete, exec, flush, get, monitor, show, "
+   "source\n");
exit(1);
 }
 
@@ -258,6 +261,10 @@ main(int argc, char **argv)
case K_FLUSH:
exit(flushroutes(argc, argv));
break;
+   case K_SOURCE:
+   nflag = 1;
+   exit(setsource(argc, argv));
+   break;
}
 
if (pledge("stdio dns", NULL) == -1)
@@ -450,6 +457,52 @@ set_metric(char *value, int key)
locking = 0;
 }
 
+
+int
+setsource(int argc, char **argv)
+{
+   char *cmd, *srcaddr = "";
+   int af = AF_UNSPEC, ret = 0;
+   struct hostent *hp = NULL;
+   int key;
+
+   if (uid)
+   errx(1, "must be root to alter source address");
+   cmd = argv[0];
+   while (--argc > 0) {
+   if (**(++argv)== '-') {
+   switch (key = keyword(1 + *argv)) {
+   case K_INET:
+   af = AF_INET;
+   aflen = sizeof(struct sockaddr_in);
+   break;
+   case K_INET6:
+   af = AF_INET6;
+   aflen = sizeof(struct sockaddr_in6);
+   break;
+   }
+   } else if ((rtm_addrs & RTA_IFA) == 0) {
+   srcaddr = *argv;
+

ifconfig: consistent display of P2P link

2020-10-01 Thread Denis Fondras
All tunnels & point-to-point addresses are separated by "->" but inet.

Denis

Index: ifconfig.c
===
RCS file: /cvs/src/sbin/ifconfig/ifconfig.c,v
retrieving revision 1.426
diff -u -p -r1.426 ifconfig.c
--- ifconfig.c  15 Sep 2020 15:23:11 -  1.426
+++ ifconfig.c  17 Sep 2020 14:41:34 -
@@ -3552,7 +3552,7 @@ in_status(int force)
}
(void) strlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
sin = (struct sockaddr_in *)_dstaddr;
-   printf(" --> %s", inet_ntoa(sin->sin_addr));
+   printf(" -> %s", inet_ntoa(sin->sin_addr));
}
printf(" netmask 0x%x", ntohl(netmask.sin_addr.s_addr));
if (flags & IFF_BROADCAST) {



ifconfig: consistent display of P2P link

2020-09-17 Thread Denis Fondras
All tunnels & point-to-point addresses are separated by "->" but inet.

Denis

Index: ifconfig.c
===
RCS file: /cvs/src/sbin/ifconfig/ifconfig.c,v
retrieving revision 1.426
diff -u -p -r1.426 ifconfig.c
--- ifconfig.c  15 Sep 2020 15:23:11 -  1.426
+++ ifconfig.c  17 Sep 2020 14:41:34 -
@@ -3552,7 +3552,7 @@ in_status(int force)
}
(void) strlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
sin = (struct sockaddr_in *)_dstaddr;
-   printf(" --> %s", inet_ntoa(sin->sin_addr));
+   printf(" -> %s", inet_ntoa(sin->sin_addr));
}
printf(" netmask 0x%x", ntohl(netmask.sin_addr.s_addr));
if (flags & IFF_BROADCAST) {



[diff] Allow preferred source IP selection

2020-09-17 Thread Denis Fondras
This updated diff unbreak P2P links where local address was not the same as
preferred source address.

Sending to tech@ may help get more feedback on what I broke.

Example usage :
Set 2001:db8::1 as source : route source 2001:db8::1
Unset previously set IPv6 address on rdomain 10 : route -T10 source -inet6 
default
Show set address : route source

Denis

Index: sbin/route/keywords.h
===
RCS file: /cvs/src/sbin/route/keywords.h,v
retrieving revision 1.34
diff -u -p -r1.34 keywords.h
--- sbin/route/keywords.h   10 Aug 2017 13:44:48 -  1.34
+++ sbin/route/keywords.h   17 Sep 2020 09:59:25 -
@@ -1,4 +1,4 @@
-/* $OpenBSD: keywords.h,v 1.34 2017/08/10 13:44:48 benno Exp $ */
+/* $OpenBSD$ */
 
 /* WARNING!  This file was generated by keywords.sh  */
 
@@ -66,6 +66,7 @@ enum {
K_SA,
K_SENDPIPE,
K_SHOW,
+   K_SOURCE,
K_SSTHRESH,
K_STATIC,
K_SWAP,
@@ -129,6 +130,7 @@ struct keytab keywords[] = {
{ "sa", K_SA },
{ "sendpipe",   K_SENDPIPE },
{ "show",   K_SHOW },
+   { "source", K_SOURCE },
{ "ssthresh",   K_SSTHRESH },
{ "static", K_STATIC },
{ "swap",   K_SWAP },
Index: sbin/route/keywords.sh
===
RCS file: /cvs/src/sbin/route/keywords.sh,v
retrieving revision 1.32
diff -u -p -r1.32 keywords.sh
--- sbin/route/keywords.sh  10 Aug 2017 13:44:48 -  1.32
+++ sbin/route/keywords.sh  17 Sep 2020 09:59:25 -
@@ -67,6 +67,7 @@ rttvar
 sa
 sendpipe
 show
+source
 ssthresh
 static
 swap
Index: sbin/route/route.8
===
RCS file: /cvs/src/sbin/route/route.8,v
retrieving revision 1.91
diff -u -p -r1.91 route.8
--- sbin/route/route.8  19 Jan 2020 18:22:31 -  1.91
+++ sbin/route/route.8  17 Sep 2020 09:59:25 -
@@ -195,6 +195,17 @@ or
 .Cm bgp .
 If the priority is negative, then routes that do not match the numeric
 priority are shown.
+.It Xo
+.Nm route
+.Op Fl T Ar rtable
+.Tg
+.Cm source
+.Ar address
+.Xc
+Set the preferred source address.  If
+.Ar address
+is the word "default", 0.0.0.0 or ::, source address will be chosen by
+the kernel for the matching address family.
 .El
 .Pp
 .Tg destination
Index: sbin/route/route.c
===
RCS file: /cvs/src/sbin/route/route.c,v
retrieving revision 1.248
diff -u -p -r1.248 route.c
--- sbin/route/route.c  7 Jul 2020 14:53:36 -   1.248
+++ sbin/route/route.c  17 Sep 2020 09:59:25 -
@@ -68,7 +68,8 @@
 const struct if_status_description
if_status_descriptions[] = LINK_STATE_DESCRIPTIONS;
 
-union sockunion so_dst, so_gate, so_mask, so_ifa, so_ifp, so_src, so_label;
+union sockunion so_dst, so_gate, so_mask, so_ifa, so_ifp, so_src, so_label,
+so_source;
 
 typedef union sockunion *sup;
 pid_t  pid;
@@ -85,6 +86,7 @@ struct rt_metrics rt_metrics;
 
 int flushroutes(int, char **);
 int newroute(int, char **);
+int setsource(int, char **);
 int show(int, char *[]);
 int keycmp(const void *, const void *);
 int keyword(char *);
@@ -132,7 +134,8 @@ usage(char *cp)
"usage: %s [-dnqtv] [-T rtable] command [[modifiers] args]\n",
__progname);
fprintf(stderr,
-   "commands: add, change, delete, exec, flush, get, monitor, show\n");
+   "commands: add, change, delete, exec, flush, get, monitor, show, "
+   "source\n");
exit(1);
 }
 
@@ -258,6 +261,10 @@ main(int argc, char **argv)
case K_FLUSH:
exit(flushroutes(argc, argv));
break;
+   case K_SOURCE:
+   nflag = 1;
+   exit(setsource(argc, argv));
+   break;
}
 
if (pledge("stdio dns", NULL) == -1)
@@ -450,6 +457,52 @@ set_metric(char *value, int key)
locking = 0;
 }
 
+
+int
+setsource(int argc, char **argv)
+{
+   char *cmd, *srcaddr = "";
+   int af = AF_UNSPEC, ret = 0;
+   struct hostent *hp = NULL;
+   int key;
+
+   if (uid)
+   errx(1, "must be root to alter source address");
+   cmd = argv[0];
+   while (--argc > 0) {
+   if (**(++argv)== '-') {
+   switch (key = keyword(1 + *argv)) {
+   case K_INET:
+   af = AF_INET;
+   aflen = sizeof(struct sockaddr_in);
+   break;
+   case K_INET6:
+   af = AF_INET6;
+   aflen = sizeof(struct sockaddr_in6);
+   break;
+   }
+   } else if ((rtm_addrs & RTA_IFA) == 0) {
+   srcaddr = *argv;
+   

route.8, remove unprinted text

2020-09-10 Thread Denis Fondras
I can't see where these two lines are printed.


Index: route.8
===
RCS file: /cvs/src/sbin/route/route.8,v
retrieving revision 1.91
diff -u -p -r1.91 route.8
--- route.8 19 Jan 2020 18:22:31 -  1.91
+++ route.8 10 Sep 2020 20:06:52 -
@@ -197,8 +197,6 @@ If the priority is negative, then routes
 priority are shown.
 .El
 .Pp
-.Tg destination
-.Tg gateway
 The other commands relating to adding, changing, or deleting routes
 have the syntax:
 .Pp



Re: snmpd refactor listen on grammar

2020-09-10 Thread Denis Fondras
On Wed, Sep 09, 2020 at 07:45:32AM +0200, Martijn van Duren wrote:
> On Tue, 2020-09-08 at 19:33 +0200, Denis Fondras wrote:
> > On Sun, Sep 06, 2020 at 10:11:02PM +0200, Martijn van Duren wrote:
> > > Moving towards individual transport mappings, it's becoming more 
> > > convenient to have the protocol directly after the listen on statement.
> > > This gives me more flexibility in using mapping-specific APIs, also
> > > when other transport mappings might become available in the future it
> > > allows for easier mapping-specific features.
> > > 
> > > While here I decided to also add port support for snmpe, which at this
> > > point is rather trivial. Traphandler is not my point of focus at this
> > > time.
> > > 
> > > having udp|tcp at the last position is still supported, but generates a
> > > pretty deprecated warning. Probably to be removed after release.
> > > 
> > > OK?
> > > 
> > 
> > OK denis@
> > 
> > Can you check that port > 0 ? Because it prints "snmpd.conf:7: invalid
> > address: ::1" which is not correct (though using 0 or -1 for port is a weird
> > idea).
> > 
> > > martijn@
> > > 
> Sure
> 

Thanks Martijn.

OK denis@

> Index: parse.y
> ===
> RCS file: /cvs/src/usr.sbin/snmpd/parse.y,v
> retrieving revision 1.60
> diff -u -p -r1.60 parse.y
> --- parse.y   6 Sep 2020 15:51:28 -   1.60
> +++ parse.y   9 Sep 2020 05:45:10 -
> @@ -40,9 +40,11 @@
>  #include 
>  #include 
>  #include 
> +#include 
>  #include 
>  #include 
>  #include 
> +#include 
>  #include 
>  #include 
>  #include 
> @@ -92,6 +94,7 @@ char*symget(const char *);
>  struct snmpd *conf = NULL;
>  static interrors = 0;
>  static struct usmuser*user = NULL;
> +static char  *snmpd_port = SNMPD_PORT;
>  
>  int   host(const char *, const char *, int,
>   struct sockaddr_storage *, int);
> @@ -122,11 +125,11 @@ typedef struct {
>  %token   SYSTEM CONTACT DESCR LOCATION NAME OBJECTID SERVICES RTFILTER
>  %token   READONLY READWRITE OCTETSTRING INTEGER COMMUNITY TRAP RECEIVER
>  %token   SECLEVEL NONE AUTH ENC USER AUTHKEY ENCKEY ERROR DISABLED
> -%token   HANDLE DEFAULT SRCADDR TCP UDP PFADDRFILTER
> +%token   HANDLE DEFAULT SRCADDR TCP UDP PFADDRFILTER PORT
>  %token STRING
>  %token NUMBER
>  %type  hostcmn
> -%type  srcaddr
> +%type  srcaddr port
>  %type  optwrite yesno seclevel proto
>  %typeobjtype cmd
>  %type oid hostoid trapoid
> @@ -193,28 +196,7 @@ yesno:  STRING   {
>   }
>   ;
>  
> -main : LISTEN ON STRING proto{
> - struct sockaddr_storage ss[16];
> - int nhosts, i;
> -
> - nhosts = host($3, SNMPD_PORT, $4, ss, nitems(ss));
> - if (nhosts < 1) {
> - yyerror("invalid address: %s", $3);
> - free($3);
> - YYERROR;
> - }
> - if (nhosts > (int)nitems(ss))
> - log_warn("%s resolves to more than %zu hosts",
> - $3, nitems(ss));
> - free($3);
> -
> - for (i = 0; i < nhosts; i++) {
> - if (listen_add(&(ss[i]), $4) == -1) {
> - yyerror("calloc");
> - YYERROR;
> - }
> - }
> - }
> +main : LISTEN ON listenproto
>   | READONLY COMMUNITY STRING {
>   if (strlcpy(conf->sc_rdcommunity, $3,
>   sizeof(conf->sc_rdcommunity)) >=
> @@ -295,6 +277,132 @@ main: LISTEN ON STRING proto{
>   }
>   ;
>  
> +listenproto  : UDP listen_udp
> + | TCP listen_tcp
> + | listen_empty
> +
> +listen_udp   : STRING port   {
> + struct sockaddr_storage ss[16];
> + int nhosts, i;
> +
> + nhosts = host($1, $2, SOCK_DGRAM, ss, nitems(ss));
> + if (nhosts < 1) {
> +  

Re: snmpd refactor listen on grammar

2020-09-08 Thread Denis Fondras
On Sun, Sep 06, 2020 at 10:11:02PM +0200, Martijn van Duren wrote:
> Moving towards individual transport mappings, it's becoming more 
> convenient to have the protocol directly after the listen on statement.
> This gives me more flexibility in using mapping-specific APIs, also
> when other transport mappings might become available in the future it
> allows for easier mapping-specific features.
> 
> While here I decided to also add port support for snmpe, which at this
> point is rather trivial. Traphandler is not my point of focus at this
> time.
> 
> having udp|tcp at the last position is still supported, but generates a
> pretty deprecated warning. Probably to be removed after release.
> 
> OK?
> 

OK denis@

Can you check that port > 0 ? Because it prints "snmpd.conf:7: invalid
address: ::1" which is not correct (though using 0 or -1 for port is a weird
idea).

> martijn@
> 
> Index: parse.y
> ===
> RCS file: /cvs/src/usr.sbin/snmpd/parse.y,v
> retrieving revision 1.60
> diff -u -p -r1.60 parse.y
> --- parse.y   6 Sep 2020 15:51:28 -   1.60
> +++ parse.y   6 Sep 2020 20:08:08 -
> @@ -40,6 +40,7 @@
>  #include 
>  #include 
>  #include 
> +#include 
>  #include 
>  #include 
>  #include 
> @@ -92,6 +93,7 @@ char*symget(const char *);
>  struct snmpd *conf = NULL;
>  static interrors = 0;
>  static struct usmuser*user = NULL;
> +static char  *snmpd_port = SNMPD_PORT;
>  
>  int   host(const char *, const char *, int,
>   struct sockaddr_storage *, int);
> @@ -122,11 +124,11 @@ typedef struct {
>  %token   SYSTEM CONTACT DESCR LOCATION NAME OBJECTID SERVICES RTFILTER
>  %token   READONLY READWRITE OCTETSTRING INTEGER COMMUNITY TRAP RECEIVER
>  %token   SECLEVEL NONE AUTH ENC USER AUTHKEY ENCKEY ERROR DISABLED
> -%token   HANDLE DEFAULT SRCADDR TCP UDP PFADDRFILTER
> +%token   HANDLE DEFAULT SRCADDR TCP UDP PFADDRFILTER PORT
>  %token STRING
>  %token NUMBER
>  %type  hostcmn
> -%type  srcaddr
> +%type  srcaddr port
>  %type  optwrite yesno seclevel proto
>  %typeobjtype cmd
>  %type oid hostoid trapoid
> @@ -193,28 +195,7 @@ yesno:  STRING   {
>   }
>   ;
>  
> -main : LISTEN ON STRING proto{
> - struct sockaddr_storage ss[16];
> - int nhosts, i;
> -
> - nhosts = host($3, SNMPD_PORT, $4, ss, nitems(ss));
> - if (nhosts < 1) {
> - yyerror("invalid address: %s", $3);
> - free($3);
> - YYERROR;
> - }
> - if (nhosts > (int)nitems(ss))
> - log_warn("%s resolves to more than %zu hosts",
> - $3, nitems(ss));
> - free($3);
> -
> - for (i = 0; i < nhosts; i++) {
> - if (listen_add(&(ss[i]), $4) == -1) {
> - yyerror("calloc");
> - YYERROR;
> - }
> - }
> - }
> +main : LISTEN ON listenproto
>   | READONLY COMMUNITY STRING {
>   if (strlcpy(conf->sc_rdcommunity, $3,
>   sizeof(conf->sc_rdcommunity)) >=
> @@ -295,6 +276,128 @@ main: LISTEN ON STRING proto{
>   }
>   ;
>  
> +listenproto  : UDP listen_udp
> + | TCP listen_tcp
> + | listen_empty
> +
> +listen_udp   : STRING port   {
> + struct sockaddr_storage ss[16];
> + int nhosts, i;
> +
> + nhosts = host($1, $2, SOCK_DGRAM, ss, nitems(ss));
> + if (nhosts < 1) {
> + yyerror("invalid address: %s", $1);
> + free($1);
> + if ($2 != snmpd_port)
> + free($2);
> + YYERROR;
> + }
> + if (nhosts > (int)nitems(ss))
> + log_warn("%s:%s resolves to more than %zu 
> hosts",
> + $1, $2, nitems(ss));
> +
> + free($1);
> + if ($2 != snmpd_port)
> + free($2);
> + for (i = 0; i < nhosts; i++) {
> + if (listen_add(&(ss[i]), SOCK_DGRAM) == -1) {
> + yyerror("calloc");
> + YYERROR;
> +   

Re: snmpd remove snmpe_dispatch_parent

2020-09-06 Thread Denis Fondras
On Sun, Sep 06, 2020 at 06:37:17PM +0200, Martijn van Duren wrote:
> going for another easy picking: snmpe_dispatch_parent is just an empty
> stub. proc.c assigns proc_dispatch_null to p_cb if it's null, which 
> effectively does the same thing.
> 
> OK?
> 

OK denis@

> martijn@
> 
> Index: snmpe.c
> ===
> RCS file: /cvs/src/usr.sbin/snmpd/snmpe.c,v
> retrieving revision 1.66
> diff -u -p -r1.66 snmpe.c
> --- snmpe.c   6 Sep 2020 15:51:28 -   1.66
> +++ snmpe.c   6 Sep 2020 16:37:10 -
> @@ -46,7 +46,6 @@ void snmpe_tryparse(int, struct snmp_me
>  int   snmpe_parsevarbinds(struct snmp_message *);
>  void  snmpe_response(struct snmp_message *);
>  void  snmpe_sig_handler(int sig, short, void *);
> -int   snmpe_dispatch_parent(int, struct privsep_proc *, struct imsg *);
>  int   snmpe_bind(struct address *);
>  void  snmpe_recvmsg(int fd, short, void *);
>  void  snmpe_readcb(int fd, short, void *);
> @@ -60,7 +59,7 @@ struct imsgev   *iev_parent;
>  static const struct timeval  snmpe_tcp_timeout = { 10, 0 }; /* 10s */
>  
>  static struct privsep_proc procs[] = {
> - { "parent", PROC_PARENT,snmpe_dispatch_parent }
> + { "parent", PROC_PARENT }
>  };
>  
>  void
> @@ -133,17 +132,6 @@ snmpe_shutdown(void)
>   close(h->fd);
>   }
>   kr_shutdown();
> -}
> -
> -int
> -snmpe_dispatch_parent(int fd, struct privsep_proc *p, struct imsg *imsg)
> -{
> - switch (imsg->hdr.type) {
> - default:
> - break;
> - }
> -
> - return (-1);
>  }
>  
>  int
> 



Re: Refine IPv6 source address selection

2020-08-24 Thread Denis Fondras
On Mon, Aug 24, 2020 at 06:42:02PM +0200, Florian Obser wrote:
> To clarify, this is independent of my recent work in
> in6_ifawithscope(), -ifa did not work with the old code, either.
> 

Of course ! Sorry if my message led to think you were responsible for it.



Refine IPv6 source address selection

2020-08-24 Thread Denis Fondras
While working on source selection, I noticed the IPv6 source was not honored
when set from route(8) with -ifa.

After discussing with florian@, here is a proposed change. It chooses the source
address associated with the route (hence honoring -ifa) instead of the first
address of the output interface which becomes the source address of last
resort.

Index: netinet6/in6_src.c
===
RCS file: /cvs/src/sys/netinet6/in6_src.c,v
retrieving revision 1.81
diff -u -p -r1.81 in6_src.c
--- netinet6/in6_src.c  2 Dec 2016 11:16:04 -   1.81
+++ netinet6/in6_src.c  24 Aug 2020 15:14:53 -
@@ -207,13 +207,14 @@ in6_pcbselsrc(struct in6_addr **in6src, 
 */
 
if (ro->ro_rt) {
-   ifp = if_get(ro->ro_rt->rt_ifidx);
-   if (ifp != NULL) {
-   ia6 = in6_ifawithscope(ifp, dst, rtableid);
-   if_put(ifp);
+   ia6 = ifatoia6(ro->ro_rt->rt_ifa);
+   if (ia6 == NULL) {
+   ifp = if_get(ro->ro_rt->rt_ifidx);
+   if (ifp != NULL) {
+   ia6 = in6_ifawithscope(ifp, dst, rtableid);
+   if_put(ifp);
+   }
}
-   if (ia6 == NULL) /* xxx scope error ?*/
-   ia6 = ifatoia6(ro->ro_rt->rt_ifa);
}
if (ia6 == NULL)
return (EHOSTUNREACH);  /* no route */



Re: empty rc.firsttime when installing

2020-07-14 Thread Denis Fondras
On Tue, Jul 14, 2020 at 02:14:55PM +0100, Stuart Henderson wrote:
> On 2020/07/14 15:03, Denis Fondras wrote:
> > I was upgrading an EdgeRouter and it restarted multiple times instead of 
> > booting
> > /bsd
> > 
> > When I had a chance to boot it correctly, I noticed that sysmerge and 
> > fw_update
> > were run multiple times.
> > 
> > This diff avoids filling rc.firsttime and rc.sysmerge.
> 
> hmm, that will cause problems for some things I do (the main one being:
> sysupgrade -n, add a pkg_add -u line to rc.firsttime, reboot).
> 

Thank you all for raising the problem.



empty rc.firsttime when installing

2020-07-14 Thread Denis Fondras
I was upgrading an EdgeRouter and it restarted multiple times instead of booting
/bsd

When I had a chance to boot it correctly, I noticed that sysmerge and fw_update
were run multiple times.

This diff avoids filling rc.firsttime and rc.sysmerge.


Index: distrib/miniroot/install.sub
===
RCS file: /cvs/src/distrib/miniroot/install.sub,v
retrieving revision 1.1154
diff -u -p -r1.1154 install.sub
--- distrib/miniroot/install.sub26 May 2020 16:21:00 -  1.1154
+++ distrib/miniroot/install.sub14 Jul 2020 12:54:27 -
@@ -2734,6 +2734,9 @@ finish_up() {
local _kernel_dir=/mnt/usr/share/relink/kernel
local _kernel=${MDKERNEL:-GENERIC} _syspatch_archs="amd64 arm64 i386"
 
+   # Empty rc.firsttime
+   echo "" >/mnt/etc/rc.firsttime
+
# Mount all known swap partitions.  This gives systems with little
# memory a better chance at running 'MAKEDEV all'.
if [[ -x /mnt/sbin/swapctl ]]; then
@@ -2812,7 +2815,7 @@ finish_up() {
 
# Ensure that sysmerge in batch mode is run on reboot.
[[ $MODE == upgrade ]] &&
-   echo "/usr/sbin/sysmerge -b" >>/mnt/etc/rc.sysmerge
+   echo "/usr/sbin/sysmerge -b" >/mnt/etc/rc.sysmerge
 
# If a proxy was needed to fetch the sets, use it for fw_update and 
syspatch
[[ -n $http_proxy ]] &&



Re: 11n Tx aggregation for iwm(4)

2020-06-27 Thread Denis Fondras
On Fri, Jun 26, 2020 at 02:45:53PM +0200, Stefan Sperling wrote:
> This patch adds support for 11n Tx aggregation to iwm(4).

iwm0 at pci2 dev 0 function 0 "Intel Dual Band Wireless AC 7260" rev
0x73, msi

AP is Zyxel USG40W

Before :
bandwidth min/avg/max/std-dev = 9.800/14.000/14.214/0.606 Mbps

After :
bandwidth min/avg/max/std-dev = 8.124/47.270/57.076/8.906 Mbps



update vxlan(4) man

2020-06-26 Thread Denis Fondras
vxlan(4) actually supports IPv6 tunnel endpoints.
Only multicast endpoints are unsupported.

Index: vxlan.4
===
RCS file: /cvs/src/share/man/man4/vxlan.4,v
retrieving revision 1.8
diff -u -p -r1.8 vxlan.4
--- vxlan.4 22 Nov 2018 17:31:11 -  1.8
+++ vxlan.4 26 Jun 2020 11:52:32 -
@@ -176,4 +176,5 @@ decreased MTU of 1450 bytes.
 In any other case, it is commonly recommended to set the MTU of the
 transport interfaces to at least 1600 bytes.
 .Pp
-The implementation does not support IPv6 tunnel endpoints at present.
+The implementation does not support IPv6 multicast tunnel endpoints at
+present.



Re: Some redundant code lines in sys

2020-06-05 Thread Denis Fondras
On Fri, Jun 05, 2020 at 12:56:21PM +0200, Prof. Dr. Steffen Wendzel wrote:
> Dear all:
> 
> just in case this appears useful to you: I found some redundant code
> lines in the following files.
> 
> sys/net/pipex.h:
>struct pipex_session  *pipex_pppoe_lookup_session (struct mbuf *);
>struct pipex_session  *pipex_pppoe_lookup_session (struct mbuf *);
> 
> usr.sbin/relayd/agentx.c
>snmp_agentx_oid(pdu, oid) == -1 ||
>snmp_agentx_oid(pdu, oid) == -1 ||
> 
> usr.sbin/snmpd/agentx.c:
>  snmp_agentx_oid(pdu, oid) == -1 ||
>  snmp_agentx_oid(pdu, oid) == -1 ||
> 
> usr.sbin/bgpd/rde.h:
>   void path_init(u_int32_t);
>   void path_init(u_int32_t);
> 
> lib/libcurses/nc_tparm.h:
> #define TPARM_1(a,b) TPARM_2(a,b,0)
> #define TPARM_1(a,b) TPARM_2(a,b,0)
> 

Nice catch, thank you.


Index: lib/libcurses/nc_tparm.h
===
RCS file: /cvs/src/lib/libcurses/nc_tparm.h,v
retrieving revision 1.1
diff -u -p -r1.1 nc_tparm.h
--- lib/libcurses/nc_tparm.h12 Jan 2010 23:21:59 -  1.1
+++ lib/libcurses/nc_tparm.h5 Jun 2020 11:45:41 -
@@ -62,6 +62,5 @@
 #define TPARM_3(a,b,c,d) TPARM_4(a,b,c,d,0)
 #define TPARM_2(a,b,c) TPARM_3(a,b,c,0)
 #define TPARM_1(a,b) TPARM_2(a,b,0)
-#define TPARM_1(a,b) TPARM_2(a,b,0)
 #define TPARM_0(a) TPARM_1(a,0)
 #endif
Index: sys/net/pipex.h
===
RCS file: /cvs/src/sys/net/pipex.h,v
retrieving revision 1.22
diff -u -p -r1.22 pipex.h
--- sys/net/pipex.h 26 May 2020 07:06:37 -  1.22
+++ sys/net/pipex.h 5 Jun 2020 11:45:44 -
@@ -206,7 +206,6 @@ int   pipex_notify_close
 
 struct mbuf   *pipex_output (struct mbuf *, int, int, struct 
pipex_iface_context *);
 struct pipex_session  *pipex_pppoe_lookup_session (struct mbuf *);
-struct pipex_session  *pipex_pppoe_lookup_session (struct mbuf *);
 struct mbuf   *pipex_pppoe_input (struct mbuf *, struct pipex_session 
*);
 struct pipex_session  *pipex_pptp_lookup_session (struct mbuf *);
 struct mbuf   *pipex_pptp_input (struct mbuf *, struct pipex_session 
*);
Index: usr.sbin/bgpd/rde.h
===
RCS file: /cvs/src/usr.sbin/bgpd/rde.h,v
retrieving revision 1.233
diff -u -p -r1.233 rde.h
--- usr.sbin/bgpd/rde.h 24 Jan 2020 05:44:05 -  1.233
+++ usr.sbin/bgpd/rde.h 5 Jun 2020 11:45:45 -
@@ -557,7 +557,6 @@ re_rib(struct rib_entry *re)
 }
 
 voidpath_init(u_int32_t);
-voidpath_init(u_int32_t);
 voidpath_shutdown(void);
 voidpath_hash_stats(struct rde_hashstats *);
 int path_compare(struct rde_aspath *, struct rde_aspath *);
Index: usr.sbin/relayd/agentx.c
===
RCS file: /cvs/src/usr.sbin/relayd/agentx.c,v
retrieving revision 1.14
diff -u -p -r1.14 agentx.c
--- usr.sbin/relayd/agentx.c28 May 2017 10:39:15 -  1.14
+++ usr.sbin/relayd/agentx.c5 Jun 2020 11:45:45 -
@@ -654,7 +654,6 @@ snmp_agentx_unregister_pdu(struct snmp_o
 
if (snmp_agentx_raw(pdu, , sizeof(uhdr)) == -1 ||
snmp_agentx_oid(pdu, oid) == -1 ||
-   snmp_agentx_oid(pdu, oid) == -1 ||
(range_index && snmp_agentx_int(pdu, _bound) == -1)) {
snmp_agentx_pdu_free(pdu);
return (NULL);
Index: usr.sbin/snmpd/agentx.c
===
RCS file: /cvs/src/usr.sbin/snmpd/agentx.c,v
retrieving revision 1.13
diff -u -p -r1.13 agentx.c
--- usr.sbin/snmpd/agentx.c 17 Jun 2018 18:19:59 -  1.13
+++ usr.sbin/snmpd/agentx.c 5 Jun 2020 11:45:45 -
@@ -658,7 +658,6 @@ snmp_agentx_unregister_pdu(struct snmp_o
 
if (snmp_agentx_raw(pdu, , sizeof(uhdr)) == -1 ||
snmp_agentx_oid(pdu, oid) == -1 ||
-   snmp_agentx_oid(pdu, oid) == -1 ||
(range_index && snmp_agentx_int(pdu, _bound) == -1)) {
snmp_agentx_pdu_free(pdu);
return (NULL);



ospf6d: enable reload

2020-05-30 Thread Denis Fondras
This diff provides a working 'ospf6ctl reload'.

Must be applied after https://marc.info/?l=openbsd-tech=159084971620177=2

Index: ospf6ctl/ospf6ctl.c
===
RCS file: /home/denis/dev/cvs/src/usr.sbin/ospf6ctl/ospf6ctl.c,v
retrieving revision 1.51
diff -u -p -r1.51 ospf6ctl.c
--- ospf6ctl/ospf6ctl.c 5 Apr 2020 18:19:04 -   1.51
+++ ospf6ctl/ospf6ctl.c 30 May 2020 18:02:41 -
@@ -235,14 +235,10 @@ main(int argc, char *argv[])
done = 1;
break;
case RELOAD:
-#ifdef notyet
imsg_compose(ibuf, IMSG_CTL_RELOAD, 0, 0, -1, NULL, 0);
printf("reload request sent.\n");
done = 1;
break;
-#else
-   errx(1, "reload not supported");
-#endif
}
 
while (ibuf->w.queued)
Index: ospf6d/ospf6d.c
===
RCS file: /home/denis/dev/cvs/src/usr.sbin/ospf6d/ospf6d.c,v
retrieving revision 1.47
diff -u -p -r1.47 ospf6d.c
--- ospf6d/ospf6d.c 30 May 2020 18:02:13 -  1.47
+++ ospf6d/ospf6d.c 30 May 2020 18:02:41 -
@@ -277,6 +277,8 @@ main(int argc, char *argv[])
fatalx("control socket setup failed");
main_imsg_compose_ospfe_fd(IMSG_CONTROLFD, 0, control_fd);
 
+   if (unveil("/", "r") == -1)
+   fatal("unveil");
if (unveil(ospfd_conf->csock, "c") == -1)
fatal("unveil");
if (unveil(NULL, NULL) == -1)
@@ -611,23 +613,37 @@ ospf_redistribute(struct kroute *kr, u_i
 int
 ospf_reload(void)
 {
-#ifdef notyet
struct area *area;
+   struct iface*iface;
struct ospfd_conf   *xconf;
 
if ((xconf = parse_config(conffile, ospfd_conf->opts)) == NULL)
return (-1);
 
-   /* XXX bail out if router-id changed */
+   /* No router-id was specified, keep existing value */
+   if (xconf->rtr_id.s_addr == 0)
+   xconf->rtr_id.s_addr = ospfd_conf->rtr_id.s_addr;
+
+   /* Abort the reload if rtr_id changed */
+   if (ospfd_conf->rtr_id.s_addr != xconf->rtr_id.s_addr) {
+   log_warnx("router-id changed: restart required");
+   return (-1);
+   }
 
/* send config to childs */
if (ospf_sendboth(IMSG_RECONF_CONF, xconf, sizeof(*xconf)) == -1)
return (-1);
 
-   /* send areas, interfaces happen out of band */
+   /* send areas & interfaces */
LIST_FOREACH(area, >area_list, entry) {
if (ospf_sendboth(IMSG_RECONF_AREA, area, sizeof(*area)) == -1)
return (-1);
+
+   LIST_FOREACH(iface, >iface_list, entry) {
+   if (ospf_sendboth(IMSG_RECONF_IFACE, iface,
+   sizeof(*iface)) == -1)
+   return (-1);
+   }
}
 
if (ospf_sendboth(IMSG_RECONF_END, NULL, 0) == -1)
@@ -639,9 +655,6 @@ ospf_reload(void)
/* update redistribute lists */
kr_reload(ospfd_conf->redist_label_or_prefix);
return (0);
-#else
-   return (-1);
-#endif
 }
 
 int
@@ -725,6 +738,22 @@ merge_config(struct ospfd_conf *conf, st
 * stub is not yet used but switching between stub and normal
 * will be another painful job.
 */
+   if (a->stub != xa->stub && ospfd_process == PROC_OSPF_ENGINE)
+   a->dirty = 1; /* force rtr LSA update */
+#if 0
+   if (xa->stub && ospfd_process == PROC_RDE_ENGINE) {
+   while ((r = SIMPLEQ_FIRST(>redist_list)) != NULL) {
+   SIMPLEQ_REMOVE_HEAD(>redist_list, entry);
+   free(r);
+   }
+
+   while ((r = SIMPLEQ_FIRST(>redist_list)) != NULL) {
+   SIMPLEQ_REMOVE_HEAD(>redist_list, entry);
+   SIMPLEQ_INSERT_TAIL(>redist_list, r, entry);
+   }
+   }
+#endif
+
a->stub = xa->stub;
a->stub_default_cost = xa->stub_default_cost;
if (ospfd_process == PROC_RDE_ENGINE)
@@ -746,7 +775,15 @@ merge_config(struct ospfd_conf *conf, st
}
if (a->dirty) {
a->dirty = 0;
-   orig_rtr_lsa(LIST_FIRST(>iface_list)->area);
+   orig_rtr_lsa(a);
+   }
+   }
+   }
+   if (ospfd_process == PROC_RDE_ENGINE) {
+   LIST_FOREACH(a, >area_list, entry) {
+   if (a->dirty) {
+   start_spf_timer();
+   break;
}
}
}
@@ -767,7 +804,7 @@ merge_interfaces(struct area *a, struct 

ospf6d: change the way interfaces are handled

2020-05-30 Thread Denis Fondras
This diff updates how ospf6d(8) handles interfaces.
It is now in line with what ospfd(8) does.

Last step before enabling reload.

Tested against Mikrotik and Zebra implementations.

Warning: it changes the default behaviour. No prefix is announced if no
"redistribute" statement is present in config file. Is this a showstopper ?

Index: hello.c
===
RCS file: /cvs/src/usr.sbin/ospf6d/hello.c,v
retrieving revision 1.22
diff -u -p -r1.22 hello.c
--- hello.c 3 Jan 2020 17:25:48 -   1.22
+++ hello.c 30 May 2020 14:19:09 -
@@ -175,12 +175,16 @@ recv_hello(struct iface *iface, struct i
nbr->priority = LSA_24_GETHI(ntohl(hello.opts));
/* XXX neighbor address shouldn't be stored on virtual links */
nbr->addr = *src;
+   ospfe_imsg_compose_rde(IMSG_NEIGHBOR_ADDR, nbr->peerid, 0,
+   src, sizeof(struct in6_addr));
}
 
if (!IN6_ARE_ADDR_EQUAL(>addr, src)) {
log_warnx("%s: neighbor ID %s changed its address to %s",
__func__, inet_ntoa(nbr->id), log_in6addr(src));
nbr->addr = *src;
+   ospfe_imsg_compose_rde(IMSG_NEIGHBOR_ADDR, nbr->peerid, 0,
+   src, sizeof(struct in6_addr));
}
 
nbr->options = opts;
Index: interface.c
===
RCS file: /cvs/src/usr.sbin/ospf6d/interface.c,v
retrieving revision 1.29
diff -u -p -r1.29 interface.c
--- interface.c 27 May 2020 09:03:56 -  1.29
+++ interface.c 30 May 2020 14:19:09 -
@@ -72,8 +72,6 @@ struct {
 static int vlink_cnt = 0;
 #endif
 
-TAILQ_HEAD(, iface)iflist;
-
 const char * const if_event_names[] = {
"NOTHING",
"UP",
@@ -145,10 +143,6 @@ if_fsm(struct iface *iface, enum iface_e
area_track(iface->area);
orig_rtr_lsa(iface->area);
orig_link_lsa(iface);
-
-   /* state change inform RDE */
-   ospfe_imsg_compose_rde(IMSG_IFINFO, iface->self->peerid, 0,
-   >state, sizeof(iface->state));
}
 
if (old_state & (IF_STA_MULTI | IF_STA_POINTTOPOINT) &&
@@ -166,41 +160,8 @@ if_fsm(struct iface *iface, enum iface_e
return (ret);
 }
 
-int
-if_init(void)
-{
-   TAILQ_INIT();
-
-   return (fetchifs(0));
-}
-
-/* XXX using a linked list should be OK for now */
 struct iface *
-if_find(unsigned int ifindex)
-{
-   struct iface*iface;
-
-   TAILQ_FOREACH(iface, , list) {
-   if (ifindex == iface->ifindex)
-   return (iface);
-   }
-   return (NULL);
-}
-
-struct iface *
-if_findname(char *name)
-{
-   struct iface*iface;
-
-   TAILQ_FOREACH(iface, , list) {
-   if (!strcmp(name, iface->name))
-   return (iface);
-   }
-   return (NULL);
-}
-
-struct iface *
-if_new(u_short ifindex, char *ifname)
+if_new(struct kif *kif, struct kif_addr *ka)
 {
struct iface*iface;
 
@@ -210,7 +171,6 @@ if_new(u_short ifindex, char *ifname)
iface->state = IF_STA_DOWN;
 
LIST_INIT(>nbr_list);
-   TAILQ_INIT(>ifa_list);
TAILQ_INIT(>ls_ack_list);
RB_INIT(>lsa_tree);
 
@@ -225,34 +185,36 @@ if_new(u_short ifindex, char *ifname)
return (iface);
}
 #endif
-   strlcpy(iface->name, ifname, sizeof(iface->name));
-   iface->ifindex = ifindex;
-
-   TAILQ_INSERT_TAIL(, iface, list);
-
-   return (iface);
-}
 
-void
-if_update(struct iface *iface, int mtu, int flags, u_int8_t type,
-u_int8_t state, u_int64_t rate, u_int32_t rdomain)
-{
-   iface->mtu = mtu;
-   iface->flags = flags;
-   iface->if_type = type;
-   iface->linkstate = state;
-   iface->baudrate = rate;
-   iface->rdomain = rdomain;
+   strlcpy(iface->name, kif->ifname, sizeof(iface->name));
 
-   /* set type */
-   if (flags & IFF_POINTOPOINT)
+   /* get type */
+   if (kif->flags & IFF_POINTOPOINT)
iface->type = IF_TYPE_POINTOPOINT;
-   if (flags & IFF_BROADCAST && flags & IFF_MULTICAST)
+   if (kif->flags & IFF_BROADCAST && kif->flags & IFF_MULTICAST)
iface->type = IF_TYPE_BROADCAST;
-   if (flags & IFF_LOOPBACK) {
+   if (kif->flags & IFF_LOOPBACK) {
iface->type = IF_TYPE_POINTOPOINT;
-   iface->cflags |= F_IFACE_PASSIVE;
+   iface->passive = 1;
}
+
+   /* get mtu, index and flags */
+   iface->mtu = kif->mtu;
+   iface->ifindex = kif->ifindex;
+   iface->rdomain = kif->rdomain;
+   iface->flags = kif->flags;
+   iface->linkstate = kif->link_state;
+   iface->if_type = kif->if_type;
+   iface->baudrate = kif->baudrate;
+
+   /* set address, mask and p2p addr */
+   iface->addr = ka->addr;
+   

Re: snmp(1) cleanup snmpd legacy

2020-05-19 Thread Denis Fondras
On Mon, May 18, 2020 at 12:18:47PM +0200, Martijn van Duren wrote:
> Anyone feeling like trimming a little fat?
> 

OK denis@

> On Fri, 2020-05-08 at 11:41 +0200, Martijn van Duren wrote:
> > Diff below removes fields from struct oid used by snmpd but not useful
> > for snmp(1). Minus 503LoC and -200kb on installed binary.
> > No functional change intended.
> > 
> > OK?
> > 
> > martijn@
> > 
> > Index: mib.c
> > ===
> > RCS file: /cvs/src/usr.bin/snmp/mib.c,v
> > retrieving revision 1.1
> > diff -u -p -r1.1 mib.c
> > --- mib.c   9 Aug 2019 06:17:59 -   1.1
> > +++ mib.c   8 May 2020 09:40:59 -
> > @@ -27,466 +27,9 @@
> >  #include "smi.h"
> >  
> >  static struct oid mib_tree[] = MIB_TREE;
> > -static struct oid base_mib[] = {
> > -   { MIB(mib_2),   OID_MIB },
> > -   { MIB(sysDescr),OID_RD },
> > -   { MIB(sysOID),  OID_RD },
> > -   { MIB(sysUpTime),   OID_RD },
> > -   { MIB(sysContact),  OID_RW },
> > -   { MIB(sysName), OID_RW },
> > -   { MIB(sysLocation), OID_RW },
> > -   { MIB(sysServices), OID_RS },
> > -   { MIB(sysORLastChange), OID_RD },
> > -   { MIB(sysORIndex),  OID_TRD },
> > -   { MIB(sysORID), OID_TRD },
> > -   { MIB(sysORDescr),  OID_TRD },
> > -   { MIB(sysORUpTime), OID_TRD },
> > -   { MIB(snmp),OID_MIB },
> > -   { MIB(snmpInPkts),  OID_RD },
> > -   { MIB(snmpOutPkts), OID_RD },
> > -   { MIB(snmpInBadVersions),   OID_RD },
> > -   { MIB(snmpInBadCommunityNames), OID_RD },
> > -   { MIB(snmpInBadCommunityUses),  OID_RD },
> > -   { MIB(snmpInASNParseErrs),  OID_RD },
> > -   { MIB(snmpInTooBigs),   OID_RD },
> > -   { MIB(snmpInNoSuchNames),   OID_RD },
> > -   { MIB(snmpInBadValues), OID_RD },
> > -   { MIB(snmpInReadOnlys), OID_RD },
> > -   { MIB(snmpInGenErrs),   OID_RD },
> > -   { MIB(snmpInTotalReqVars),  OID_RD },
> > -   { MIB(snmpInTotalSetVars),  OID_RD },
> > -   { MIB(snmpInGetRequests),   OID_RD },
> > -   { MIB(snmpInGetNexts),  OID_RD },
> > -   { MIB(snmpInSetRequests),   OID_RD },
> > -   { MIB(snmpInGetResponses),  OID_RD },
> > -   { MIB(snmpInTraps), OID_RD },
> > -   { MIB(snmpOutTooBigs),  OID_RD },
> > -   { MIB(snmpOutNoSuchNames),  OID_RD },
> > -   { MIB(snmpOutBadValues),OID_RD },
> > -   { MIB(snmpOutGenErrs),  OID_RD },
> > -   { MIB(snmpOutGetRequests),  OID_RD },
> > -   { MIB(snmpOutGetNexts), OID_RD },
> > -   { MIB(snmpOutSetRequests),  OID_RD },
> > -   { MIB(snmpOutGetResponses), OID_RD },
> > -   { MIB(snmpOutTraps),OID_RD },
> > -   { MIB(snmpEnableAuthenTraps),   OID_RW },
> > -   { MIB(snmpSilentDrops), OID_RD },
> > -   { MIB(snmpProxyDrops),  OID_RD },
> > -   { MIBEND }
> > -};
> > -
> > -static struct oid usm_mib[] = {
> > -   { MIB(snmpEngine),  OID_MIB },
> > -   { MIB(snmpEngineID),OID_RD },
> > -   { MIB(snmpEngineBoots), OID_RD },
> > -   { MIB(snmpEngineTime),  OID_RD },
> > -   { MIB(snmpEngineMaxMsgSize),OID_RD },
> > -   { MIB(usmStats),OID_MIB },
> > -   { MIB(usmStatsUnsupportedSecLevels),OID_RD },
> > -   { MIB(usmStatsNotInTimeWindow), OID_RD },
> > -   { MIB(usmStatsUnknownUserNames),OID_RD },
> > -   { MIB(usmStatsUnknownEngineId), OID_RD },
> > -   { MIB(usmStatsWrongDigests),OID_RD },
> > -   { MIB(usmStatsDecryptionErrors),OID_RD },
> > -   { MIBEND }
> > -};
> > -
> > -static struct oid hr_mib[] = {
> > -   { MIB(host),OID_MIB },
> > -   { MIB(hrSystemUptime),  OID_RD },
> > -   { MIB(hrSystemDate),OID_RD },
> > -   { MIB(hrSystemProcesses),   OID_RD },
> > -   { MIB(hrSystemMaxProcesses),OID_RD },
> > -   { MIB(hrMemorySize),OID_RD },
> > -   { MIB(hrStorageIndex),  OID_TRD },
> > -   { MIB(hrStorageType),   OID_TRD },
> > -   { MIB(hrStorageDescr),  OID_TRD },
> > -   { MIB(hrStorageAllocationUnits),OID_TRD },
> > -   { MIB(hrStorageSize),   OID_TRD },
> > -   { MIB(hrStorageUsed),   OID_TRD },
> > -   { MIB(hrStorageAllocationFailures), OID_TRD },
> > -   { MIB(hrDeviceIndex),   OID_TRD },
> > -   { MIB(hrDeviceType),OID_TRD },
> > -   { MIB(hrDeviceDescr),   OID_TRD },
> > -   { MIB(hrDeviceID),  OID_TRD },
> > -   { MIB(hrDeviceStatus),  OID_TRD },
> > -   { MIB(hrDeviceErrors),  OID_TRD },
> > -   { 

Re: ospfctl json support

2020-05-18 Thread Denis Fondras
On Mon, May 18, 2020 at 09:04:06AM +0200, Claudio Jeker wrote:
> There is a file missing in the diff.
> 
> One thing I have seen in the original diff from Richard was that the
> copyright in the new file should be copied from ospfctl.c since this is
> mostly a copy paste action and not new work.
> 

Stupid me... Here is an update.
Thank you Claudio.

Index: Makefile
===
RCS file: /cvs/src/usr.sbin/ospfctl/Makefile,v
retrieving revision 1.5
diff -u -p -r1.5 Makefile
--- Makefile2 Sep 2016 14:02:48 -   1.5
+++ Makefile17 May 2020 10:51:28 -
@@ -3,7 +3,7 @@
 .PATH: ${.CURDIR}/../ospfd
 
 PROG=  ospfctl
-SRCS=  logmsg.c ospfctl.c parser.c
+SRCS=  logmsg.c ospfctl.c output.c parser.c
 CFLAGS+= -Wall
 CFLAGS+= -Wstrict-prototypes -Wmissing-prototypes
 CFLAGS+= -Wshadow -Wpointer-arith -Wcast-qual
Index: ospfctl.c
===
RCS file: /cvs/src/usr.sbin/ospfctl/ospfctl.c,v
retrieving revision 1.66
diff -u -p -r1.66 ospfctl.c
--- ospfctl.c   1 Nov 2019 18:15:28 -   1.66
+++ ospfctl.c   17 May 2020 11:11:50 -
@@ -35,42 +35,16 @@
 
 #include "ospf.h"
 #include "ospfd.h"
+#include "ospfctl.h"
 #include "ospfe.h"
 #include "parser.h"
 
 __dead void usage(void);
-int show_summary_msg(struct imsg *);
-uint64_tget_ifms_type(uint8_t);
-int show_interface_msg(struct imsg *);
-int show_interface_detail_msg(struct imsg *);
-const char *print_link(int);
-const char *fmt_timeframe(time_t t);
-const char *fmt_timeframe_core(time_t t);
-const char *log_id(u_int32_t );
-const char *log_adv_rtr(u_int32_t);
-voidshow_database_head(struct in_addr, char *, u_int8_t);
-int show_database_msg(struct imsg *);
-char   *print_ls_type(u_int8_t);
-voidshow_db_hdr_msg_detail(struct lsa_hdr *);
-char   *print_rtr_link_type(u_int8_t);
-const char *print_ospf_flags(u_int8_t);
-int show_db_msg_detail(struct imsg *imsg);
-int show_nbr_msg(struct imsg *);
-const char *print_ospf_options(u_int8_t);
-int show_nbr_detail_msg(struct imsg *);
-int show_rib_msg(struct imsg *);
-voidshow_rib_head(struct in_addr, u_int8_t, u_int8_t);
-const char *print_ospf_rtr_flags(u_int8_t);
-int show_rib_detail_msg(struct imsg *);
-voidshow_fib_head(void);
-int show_fib_msg(struct imsg *);
-voidshow_interface_head(void);
-const char *get_media_descr(uint64_t);
-const char *get_linkstate(uint8_t, int);
-voidprint_baudrate(u_int64_t);
-int show_fib_interface_msg(struct imsg *);
+
+int show(struct imsg *, struct parse_result *);
 
 struct imsgbuf *ibuf;
+const struct output*output = _output;
 
 __dead void
 usage(void)
@@ -145,10 +119,6 @@ main(int argc, char *argv[])
imsg_compose(ibuf, IMSG_CTL_SHOW_SUM, 0, 0, -1, NULL, 0);
break;
case SHOW_IFACE:
-   printf("%-11s %-18s %-6s %-10s %-10s %-8s %3s %3s\n",
-   "Interface", "Address", "State", "HelloTimer", "Linkstate",
-   "Uptime", "nc", "ac");
-   /*FALLTHROUGH*/
case SHOW_IFACE_DTAIL:
if (*res->ifname) {
ifidx = if_nametoindex(res->ifname);
@@ -159,9 +129,6 @@ main(int argc, char *argv[])
, sizeof(ifidx));
break;
case SHOW_NBR:
-   printf("%-15s %-3s %-12s %-8s %-15s %-9s %s\n", "ID", "Pri",
-   "State", "DeadTime", "Address", "Iface","Uptime");
-   /*FALLTHROUGH*/
case SHOW_NBR_DTAIL:
imsg_compose(ibuf, IMSG_CTL_SHOW_NBR, 0, 0, -1, NULL, 0);
break;
@@ -194,9 +161,6 @@ main(int argc, char *argv[])
imsg_compose(ibuf, IMSG_CTL_SHOW_DB_OPAQ, 0, 0, -1, NULL, 0);
break;
case SHOW_RIB:
-   printf("%-20s %-17s %-12s %-9s %-7s %-8s\n", "Destination",
-   "Nexthop", "Path Type", "Type", "Cost", "Uptime");
-   /*FALLTHROUGH*/
case SHOW_RIB_DTAIL:
imsg_compose(ibuf, IMSG_CTL_SHOW_RIB, 0, 0, -1, NULL, 0);
break;
@@ -207,7 +171,6 @@ main(int argc, char *argv[])
else
imsg_compose(ibuf, IMSG_CTL_KROUTE_ADDR, 0, 0, -1,
>addr, sizeof(res->addr));
-   show_fib_head();
break;
case SHOW_FIB_IFACE:
if (*res->ifname)
@@ -215,7 +178,6 @@ main(int argc, char *argv[])
res->ifname, sizeof(res->ifname));
else
imsg_compose(ibuf, IMSG_CTL_IFINFO, 0, 0, -1, NULL, 0);
-   show_interface_head();
break;
case FIB:
   

Re: ospfctl json support

2020-05-17 Thread Denis Fondras
On Fri, May 15, 2020 at 11:34:58AM +0100, Richard Chivers wrote:
> Hi,
> 
> I have now resolved the spacing/tabbing issues I think correctly
> following style(9), along with a couple of other indent issues.
> 
> Would appreciate a cursory look at this stage to spot any further common 
> issues.
> 

I fixed some indent and break long lines.

It reads OK for me. A quick test shows it works for basic commands.

OK denis@

Anyone else for a OK ?

Index: Makefile
===
RCS file: /cvs/src/usr.sbin/ospfctl/Makefile,v
retrieving revision 1.5
diff -u -p -r1.5 Makefile
--- Makefile2 Sep 2016 14:02:48 -   1.5
+++ Makefile17 May 2020 10:51:28 -
@@ -3,7 +3,7 @@
 .PATH: ${.CURDIR}/../ospfd
 
 PROG=  ospfctl
-SRCS=  logmsg.c ospfctl.c parser.c
+SRCS=  logmsg.c ospfctl.c output.c parser.c
 CFLAGS+= -Wall
 CFLAGS+= -Wstrict-prototypes -Wmissing-prototypes
 CFLAGS+= -Wshadow -Wpointer-arith -Wcast-qual
Index: ospfctl.c
===
RCS file: /cvs/src/usr.sbin/ospfctl/ospfctl.c,v
retrieving revision 1.66
diff -u -p -r1.66 ospfctl.c
--- ospfctl.c   1 Nov 2019 18:15:28 -   1.66
+++ ospfctl.c   17 May 2020 11:11:50 -
@@ -35,42 +35,16 @@
 
 #include "ospf.h"
 #include "ospfd.h"
+#include "ospfctl.h"
 #include "ospfe.h"
 #include "parser.h"
 
 __dead void usage(void);
-int show_summary_msg(struct imsg *);
-uint64_tget_ifms_type(uint8_t);
-int show_interface_msg(struct imsg *);
-int show_interface_detail_msg(struct imsg *);
-const char *print_link(int);
-const char *fmt_timeframe(time_t t);
-const char *fmt_timeframe_core(time_t t);
-const char *log_id(u_int32_t );
-const char *log_adv_rtr(u_int32_t);
-voidshow_database_head(struct in_addr, char *, u_int8_t);
-int show_database_msg(struct imsg *);
-char   *print_ls_type(u_int8_t);
-voidshow_db_hdr_msg_detail(struct lsa_hdr *);
-char   *print_rtr_link_type(u_int8_t);
-const char *print_ospf_flags(u_int8_t);
-int show_db_msg_detail(struct imsg *imsg);
-int show_nbr_msg(struct imsg *);
-const char *print_ospf_options(u_int8_t);
-int show_nbr_detail_msg(struct imsg *);
-int show_rib_msg(struct imsg *);
-voidshow_rib_head(struct in_addr, u_int8_t, u_int8_t);
-const char *print_ospf_rtr_flags(u_int8_t);
-int show_rib_detail_msg(struct imsg *);
-voidshow_fib_head(void);
-int show_fib_msg(struct imsg *);
-voidshow_interface_head(void);
-const char *get_media_descr(uint64_t);
-const char *get_linkstate(uint8_t, int);
-voidprint_baudrate(u_int64_t);
-int show_fib_interface_msg(struct imsg *);
+
+int show(struct imsg *, struct parse_result *);
 
 struct imsgbuf *ibuf;
+const struct output*output = _output;
 
 __dead void
 usage(void)
@@ -145,10 +119,6 @@ main(int argc, char *argv[])
imsg_compose(ibuf, IMSG_CTL_SHOW_SUM, 0, 0, -1, NULL, 0);
break;
case SHOW_IFACE:
-   printf("%-11s %-18s %-6s %-10s %-10s %-8s %3s %3s\n",
-   "Interface", "Address", "State", "HelloTimer", "Linkstate",
-   "Uptime", "nc", "ac");
-   /*FALLTHROUGH*/
case SHOW_IFACE_DTAIL:
if (*res->ifname) {
ifidx = if_nametoindex(res->ifname);
@@ -159,9 +129,6 @@ main(int argc, char *argv[])
, sizeof(ifidx));
break;
case SHOW_NBR:
-   printf("%-15s %-3s %-12s %-8s %-15s %-9s %s\n", "ID", "Pri",
-   "State", "DeadTime", "Address", "Iface","Uptime");
-   /*FALLTHROUGH*/
case SHOW_NBR_DTAIL:
imsg_compose(ibuf, IMSG_CTL_SHOW_NBR, 0, 0, -1, NULL, 0);
break;
@@ -194,9 +161,6 @@ main(int argc, char *argv[])
imsg_compose(ibuf, IMSG_CTL_SHOW_DB_OPAQ, 0, 0, -1, NULL, 0);
break;
case SHOW_RIB:
-   printf("%-20s %-17s %-12s %-9s %-7s %-8s\n", "Destination",
-   "Nexthop", "Path Type", "Type", "Cost", "Uptime");
-   /*FALLTHROUGH*/
case SHOW_RIB_DTAIL:
imsg_compose(ibuf, IMSG_CTL_SHOW_RIB, 0, 0, -1, NULL, 0);
break;
@@ -207,7 +171,6 @@ main(int argc, char *argv[])
else
imsg_compose(ibuf, IMSG_CTL_KROUTE_ADDR, 0, 0, -1,
>addr, sizeof(res->addr));
-   show_fib_head();
break;
case SHOW_FIB_IFACE:
if (*res->ifname)
@@ -215,7 +178,6 @@ main(int argc, char *argv[])
res->ifname, sizeof(res->ifname));
else
imsg_compose(ibuf, IMSG_CTL_IFINFO, 0, 0, -1, NULL, 

Re: bgpctl paged output for show rib

2020-05-17 Thread Denis Fondras
> This implements a way to add a limit for bgpctl show rib output.
> When a limit is set then the output will include a token (at the end)
> that can be used to get the next batch of output. These two things allow
> to build a frontend that puts the output onto multiple pages.
> Both regular output and JSON output include the token.
>

I am not comfortable with this. It seems out of the scope of bgpctl.
I would prefer to keep it simple / follow the unix way, aka pipe the output to
another tool to paginate the output.
In your example you use a temp file, why not work on this file to manage the
limit / page display ?



ospf6d: remove F_IFACE_AVAIL

2020-05-16 Thread Denis Fondras
This information is never used/checked.

Index: kroute.c
===
RCS file: /cvs/src/usr.sbin/ospf6d/kroute.c,v
retrieving revision 1.63
diff -u -p -r1.63 kroute.c
--- kroute.c16 May 2020 15:54:12 -  1.63
+++ kroute.c16 May 2020 18:11:51 -
@@ -761,7 +761,6 @@ kif_update(u_short ifindex, int flags, s
return (NULL);
if ((iface = if_new(ifindex, ifname)) == NULL)
return (NULL);
-   iface->cflags |= F_IFACE_AVAIL;
}
 
if_update(iface, ifd->ifi_mtu, flags, ifd->ifi_type,
@@ -1019,7 +1018,6 @@ if_announce(void *msg)
case IFAN_ARRIVAL:
if ((iface = if_new(ifan->ifan_index, ifan->ifan_name)) == NULL)
fatal("if_announce failed");
-   iface->cflags |= F_IFACE_AVAIL;
break;
case IFAN_DEPARTURE:
iface = if_find(ifan->ifan_index);
Index: ospf6d.h
===
RCS file: /cvs/src/usr.sbin/ospf6d/ospf6d.h,v
retrieving revision 1.48
diff -u -p -r1.48 ospf6d.h
--- ospf6d.h16 May 2020 15:54:12 -  1.48
+++ ospf6d.h16 May 2020 18:11:51 -
@@ -330,7 +330,6 @@ struct iface {
u_int8_t cflags;
 #define F_IFACE_PASSIVE0x01
 #define F_IFACE_CONFIGURED 0x02
-#define F_IFACE_AVAIL  0x04
 };
 
 struct ifaddrchange {



scan_ffs prints negative size

2020-05-16 Thread Denis Fondras
Small diff to fix size printing.

Before :
$ doas scan_ffs -v sd0
block 55167 id 758d4818,f2894c98 size -859043093

After:
$ doas ./obj/scan_ffs -v sd0
block 55167 id 758d4818,f2894c98 size 3435924203

Index: scan_ffs.c
===
RCS file: /cvs/src/sbin/scan_ffs/scan_ffs.c,v
retrieving revision 1.23
diff -u -p -r1.23 scan_ffs.c
--- scan_ffs.c  28 Jun 2019 13:32:46 -  1.23
+++ scan_ffs.c  16 May 2020 12:19:18 -
@@ -70,7 +70,7 @@ ufsscan(int fd, daddr_t beg, daddr_t end
sb = (struct fs*)([n]);
if (sb->fs_magic == FS_MAGIC) {
if (flags & FLAG_VERBOSE)
-   printf("block %lld id %x,%x size %d\n",
+   printf("block %lld id %x,%x size %u\n",
(long long)(blk + (n/512)),
sb->fs_id[0], sb->fs_id[1],
sb->fs_ffs1_size);



Re: ospfctl json support

2020-05-14 Thread Denis Fondras
On Thu, May 14, 2020 at 07:15:41PM +0100, Richard Chivers wrote:
> Shall I effectively fix issues in the original code at this stage, or only
> where I have moved and refactored?
> 

Thanks. Limit the changes to what is relative to json support. The diff is
already big enough :)



ospf6d: remove IMSG_IFDELETE

2020-05-14 Thread Denis Fondras
Following https://marc.info/?l=openbsd-tech=158946552515632=2, when
IMSG_IFADD is removed, IMSG_IFDELETE becomes useless...

Index: kroute.c
===
RCS file: /home/denis/dev/cvs/src/usr.sbin/ospf6d/kroute.c,v
retrieving revision 1.62
diff -u -p -r1.62 kroute.c
--- kroute.c16 Dec 2019 08:28:33 -  1.62
+++ kroute.c14 May 2020 18:06:16 -
@@ -1023,12 +1023,6 @@ if_announce(void *msg)
break;
case IFAN_DEPARTURE:
iface = if_find(ifan->ifan_index);
-   if (iface->cflags & F_IFACE_CONFIGURED) {
-   main_imsg_compose_rde(IMSG_IFDELETE, 0,
-   >ifindex, sizeof(iface->ifindex));
-   main_imsg_compose_ospfe(IMSG_IFDELETE, 0,
-   >ifindex, sizeof(iface->ifindex));
-   }
if_del(iface);
break;
}
Index: ospf6d.h
===
RCS file: /home/denis/dev/cvs/src/usr.sbin/ospf6d/ospf6d.h,v
retrieving revision 1.47
diff -u -p -r1.47 ospf6d.h
--- ospf6d.h14 May 2020 18:05:50 -  1.47
+++ ospf6d.h14 May 2020 18:06:30 -
@@ -103,7 +103,6 @@ enum imsg_type {
IMSG_KROUTE_CHANGE,
IMSG_KROUTE_DELETE,
IMSG_IFINFO,
-   IMSG_IFDELETE,
IMSG_IFADDRNEW,
IMSG_IFADDRDEL,
IMSG_NEIGHBOR_UP,
Index: ospfe.c
===
RCS file: /home/denis/dev/cvs/src/usr.sbin/ospf6d/ospfe.c,v
retrieving revision 1.62
diff -u -p -r1.62 ospfe.c
--- ospfe.c 14 May 2020 18:05:50 -  1.62
+++ ospfe.c 14 May 2020 18:07:26 -
@@ -257,7 +257,6 @@ ospfe_dispatch_main(int fd, short event,
struct imsgev   *iev = bula;
struct imsgbuf  *ibuf = >ibuf;
int  n, stub_changed, shut = 0, isvalid, wasvalid;
-   unsigned int ifindex;
 
if (event & EV_READ) {
if ((n = imsg_read(ibuf)) == -1 && errno != EAGAIN)
@@ -326,19 +325,6 @@ ospfe_dispatch_main(int fd, short event,
if_fsm(iface, IF_EVT_DOWN);
log_warnx("interface %s down", iface->name);
}
-   break;
-   case IMSG_IFDELETE:
-   if (imsg.hdr.len != IMSG_HEADER_SIZE +
-   sizeof(ifindex))
-   fatalx("IFDELETE imsg with wrong len");
-
-   memcpy(, imsg.data, sizeof(ifindex));
-   iface = if_find(ifindex);
-   if (iface == NULL)
-   fatalx("interface lost in ospfe");
-
-   LIST_REMOVE(iface, entry);
-   if_del(iface);
break;
case IMSG_IFADDRNEW:
if (imsg.hdr.len != IMSG_HEADER_SIZE +
Index: rde.c
===
RCS file: /home/denis/dev/cvs/src/usr.sbin/ospf6d/rde.c,v
retrieving revision 1.87
diff -u -p -r1.87 rde.c
--- rde.c   14 May 2020 18:05:50 -  1.87
+++ rde.c   14 May 2020 18:07:18 -
@@ -651,7 +651,6 @@ rde_dispatch_parent(int fd, short event,
struct imsgbuf  *ibuf = >ibuf;
ssize_t  n;
int  shut = 0, link_ok, prev_link_ok, orig_lsa;
-   unsigned int ifindex;
 
if (event & EV_READ) {
if ((n = imsg_read(ibuf)) == -1 && errno != EAGAIN)
@@ -733,19 +732,6 @@ rde_dispatch_parent(int fd, short event,
 
orig_intra_area_prefix_lsas(iface->area);
 
-   break;
-   case IMSG_IFDELETE:
-   if (imsg.hdr.len != IMSG_HEADER_SIZE +
-   sizeof(ifindex))
-   fatalx("IFDELETE imsg with wrong len");
-
-   memcpy(, imsg.data, sizeof(ifindex));
-   iface = if_find(ifindex);
-   if (iface == NULL)
-   fatalx("interface lost in rde");
-
-   LIST_REMOVE(iface, entry);
-   if_del(iface);
break;
case IMSG_IFADDRNEW:
if (imsg.hdr.len != IMSG_HEADER_SIZE +



Re: ospfctl json support

2020-05-14 Thread Denis Fondras
On Thu, May 14, 2020 at 05:51:58PM +0100, Richard Chivers wrote:
> Let me know if this now works for you.
> 

This is better, I can apply it :)
However, there are many style(9) issues. Can you fix them please before I review
the changes ?

Thank you.



ospf6d: remove IMSG_IFADD

2020-05-14 Thread Denis Fondras
IMSG_IFADD is never used, wipe it.

Index: ospf6d.h
===
RCS file: /cvs/src/usr.sbin/ospf6d/ospf6d.h,v
retrieving revision 1.46
diff -u -p -r1.46 ospf6d.h
--- ospf6d.h5 Apr 2020 18:19:04 -   1.46
+++ ospf6d.h14 May 2020 13:52:08 -
@@ -103,7 +103,6 @@ enum imsg_type {
IMSG_KROUTE_CHANGE,
IMSG_KROUTE_DELETE,
IMSG_IFINFO,
-   IMSG_IFADD,
IMSG_IFDELETE,
IMSG_IFADDRNEW,
IMSG_IFADDRDEL,
Index: ospfe.c
===
RCS file: /cvs/src/usr.sbin/ospf6d/ospfe.c,v
retrieving revision 1.61
diff -u -p -r1.61 ospfe.c
--- ospfe.c 2 Jan 2020 10:16:46 -   1.61
+++ ospfe.c 14 May 2020 13:52:08 -
@@ -327,18 +327,6 @@ ospfe_dispatch_main(int fd, short event,
log_warnx("interface %s down", iface->name);
}
break;
-   case IMSG_IFADD:
-   if ((iface = malloc(sizeof(struct iface))) == NULL)
-   fatal(NULL);
-   memcpy(iface, imsg.data, sizeof(struct iface));
-
-   LIST_INIT(>nbr_list);
-   TAILQ_INIT(>ls_ack_list);
-   RB_INIT(>lsa_tree);
-
-   LIST_INSERT_HEAD(>area->iface_list, iface,
-   entry);
-   break;
case IMSG_IFDELETE:
if (imsg.hdr.len != IMSG_HEADER_SIZE +
sizeof(ifindex))
Index: rde.c
===
RCS file: /cvs/src/usr.sbin/ospf6d/rde.c,v
retrieving revision 1.86
diff -u -p -r1.86 rde.c
--- rde.c   5 Apr 2020 18:19:04 -   1.86
+++ rde.c   14 May 2020 13:52:09 -
@@ -734,17 +734,6 @@ rde_dispatch_parent(int fd, short event,
orig_intra_area_prefix_lsas(iface->area);
 
break;
-   case IMSG_IFADD:
-   if ((iface = malloc(sizeof(struct iface))) == NULL)
-   fatal(NULL);
-   memcpy(iface, imsg.data, sizeof(struct iface));
-
-   LIST_INIT(>nbr_list);
-   TAILQ_INIT(>ls_ack_list);
-   RB_INIT(>lsa_tree);
-
-   LIST_INSERT_HEAD(>area->iface_list, iface, 
entry);
-   break;
case IMSG_IFDELETE:
if (imsg.hdr.len != IMSG_HEADER_SIZE +
sizeof(ifindex))



Re: ospfctl json support

2020-05-14 Thread Denis Fondras
Please provide a properly formatted diff.

On Thu, May 14, 2020 at 07:16:31AM +0100, Richard Chivers wrote:
> Hi,
> 
> I have done the work to implement ospfctl json support, but as
> discussed i will provide it in two diffs.
> 
> This first one externalises the output aspect of ospfctl and there are
> some things like tail that are not needed specifically for straight
> standard output, but are required for json support.
> 
> I also wasn't sure what to do with Copyright messages at the top of
> files, any advice appreciated.
> 
> In terms of outstanding issues, not sure how big to make the array in
> print_baudrate, I guessed 32 would cover things?
> 
> Many of the functions that return output fragments are called print,
> when they actually return strings. in bgpctl many of these seem to
> have been renamed to fmt_. I have left these as is for now to again
> reduce the size of the change.
> 
> 
> diff --git a/usr.sbin/ospfctl/Makefile b/usr.sbin/ospfctl/Makefile
> index cfd5e4ccb71..6560e0d5f89 100644
> --- a/usr.sbin/ospfctl/Makefile
> +++ b/usr.sbin/ospfctl/Makefile
> @@ -3,7 +3,7 @@
> .PATH: ${.CURDIR}/../ospfd
> PROG= ospfctl
> -SRCS= logmsg.c ospfctl.c parser.c
> +SRCS= logmsg.c ospfctl.c output.c parser.c
> CFLAGS+= -Wall
> CFLAGS+= -Wstrict-prototypes -Wmissing-prototypes
> CFLAGS+= -Wshadow -Wpointer-arith -Wcast-qual
> diff --git a/usr.sbin/ospfctl/ospfctl.c b/usr.sbin/ospfctl/ospfctl.c
> index 2d7189793d8..e04124853a1 100644
> --- a/usr.sbin/ospfctl/ospfctl.c
> +++ b/usr.sbin/ospfctl/ospfctl.c
> @@ -35,42 +35,16 @@
> #include "ospf.h"
> #include "ospfd.h"
> +#include "ospfctl.h"
> #include "ospfe.h"
> #include "parser.h"
> __dead void usage(void);
> -int show_summary_msg(struct imsg *);
> -uint64_t get_ifms_type(uint8_t);
> -int show_interface_msg(struct imsg *);
> -int show_interface_detail_msg(struct imsg *);
> -const char *print_link(int);
> -const char *fmt_timeframe(time_t t);
> -const char *fmt_timeframe_core(time_t t);
> -const char *log_id(u_int32_t );
> -const char *log_adv_rtr(u_int32_t);
> -void show_database_head(struct in_addr, char *, u_int8_t);
> -int show_database_msg(struct imsg *);
> -char *print_ls_type(u_int8_t);
> -void show_db_hdr_msg_detail(struct lsa_hdr *);
> -char *print_rtr_link_type(u_int8_t);
> -const char *print_ospf_flags(u_int8_t);
> -int show_db_msg_detail(struct imsg *imsg);
> -int show_nbr_msg(struct imsg *);
> -const char *print_ospf_options(u_int8_t);
> -int show_nbr_detail_msg(struct imsg *);
> -int show_rib_msg(struct imsg *);
> -void show_rib_head(struct in_addr, u_int8_t, u_int8_t);
> -const char *print_ospf_rtr_flags(u_int8_t);
> -int show_rib_detail_msg(struct imsg *);
> -void show_fib_head(void);
> -int show_fib_msg(struct imsg *);
> -void show_interface_head(void);
> -const char * get_media_descr(uint64_t);
> -const char * get_linkstate(uint8_t, int);
> -void print_baudrate(u_int64_t);
> -int show_fib_interface_msg(struct imsg *);
> +
> +int show(struct imsg *imsg, struct parse_result *res);
> struct imsgbuf *ibuf;
> +const struct output *output = _output;
> __dead void
> usage(void)
> @@ -145,9 +119,6 @@ main(int argc, char *argv[])
> imsg_compose(ibuf, IMSG_CTL_SHOW_SUM, 0, 0, -1, NULL, 0);
> break;
> case SHOW_IFACE:
> - printf("%-11s %-18s %-6s %-10s %-10s %-8s %3s %3s\n",
> - "Interface", "Address", "State", "HelloTimer", "Linkstate",
> - "Uptime", "nc", "ac");
> /*FALLTHROUGH*/
> case SHOW_IFACE_DTAIL:
> if (*res->ifname) {
> @@ -159,8 +130,6 @@ main(int argc, char *argv[])
> , sizeof(ifidx));
> break;
> case SHOW_NBR:
> - printf("%-15s %-3s %-12s %-8s %-15s %-9s %s\n", "ID", "Pri",
> - "State", "DeadTime", "Address", "Iface","Uptime");
> /*FALLTHROUGH*/
> case SHOW_NBR_DTAIL:
> imsg_compose(ibuf, IMSG_CTL_SHOW_NBR, 0, 0, -1, NULL, 0);
> @@ -194,8 +163,6 @@ main(int argc, char *argv[])
> imsg_compose(ibuf, IMSG_CTL_SHOW_DB_OPAQ, 0, 0, -1, NULL, 0);
> break;
> case SHOW_RIB:
> - printf("%-20s %-17s %-12s %-9s %-7s %-8s\n", "Destination",
> - "Nexthop", "Path Type", "Type", "Cost", "Uptime");
> /*FALLTHROUGH*/
> case SHOW_RIB_DTAIL:
> imsg_compose(ibuf, IMSG_CTL_SHOW_RIB, 0, 0, -1, NULL, 0);
> @@ -207,7 +174,6 @@ main(int argc, char *argv[])
> else
> imsg_compose(ibuf, IMSG_CTL_KROUTE_ADDR, 0, 0, -1,
> >addr, sizeof(res->addr));
> - show_fib_head();
> break;
> case SHOW_FIB_IFACE:
> if (*res->ifname)
> @@ -215,7 +181,6 @@ main(int argc, char *argv[])
> res->ifname, sizeof(res->ifname));
> else
> imsg_compose(ibuf, IMSG_CTL_IFINFO, 0, 0, -1, NULL, 0);
> - show_interface_head();
> break;
> case FIB:
> errx(1, "fib couple|decouple");
> @@ -255,72 +220,30 @@ main(int argc, char *argv[])
> if (msgbuf_write(>w) <= 0 && errno != EAGAIN)
> err(1, "write error");
> - while (!done) {
> - if ((n = imsg_read(ibuf)) == -1 && errno != EAGAIN)
> - errx(1, "imsg_read error");
> - if (n == 0)
> - errx(1, "pipe closed");
> + // Don't attempt output for certain commands such as log verbose
> + if(!done){
> + output->head(res);
> while (!done) {
> - if ((n = 

Re: add support for STAILQ_* to queue.h

2020-04-23 Thread Denis Fondras
On Thu, Apr 23, 2020 at 10:31:53AM -0600, Theo de Raadt wrote:
> I would be happy wit such unification.
> 
> Are there any objectors?
> 
> (finishing this might need to be put off for about a month, tho)
> 

I am currently building base with a diff that converts SIMPLEQ_* to STAILQ_*



Re: add support for STAILQ_* to queue.h

2020-04-23 Thread Denis Fondras
On Thu, Apr 23, 2020 at 08:18:16AM -0600, Todd C. Miller wrote:
> Singly-linked tail queues are functionally equivalent to the "simple
> queues" we already have.  Do we really need two implementations of
> what are effectively the same thing or should we just define STAIL_*
> in terms of SIMPLEQ_* and add any missing macros?
> 

Oh! Let's try that :)
Thank you Todd.



add support for STAILQ_* to queue.h

2020-04-23 Thread Denis Fondras
I don't know if it is useful to anyone else but it is required by lsquic, a
library that implements QUIC / HTTP3.

Index: share/man/man3/queue.3
===
RCS file: /cvs/src/share/man/man3/queue.3,v
retrieving revision 1.66
diff -u -p -r1.66 queue.3
--- share/man/man3/queue.3  30 Dec 2019 17:25:39 -  1.66
+++ share/man/man3/queue.3  23 Apr 2020 11:59:19 -
@@ -96,8 +96,24 @@
 .Nm TAILQ_INSERT_TAIL ,
 .Nm TAILQ_REMOVE ,
 .Nm TAILQ_REPLACE ,
-.Nm TAILQ_CONCAT
-.Nd intrusive singly-linked and doubly-linked lists, simple queues, and tail 
queues
+.Nm TAILQ_CONCAT ,
+.Nm STAILQ_HEAD ,
+.Nm STAILQ_HEAD_INITIALIZER ,
+.Nm STAILQ_ENTRY ,
+.Nm STAILQ_FIRST ,
+.Nm STAILQ_EMPTY ,
+.Nm STAILQ_NEXT ,
+.Nm STAILQ_LAST ,
+.Nm STAILQ_FOREACH ,
+.Nm STAILQ_FOREACH_SAFE ,
+.Nm STAILQ_INIT ,
+.Nm STAILQ_INSERT_AFTER ,
+.Nm STAILQ_INSERT_HEAD ,
+.Nm STAILQ_INSERT_TAIL ,
+.Nm STAILQ_REMOVE_HEAD ,
+.Nm STAILQ_REMOVE ,
+.Nm STAILQ_CONCAT
+.Nd intrusive singly-linked and doubly-linked lists, simple queues, tail 
queue, and singly-linked tail queues
 .Sh SYNOPSIS
 .In sys/queue.h
 .Pp
@@ -206,10 +222,32 @@
 .Ft void
 .Fn TAILQ_REPLACE "TAILQ_HEAD *head" "struct TYPE *elm" "struct TYPE *elm2" 
"FIELDNAME"
 .Fn TAILQ_CONCAT "TAILQ_HEAD *head1" "TAILQ_HEAD *head2" "FIELDNAME"
+.Pp
+.Fn STAILQ_ENTRY "TYPE"
+.Fn STAILQ_HEAD "HEADNAME" "TYPE"
+.Fn STAILQ_HEAD_INITIALIZER "STAILQ_HEAD head"
+.Ft "struct TYPE *"
+.Fn STAILQ_FIRST "STAILQ_HEAD *head"
+.Ft int
+.Fn STAILQ_EMPTY "STAILQ_HEAD *head"
+.Ft "struct TYPE *"
+.Fn STAILQ_NEXT "struct TYPE *listelm" "FILEDNAME"
+.Ft "struct TYPE *"
+.Fn STAILQ_LAST "STAILQ_HEAD *head" "struct TYPE *elm" "FIELDNAME"
+.Fn STAILQ_FOREACH "VARNAME" "STAILQ_HEAD *head" "FIELDNAME"
+.Fn STAILQ_FOREACH_SAFE "VARNAME" "STAILQ_HEAD *head" "FIELDNAME" 
"TEMP_VARNAME"
+.Fn STAILQ_INIT "STAILQ_HEAD *head"
+.Fn STAILQ_INSERT_HEAD "STAILQ_HEAD *head" "struct TYPE *elm" "FIELDNAME"
+.Fn STAILQ_INSERT_TAIL "STAILQ_HEAD *head" "struct TYPE *elm" "FIELDNAME"
+.Fn STAILQ_INSERT_AFTER "STAILQ_HEAD *head" "struct TYPE *listelm" "TYPE *elm" 
"FIELDNAME"
+.Fn STAILQ_REMOVE_HEAD "STAILQ_HEAD *head" "FIELDNAME"
+.Fn STAILQ_REMOVE "STAILQ_HEAD *head" "struct TYPE *elm" "TYPE" "FIELDNAME"
+.Fn STAILQ_CONCAT "STAILQ_HEAD *head1" "STAILQ_HEAD *head2"
 .Sh DESCRIPTION
-These macros define and operate on four types of data structures:
-singly-linked lists, simple queues, lists, and tail queues.
-All four structures support the following functionality:
+These macros define and operate on five types of data structures:
+singly-linked lists, simple queues, lists, tail queues, and singly-linked
+tail queues.
+All five structures support the following functionality:
 .Pp
 .Bl -enum -compact -offset indent
 .It
@@ -303,8 +341,9 @@ defined structures containing a field of
 .Li SLIST_ENTRY ,
 .Li LIST_ENTRY ,
 .Li SIMPLEQ_ENTRY ,
+.Li TAILQ_ENTRY , 
 or
-.Li TAILQ_ENTRY .
+.Li STAILQ_ENTRY .
 In the macro definitions,
 .Fa TYPE
 is the name tag of the user defined structure and
@@ -324,8 +363,9 @@ using the macros
 .Fn SLIST_HEAD ,
 .Fn LIST_HEAD ,
 .Fn SIMPLEQ_HEAD ,
+.Fn TAILQ_HEAD ,
 or
-.Fn TAILQ_HEAD .
+.Fn STAILQ_HEAD .
 See the examples below for further explanation of how these macros are used.
 .Sh SINGLY-LINKED LISTS
 A singly-linked list is headed by a structure defined by the
@@ -927,6 +967,27 @@ while ((np = TAILQ_FIRST())) {
 }
 
 .Ed
+.Sh SINGLY LINKED TAIL QUEUES
+The macros prefixed with
+.Do Nm STAILQ_ Dc (
+.Fn STAILQ_HEAD ,
+.Fn STAILQ_HEAD_INITIALIZER ,
+.Fn STAILQ_ENTRY ,
+.Fn STAILQ_FOREACH ,
+.Fn STAILQ_FOREACH_SAFE ,
+.Fn STAILQ_FIRST ,
+.Fn STAILQ_EMPTY ,
+.Fn STAILQ_NEXT ,
+.Fn STAILQ_LAST ,
+.Fn STAILQ_INIT ,
+.Fn STAILQ_INSERT_HEAD ,
+.Fn STAILQ_INSERT_TAIL ,
+.Fn STAILQ_INSERT_AFTER ,
+.Fn STAILQ_REMOVE_HEAD ,
+.Fn STAILQ_REMOVE ,
+and
+.Fn STAILQ_CONCAT )
+are functionally identical to these simple queue functions.
 .Sh SEE ALSO
 .Xr tree 3
 .Sh NOTES
Index: sys/sys/queue.h
===
RCS file: /cvs/src/sys/sys/queue.h,v
retrieving revision 1.45
diff -u -p -r1.45 queue.h
--- sys/sys/queue.h 12 Jul 2018 14:22:54 -  1.45
+++ sys/sys/queue.h 23 Apr 2020 11:59:20 -
@@ -533,4 +533,101 @@ struct {  
\
}   \
 } while (0)
 
-#endif /* !_SYS_QUEUE_H_ */
+/*
+ * Singly-linked Tail queue declarations.
+ */
+#defineSTAILQ_HEAD(name, type) 
\
+struct name {  \
+   struct type *stqh_first;/* first element */ \
+   struct type **stqh_last;/* addr of last next element */ \
+}
+
+#defineSTAILQ_HEAD_INITIALIZER(head)   
\
+   { NULL, &(head).stqh_first }
+
+#define   

Re: slaacd(8): honour rdomain we are running in

2020-04-12 Thread Denis Fondras
On Sun, Apr 12, 2020 at 07:53:23PM +0200, Florian Obser wrote:
> OK?
> 

OK denis@

> diff --git slaacd.c slaacd.c
> index 58f15bcda37..dae2eab3434 100644
> --- slaacd.c
> +++ slaacd.c
> @@ -755,7 +755,7 @@ configure_gateway(struct imsg_configure_dfr *dfr, uint8_t 
> rtm_type)
>   rtm.rtm_version = RTM_VERSION;
>   rtm.rtm_type = rtm_type;
>   rtm.rtm_msglen = sizeof(rtm);
> - rtm.rtm_tableid = 0; /* XXX imsg->rdomain; */
> + rtm.rtm_tableid = getrtable();
>   rtm.rtm_index = dfr->if_index;
>   rtm.rtm_seq = ++rtm_seq;
>   rtm.rtm_priority = RTP_NONE;
> @@ -852,7 +852,7 @@ send_rdns_proposal(struct imsg_propose_rdns *rdns)
>   rtm.rtm_version = RTM_VERSION;
>   rtm.rtm_type = RTM_PROPOSAL;
>   rtm.rtm_msglen = sizeof(rtm);
> - rtm.rtm_tableid = 0; /* XXX imsg->rdomain; */
> + rtm.rtm_tableid = getrtable();
>   rtm.rtm_index = rdns->if_index;
>   rtm.rtm_seq = ++rtm_seq;
>   rtm.rtm_priority = RTP_PROPOSAL_SLAAC;
> 
> 
> -- 
> I'm not entirely sure you are real.
> 



ospf6d: update to connected routes

2020-04-01 Thread Denis Fondras
Handle connected routes as ospfd(8) does.

(diff to ospf6d and ospf6ctl)

Index: ospf6ctl/ospf6ctl.c
===
RCS file: /cvs/src/usr.sbin/ospf6ctl/ospf6ctl.c,v
retrieving revision 1.50
diff -u -p -r1.50 ospf6ctl.c
--- ospf6ctl/ospf6ctl.c 26 May 2019 09:27:09 -  1.50
+++ ospf6ctl/ospf6ctl.c 1 Apr 2020 18:16:12 -
@@ -1103,10 +1103,10 @@ show_rib_msg(struct imsg *imsg)
errx(1, "Invalid route type");
}
 
-   printf("%-20s %-17s %-12s %-9s %-7d %s\n", dstnet,
+   printf("%-20s %-16s%s %-12s %-9s %-7d %s\n", dstnet,
log_in6addr_scope(>nexthop, rt->ifindex),
-   path_type_name(rt->p_type), dst_type_name(rt->d_type),
-   rt->cost,
+   rt->connected ? "C" : " ", path_type_name(rt->p_type),
+   dst_type_name(rt->d_type), rt->cost,
rt->uptime == 0 ? "-" : fmt_timeframe_core(rt->uptime));
free(dstnet);
break;
Index: ospf6d/ospf6d.h
===
RCS file: /cvs/src/usr.sbin/ospf6d/ospf6d.h,v
retrieving revision 1.45
diff -u -p -r1.45 ospf6d.h
--- ospf6d/ospf6d.h 21 Jan 2020 20:38:52 -  1.45
+++ ospf6d/ospf6d.h 1 Apr 2020 18:16:12 -
@@ -483,6 +483,7 @@ struct ctl_rt {
enum dst_typed_type;
u_int8_t flags;
u_int8_t prefixlen;
+   u_int8_t connected;
 };
 
 struct ctl_sum {
Index: ospf6d/rde.c
===
RCS file: /cvs/src/usr.sbin/ospf6d/rde.c,v
retrieving revision 1.85
diff -u -p -r1.85 rde.c
--- ospf6d/rde.c29 Mar 2020 11:59:11 -  1.85
+++ ospf6d/rde.c1 Apr 2020 18:16:12 -
@@ -886,6 +886,9 @@ rde_send_change_kroute(struct rt_node *r
TAILQ_FOREACH(rn, >nexthop, entry) {
if (rn->invalid)
continue;
+   if (rn->connected)
+   /* skip self-originated routes */
+   continue;
krcount++;
 
bzero(, sizeof(kr));
@@ -899,8 +902,12 @@ rde_send_change_kroute(struct rt_node *r
kr.ext_tag = r->ext_tag;
imsg_add(wbuf, , sizeof(kr));
}
-   if (krcount == 0)
-   fatalx("rde_send_change_kroute: no valid nexthop found");
+   if (krcount == 0) {
+   /* no valid nexthop or self originated, so remove */
+   ibuf_free(wbuf);
+   rde_send_delete_kroute(r);
+   return;
+   }
 
imsg_close(_main->ibuf, wbuf);
imsg_event_add(iev_main);
Index: ospf6d/rde_spf.c
===
RCS file: /cvs/src/usr.sbin/ospf6d/rde_spf.c,v
retrieving revision 1.27
diff -u -p -r1.27 rde_spf.c
--- ospf6d/rde_spf.c29 Mar 2020 11:59:11 -  1.27
+++ ospf6d/rde_spf.c1 Apr 2020 18:16:12 -
@@ -897,7 +897,9 @@ rt_nexthop_add(struct rt_node *r, struct
rn->ifindex = vn->ifindex;
rn->adv_rtr.s_addr = adv_rtr.s_addr;
rn->uptime = now.tv_sec;
-   rn->connected = vn->prev == spf_root;
+   rn->connected = (type == LSA_TYPE_NETWORK &&
+   vn->prev == spf_root) ||
+   (IN6_IS_ADDR_UNSPECIFIED(>nexthop));
rn->invalid = 0;
 
r->invalid = 0;
@@ -952,21 +954,24 @@ rt_dump(struct in_addr area, pid_t pid, 
fatalx("rt_dump: invalid RIB type");
}
 
+   memset(, 0, sizeof(rtctl));
+   rtctl.prefix = r->prefix;
+   rtctl.area.s_addr = r->area.s_addr;
+   rtctl.cost = r->cost;
+   rtctl.cost2 = r->cost2;
+   rtctl.p_type = r->p_type;
+   rtctl.d_type = r->d_type;
+   rtctl.flags = r->flags;
+   rtctl.prefixlen = r->prefixlen;
+
TAILQ_FOREACH(rn, >nexthop, entry) {
if (rn->invalid)
continue;
 
-   rtctl.prefix = r->prefix;
+   rtctl.connected = rn->connected;
rtctl.nexthop = rn->nexthop;
rtctl.ifindex = rn->ifindex;
-   rtctl.area.s_addr = r->area.s_addr;
rtctl.adv_rtr.s_addr = rn->adv_rtr.s_addr;
-   rtctl.cost = r->cost;
-   rtctl.cost2 = r->cost2;
-   rtctl.p_type = r->p_type;
-   rtctl.d_type = r->d_type;
-   rtctl.flags = r->flags;
-   rtctl.prefixlen = r->prefixlen;
rtctl.uptime = now.tv_sec - rn->uptime;
 

Re: ospf6d: bring ospf6d closer to ospfd

2020-03-28 Thread Denis Fondras
On Sat, Mar 28, 2020 at 05:00:11PM +0100, Remi Locherer wrote:
> On Sat, Mar 21, 2020 at 05:25:45PM +0100, Denis Fondras wrote:
> > Biggest chunk is rework of rde_asext_get()/rde_asext_put().
> > Also change get_net_link() and get_rtr_link() to work like ospfd couterpart.
> 
> Reads good to me and I didn't spot any issues running tests with it.
> 

Thank you Remi.

> One question: why "if 0" the "Dump SPF tree to log"?
> 

Doh! It is not (yet) time to '#if 0' this part. This is from an unpublished diff
that changes how if_find() works. Thus printing the SPF tree needs to be
rewritten.


> > 
> > Index: rde.c
> > ===
> > RCS file: /cvs/src/usr.sbin/ospf6d/rde.c,v
> > retrieving revision 1.84
> > diff -u -p -r1.84 rde.c
> > --- rde.c   17 Feb 2020 08:12:22 -  1.84
> > +++ rde.c   21 Mar 2020 16:04:47 -
> > @@ -59,8 +59,9 @@ intrde_req_list_exists(struct rde_nbr
> >  voidrde_req_list_del(struct rde_nbr *, struct lsa_hdr *);
> >  voidrde_req_list_free(struct rde_nbr *);
> >  
> > -struct lsa *rde_asext_get(struct kroute *);
> > -struct lsa *rde_asext_put(struct kroute *);
> > +struct iface   *rde_asext_lookup(struct in6_addr, int);
> > +voidrde_asext_get(struct kroute *);
> > +voidrde_asext_put(struct kroute *);
> >  
> >  int comp_asext(struct lsa *, struct lsa *);
> >  struct lsa *orig_asext_lsa(struct kroute *, u_int16_t);
> > @@ -217,6 +218,7 @@ __dead void
> >  rde_shutdown(void)
> >  {
> > struct area *a;
> > +   struct vertex   *v, *nv;
> >  
> > /* close pipes */
> > msgbuf_clear(_ospfe->ibuf.w);
> > @@ -232,6 +234,10 @@ rde_shutdown(void)
> > LIST_REMOVE(a, entry);
> > area_del(a);
> > }
> > +   for (v = RB_MIN(lsa_tree, _tree); v != NULL; v = nv) {
> > +   nv = RB_NEXT(lsa_tree, _tree, v);
> > +   vertex_free(v);
> > +   }
> > rde_nbr_free();
> >  
> > free(iev_ospfe);
> > @@ -643,8 +649,6 @@ rde_dispatch_parent(int fd, short event,
> > struct kroutekr;
> > struct imsgev   *iev = bula;
> > struct imsgbuf  *ibuf = >ibuf;
> > -   struct lsa  *lsa;
> > -   struct vertex   *v;
> > ssize_t  n;
> > int  shut = 0, link_ok, prev_link_ok, orig_lsa;
> > unsigned int ifindex;
> > @@ -676,13 +680,7 @@ rde_dispatch_parent(int fd, short event,
> > break;
> > }
> > memcpy(, imsg.data, sizeof(kr));
> > -
> > -   if ((lsa = rde_asext_get()) != NULL) {
> > -   v = lsa_find(NULL, lsa->hdr.type,
> > -   lsa->hdr.ls_id, lsa->hdr.adv_rtr);
> > -
> > -   lsa_merge(nbrself, lsa, v);
> > -   }
> > +   rde_asext_get();
> > break;
> > case IMSG_NETWORK_DEL:
> > if (imsg.hdr.len != IMSG_HEADER_SIZE + sizeof(kr)) {
> > @@ -691,20 +689,7 @@ rde_dispatch_parent(int fd, short event,
> > break;
> > }
> > memcpy(, imsg.data, sizeof(kr));
> > -
> > -   if ((lsa = rde_asext_put()) != NULL) {
> > -   v = lsa_find(NULL, lsa->hdr.type,
> > -   lsa->hdr.ls_id, lsa->hdr.adv_rtr);
> > -
> > -   /*
> > -* if v == NULL no LSA is in the table and
> > -* nothing has to be done.
> > -*/
> > -   if (v)
> > -   lsa_merge(nbrself, lsa, v);
> > -   else
> > -   free(lsa);
> > -   }
> > +   rde_asext_put();
> > break;
> > case IMSG_IFINFO:
> > if (imsg.hdr.len != IMSG_HEADER_SIZE +
> > @@ -1202,48 +1187,77 @@ rde_req_list_free(struct rde_nbr *nbr)
> >  /*
> >   * as-external LSA handling
> >   */
> > -struct lsa *
> > -rde_asext_get(struct kroute *kr)
> > +stru

Re: tar confused error messages

2020-03-22 Thread Denis Fondras
On Sun, Mar 22, 2020 at 11:41:55AM +0100, Marc Espie wrote:
> If tar can't create intermediate directories due to permission
> issues, the resulting message is confusing:
> 
> ./tar xf gcc.tar gcc-8.3.0/include/obstack.h 
> tar: Unable to create gcc-8.3.0/include/obstack.h: No such file or directory
> 
> (here I have gcc-8.3.0 owned by root and no permissions)
> 
> The following patch changes this to:
> 
> ./tar xf gcc.tar gcc-8.3.0/include/obstack.h 
> tar: Unable to create gcc-8.3.0/include: Permission denied
> tar: Unable to create gcc-8.3.0/include/obstack.h: No such file or directory
> 

Why not use errno on line 106 of file_subs.c ?
That would yield "Permission denied" on obstack.h and would avoid having 2 error
messages.

> okay ? or a better way to do this ?
> 
> Index: extern.h
> ===
> RCS file: /cvs/src/bin/pax/extern.h,v
> retrieving revision 1.59
> diff -u -p -r1.59 extern.h
> --- extern.h  13 Sep 2018 12:33:43 -  1.59
> +++ extern.h  22 Mar 2020 10:39:53 -
> @@ -128,7 +128,7 @@ int cross_lnk(ARCHD *);
>  int chk_same(ARCHD *);
>  int node_creat(ARCHD *);
>  int unlnk_exist(char *, int);
> -int chk_path(char *, uid_t, gid_t);
> +int chk_path(char *, uid_t, gid_t, int);
>  void set_ftime(const char *, const struct timespec *,
>  const struct timespec *, int);
>  void fset_ftime(const char *, int, const struct timespec *,
> Index: file_subs.c
> ===
> RCS file: /cvs/src/bin/pax/file_subs.c,v
> retrieving revision 1.54
> diff -u -p -r1.54 file_subs.c
> --- file_subs.c   28 Jun 2019 13:34:59 -  1.54
> +++ file_subs.c   22 Mar 2020 10:39:53 -
> @@ -102,7 +102,7 @@ file_creat(ARCHD *arcn)
>   file_mode)) >= 0)
>   break;
>   oerrno = errno;
> - if (nodirs || 
> chk_path(arcn->name,arcn->sb.st_uid,arcn->sb.st_gid) < 0) {
> + if (nodirs || 
> chk_path(arcn->name,arcn->sb.st_uid,arcn->sb.st_gid, 0) < 0) {
>   syswarn(1, oerrno, "Unable to create %s", arcn->name);
>   return(-1);
>   }
> @@ -316,7 +316,7 @@ mk_link(char *to, struct stat *to_sb, ch
>   if (linkat(AT_FDCWD, to, AT_FDCWD, from, 0) == 0)
>   break;
>   oerrno = errno;
> - if (!nodirs && chk_path(from, to_sb->st_uid, to_sb->st_gid) == 
> 0)
> + if (!nodirs && chk_path(from, to_sb->st_uid, to_sb->st_gid, 
> ign) == 0)
>   continue;
>   if (!ign) {
>   syswarn(1, oerrno, "Could not link to %s from %s", to,
> @@ -458,7 +458,7 @@ badlink:
>   if (++pass <= 1)
>   continue;
>  
> - if (nodirs || chk_path(nm,arcn->sb.st_uid,arcn->sb.st_gid) < 0) 
> {
> + if (nodirs || chk_path(nm,arcn->sb.st_uid,arcn->sb.st_gid, 0) < 
> 0) {
>   syswarn(1, oerrno, "Could not create: %s", nm);
>   return(-1);
>   }
> @@ -590,7 +590,7 @@ unlnk_exist(char *name, int type)
>   */
>  
>  int
> -chk_path(char *name, uid_t st_uid, gid_t st_gid)
> +chk_path(char *name, uid_t st_uid, gid_t st_gid, int ign)
>  {
>   char *spt = name;
>   char *next;
> @@ -643,6 +643,8 @@ chk_path(char *name, uid_t st_uid, gid_t
>* needed directory and continue on
>*/
>   if (mkdir(name, S_IRWXU | S_IRWXG | S_IRWXO) == -1) {
> + if (!ign)
> + syswarn(1, errno, "Unable to create %s", name); 
>   *spt = '/';
>   retval = -1;
>   break;
> 



ospf6d: bring ospf6d closer to ospfd

2020-03-21 Thread Denis Fondras
Biggest chunk is rework of rde_asext_get()/rde_asext_put().
Also change get_net_link() and get_rtr_link() to work like ospfd couterpart.

Index: rde.c
===
RCS file: /cvs/src/usr.sbin/ospf6d/rde.c,v
retrieving revision 1.84
diff -u -p -r1.84 rde.c
--- rde.c   17 Feb 2020 08:12:22 -  1.84
+++ rde.c   21 Mar 2020 16:04:47 -
@@ -59,8 +59,9 @@ intrde_req_list_exists(struct rde_nbr
 voidrde_req_list_del(struct rde_nbr *, struct lsa_hdr *);
 voidrde_req_list_free(struct rde_nbr *);
 
-struct lsa *rde_asext_get(struct kroute *);
-struct lsa *rde_asext_put(struct kroute *);
+struct iface   *rde_asext_lookup(struct in6_addr, int);
+voidrde_asext_get(struct kroute *);
+voidrde_asext_put(struct kroute *);
 
 int comp_asext(struct lsa *, struct lsa *);
 struct lsa *orig_asext_lsa(struct kroute *, u_int16_t);
@@ -217,6 +218,7 @@ __dead void
 rde_shutdown(void)
 {
struct area *a;
+   struct vertex   *v, *nv;
 
/* close pipes */
msgbuf_clear(_ospfe->ibuf.w);
@@ -232,6 +234,10 @@ rde_shutdown(void)
LIST_REMOVE(a, entry);
area_del(a);
}
+   for (v = RB_MIN(lsa_tree, _tree); v != NULL; v = nv) {
+   nv = RB_NEXT(lsa_tree, _tree, v);
+   vertex_free(v);
+   }
rde_nbr_free();
 
free(iev_ospfe);
@@ -643,8 +649,6 @@ rde_dispatch_parent(int fd, short event,
struct kroutekr;
struct imsgev   *iev = bula;
struct imsgbuf  *ibuf = >ibuf;
-   struct lsa  *lsa;
-   struct vertex   *v;
ssize_t  n;
int  shut = 0, link_ok, prev_link_ok, orig_lsa;
unsigned int ifindex;
@@ -676,13 +680,7 @@ rde_dispatch_parent(int fd, short event,
break;
}
memcpy(, imsg.data, sizeof(kr));
-
-   if ((lsa = rde_asext_get()) != NULL) {
-   v = lsa_find(NULL, lsa->hdr.type,
-   lsa->hdr.ls_id, lsa->hdr.adv_rtr);
-
-   lsa_merge(nbrself, lsa, v);
-   }
+   rde_asext_get();
break;
case IMSG_NETWORK_DEL:
if (imsg.hdr.len != IMSG_HEADER_SIZE + sizeof(kr)) {
@@ -691,20 +689,7 @@ rde_dispatch_parent(int fd, short event,
break;
}
memcpy(, imsg.data, sizeof(kr));
-
-   if ((lsa = rde_asext_put()) != NULL) {
-   v = lsa_find(NULL, lsa->hdr.type,
-   lsa->hdr.ls_id, lsa->hdr.adv_rtr);
-
-   /*
-* if v == NULL no LSA is in the table and
-* nothing has to be done.
-*/
-   if (v)
-   lsa_merge(nbrself, lsa, v);
-   else
-   free(lsa);
-   }
+   rde_asext_put();
break;
case IMSG_IFINFO:
if (imsg.hdr.len != IMSG_HEADER_SIZE +
@@ -1202,48 +1187,77 @@ rde_req_list_free(struct rde_nbr *nbr)
 /*
  * as-external LSA handling
  */
-struct lsa *
-rde_asext_get(struct kroute *kr)
+struct iface *
+rde_asext_lookup(struct in6_addr prefix, int plen)
 {
+
struct area *area;
struct iface*iface;
struct iface_addr   *ia;
-   struct in6_addr  addr;
-
-   LIST_FOREACH(area, >area_list, entry)
-   LIST_FOREACH(iface, >iface_list, entry)
+   struct in6_addr  ina, inb;
+   
+   LIST_FOREACH(area, >area_list, entry) {
+   LIST_FOREACH(iface, >iface_list, entry) {
TAILQ_FOREACH(ia, >ifa_list, entry) {
if (IN6_IS_ADDR_LINKLOCAL(>addr))
continue;
 
-   inet6applymask(, >addr,
-   kr->prefixlen);
-   if (!memcmp(, >prefix,
-   sizeof(addr)) && kr->prefixlen ==
-   ia->prefixlen) {
-   /* already announced as Prefix LSA */
-   log_debug("rde_asext_get: %s/%d is "
-   "part of prefix LSA",
-   log_in6addr(>prefix),
-   kr->prefixlen);
-  

Re: Improve handling of IPv6 SLAAC renumbering scenarios

2020-03-15 Thread Denis Fondras
On Sat, Mar 14, 2020 at 12:54:20PM -0300, Fernando Gont wrote:
> Folks,
> 
> This improves IPv6 SLAAC handling of renumbering scenarios. At the time of
> this writing, this doesn't follow the spec, but is the right thing.
> 
> Essentially, PIOs will employ these default values:
> Preferred Lifetime = Router Lifetime (as sent by router, defaulting to 1800)
> Valid Lifetime= 48 * Preferred Lifetime
> 
> (unless you manually set them to something else)
> 
> The problem statement for this is in this IETF I-D (v6ops wg item):
> https://tools.ietf.org/html/draft-ietf-v6ops-slaac-renum
> 
> And the changes are described Section 4.1.1 of this (*individual* I-D):
> https://tools.ietf.org/html/draft-gont-6man-slaac-renum-04
> 
> Note: More is needed... but this is at least something. If you like the
> patch, I may implement the rest of the proposal.
> 
> Thoughts?
> 
> 
>  cut here 
> diff --git frontend.c frontend.c
> index c932c3dfca3..80c16f953ea 100644
> --- frontend.c
> +++ frontend.c
> @@ -128,7 +128,8 @@ struct ra_iface_conf  *find_ra_iface_conf(struct
> ra_iface_conf_head *,
>  struct ra_prefix_conf*find_ra_prefix_conf(struct 
> ra_prefix_conf_head*,
>   struct in6_addr *, int);
>  void  add_new_prefix_to_ra_iface(struct ra_iface *r,
> - struct in6_addr *, int, struct ra_prefix_conf *);
> + struct in6_addr *, int, struct ra_prefix_conf *,
> + struct ra_iface_conf *);
>  void  free_ra_iface(struct ra_iface *);
>  int   in6_mask2prefixlen(struct in6_addr *);
>  void  get_interface_prefixes(struct ra_iface *,
> @@ -858,16 +859,16 @@ merge_ra_interfaces(void)
>   continue;
>   }
> 
> - ra_iface_conf = find_ra_iface_conf(
> - _conf->ra_iface_list, ra_iface->conf_name);
> + ra_iface_conf = 
> find_ra_iface_conf(_conf->ra_iface_list,
> + ra_iface->name);
> 
>   log_debug("add static prefixes for %s", ra_iface->name);
> 
>   SIMPLEQ_FOREACH(ra_prefix_conf, _iface_conf->ra_prefix_list,
>   entry) {
>   add_new_prefix_to_ra_iface(ra_iface,
> - _prefix_conf->prefix,
> - ra_prefix_conf->prefixlen, ra_prefix_conf);
> + _prefix_conf->prefix, ra_prefix_conf->prefixlen,
> +  ra_prefix_conf, ra_iface_conf);
>   }
> 
>   if (ra_iface_conf->autoprefix)
> @@ -926,6 +927,7 @@ get_interface_prefixes(struct ra_iface *ra_iface, struct
> ra_prefix_conf
>   struct ifaddrs  *ifap, *ifa;
>   struct sockaddr_in6 *sin6;
>   int  prefixlen;
> + struct ra_iface_conf*ra_iface_conf;
> 
>   log_debug("%s: %s", __func__, ra_iface->name);
> 
> @@ -959,8 +961,11 @@ get_interface_prefixes(struct ra_iface *ra_iface,
> struct ra_prefix_conf
> 
>   mask_prefix(>sin6_addr, prefixlen);
> 
> + ra_iface_conf = 
> find_ra_iface_conf(_conf->ra_iface_list,
> + ra_iface->name);
> +
>   add_new_prefix_to_ra_iface(ra_iface, >sin6_addr,
> - prefixlen, autoprefix);
> + prefixlen, autoprefix, ra_iface_conf);
>   }
>   freeifaddrs(ifap);
>  }
> @@ -982,7 +987,8 @@ find_ra_prefix_conf(struct ra_prefix_conf_head* head,
> struct in6_addr *prefix,
> 
>  void
>  add_new_prefix_to_ra_iface(struct ra_iface *ra_iface, struct in6_addr
> *addr,
> -int prefixlen, struct ra_prefix_conf *ra_prefix_conf)
> +int prefixlen, struct ra_prefix_conf *ra_prefix_conf,
> +struct ra_iface_conf *ra_iface_conf)
>  {
>   struct ra_prefix_conf   *new_ra_prefix_conf;
> 
> @@ -992,6 +998,9 @@ add_new_prefix_to_ra_iface(struct ra_iface *ra_iface,
> struct in6_addr *addr,
>   return;
>   }
> 
> + ra_iface_conf = find_ra_iface_conf(_conf->ra_iface_list,
> + ra_iface->name);
> +
>   log_debug("adding %s/%d prefix", in6_to_str(addr), prefixlen);
> 
>   if ((new_ra_prefix_conf = calloc(1, sizeof(*ra_prefix_conf))) == NULL)
> @@ -999,7 +1008,18 @@ add_new_prefix_to_ra_iface(struct ra_iface *ra_iface,
> struct in6_addr *addr,
>   new_ra_prefix_conf->prefix = *addr;
>   new_ra_prefix_conf->prefixlen = prefixlen;
>   new_ra_prefix_conf->vltime = ra_prefix_conf->vltime;

I guess this line ^^ can be removed.

> - new_ra_prefix_conf->pltime = ra_prefix_conf->pltime;
> +
> + if(ra_prefix_conf->pltime == DEFAULT_PIO_PLTIME &&
> +ra_iface_conf->ra_options.router_lifetime > DEFAULT_PIO_PLTIME) {
> + new_ra_prefix_conf->pltime =
> + ra_iface_conf->ra_options.router_lifetime;
> + new_ra_prefix_conf->vltime = new_ra_prefix_conf->pltime * 48;
> + }
> + else{
> + new_ra_prefix_conf->pltime = 

ospf6d: rework rde_lsdb.c

2020-02-15 Thread Denis Fondras
3 changes in rde_lsdb.c
- lsa_find_lsid() has redondant parameters
- call to lsa_self() can be simplified (== ospfd)
- update debug messages to be more suitable

Index: rde.c
===
RCS file: /cvs/src/usr.sbin/ospf6d/rde.c,v
retrieving revision 1.83
diff -u -p -r1.83 rde.c
--- rde.c   21 Jan 2020 15:17:12 -  1.83
+++ rde.c   27 Jan 2020 17:11:52 -
@@ -455,17 +455,10 @@ rde_dispatch_imsg(int fd, short event, v
 
rde_req_list_del(nbr, >hdr);
 
-   self = lsa_self(lsa);
-   if (self) {
-   if (v == NULL)
-   /* LSA is no longer announced,
-* remove by premature aging. */
-   lsa_flush(nbr, lsa);
-   else
-   lsa_reflood(v, lsa);
-   } else if (lsa_add(nbr, lsa))
-   /* delayed lsa, don't flood yet */
-   break;
+   if (!(self = lsa_self(nbr, lsa, v)))
+   if (lsa_add(nbr, lsa))
+   /* delayed lsa */
+   break;
 
/* flood and perhaps ack LSA */
imsg_compose_event(iev_ospfe, IMSG_LS_FLOOD,
@@ -1683,8 +1676,7 @@ orig_asext_lsa(struct kroute *kr, u_int1
memcpy((char *)lsa + sizeof(struct lsa_hdr) + sizeof(struct lsa_asext),
>prefix, LSA_PREFIXSIZE(kr->prefixlen));
 
-   lsa->hdr.ls_id = lsa_find_lsid(_tree, lsa->hdr.type,
-   lsa->hdr.adv_rtr, comp_asext, lsa);
+   lsa->hdr.ls_id = lsa_find_lsid(_tree, comp_asext, lsa);
 
if (age == MAX_AGE) {
/* inherit metric and ext_tag from the current LSA,
Index: rde.h
===
RCS file: /cvs/src/usr.sbin/ospf6d/rde.h,v
retrieving revision 1.24
diff -u -p -r1.24 rde.h
--- rde.h   21 Jan 2020 15:17:12 -  1.24
+++ rde.h   27 Jan 2020 17:11:52 -
@@ -145,9 +145,7 @@ void vertex_nexthop_add(struct vertex 
const struct in6_addr *, u_int32_t);
 int lsa_newer(struct lsa_hdr *, struct lsa_hdr *);
 int lsa_check(struct rde_nbr *, struct lsa *, u_int16_t);
-int lsa_self(struct lsa *);
-voidlsa_flush(struct rde_nbr *, struct lsa *);
-voidlsa_reflood(struct vertex *, struct lsa*);
+int lsa_self(struct rde_nbr *, struct lsa *, struct vertex *);
 int lsa_add(struct rde_nbr *, struct lsa *);
 voidlsa_del(struct rde_nbr *, struct lsa_hdr *);
 voidlsa_age(struct vertex *);
@@ -156,7 +154,7 @@ struct vertex   *lsa_find_rtr(struct area 
 struct vertex  *lsa_find_rtr_frag(struct area *, u_int32_t, unsigned int);
 struct vertex  *lsa_find_tree(struct lsa_tree *, u_int16_t, u_int32_t,
u_int32_t);
-u_int32_t   lsa_find_lsid(struct lsa_tree *, u_int16_t, u_int32_t,
+u_int32_t   lsa_find_lsid(struct lsa_tree *,
int (*)(struct lsa *, struct lsa *), struct lsa *);
 u_int16_t   lsa_num_links(struct vertex *);
 voidlsa_snap(struct rde_nbr *);
Index: rde_lsdb.c
===
RCS file: /cvs/src/usr.sbin/ospf6d/rde_lsdb.c,v
retrieving revision 1.42
diff -u -p -r1.42 rde_lsdb.c
--- rde_lsdb.c  21 Jan 2020 15:17:13 -  1.42
+++ rde_lsdb.c  27 Jan 2020 17:11:52 -
@@ -192,7 +192,7 @@ lsa_check(struct rde_nbr *nbr, struct ls
return (0);
}
if (ntohs(lsa->hdr.len) != len) {
-   log_warnx("lsa_check: bad packet size");
+   log_warnx("lsa_check: bad packet length");
return (0);
}
 
@@ -244,7 +244,7 @@ lsa_check(struct rde_nbr *nbr, struct ls
}
metric = ntohl(lsa->data.pref_sum.metric);
if (metric & ~LSA_METRIC_MASK) {
-   log_warnx("lsa_check: bad LSA summary metric");
+   log_warnx("lsa_check: bad LSA prefix summary metric");
return (0);
}
if (lsa_get_prefix(((char *)lsa) + sizeof(lsa->hdr) +
@@ -263,7 +263,7 @@ lsa_check(struct rde_nbr *nbr, struct ls
}
metric = ntohl(lsa->data.rtr_sum.metric);
if (metric & ~LSA_METRIC_MASK) {
-   log_warnx("lsa_check: bad LSA summary metric");
+   log_warnx("lsa_check: bad LSA router summary metric");
return (0);
  

ospf6d: rework rde_lsdb.c

2020-01-27 Thread Denis Fondras
3 changes in rde_lsdb.c
- lsa_find_lsid() has redondant parameters
- call to lsa_self() can be simplified (== ospfd)
- update debug messages to be more suitable

Index: rde.c
===
RCS file: /cvs/src/usr.sbin/ospf6d/rde.c,v
retrieving revision 1.83
diff -u -p -r1.83 rde.c
--- rde.c   21 Jan 2020 15:17:12 -  1.83
+++ rde.c   27 Jan 2020 17:11:52 -
@@ -455,17 +455,10 @@ rde_dispatch_imsg(int fd, short event, v
 
rde_req_list_del(nbr, >hdr);
 
-   self = lsa_self(lsa);
-   if (self) {
-   if (v == NULL)
-   /* LSA is no longer announced,
-* remove by premature aging. */
-   lsa_flush(nbr, lsa);
-   else
-   lsa_reflood(v, lsa);
-   } else if (lsa_add(nbr, lsa))
-   /* delayed lsa, don't flood yet */
-   break;
+   if (!(self = lsa_self(nbr, lsa, v)))
+   if (lsa_add(nbr, lsa))
+   /* delayed lsa */
+   break;
 
/* flood and perhaps ack LSA */
imsg_compose_event(iev_ospfe, IMSG_LS_FLOOD,
@@ -1683,8 +1676,7 @@ orig_asext_lsa(struct kroute *kr, u_int1
memcpy((char *)lsa + sizeof(struct lsa_hdr) + sizeof(struct lsa_asext),
>prefix, LSA_PREFIXSIZE(kr->prefixlen));
 
-   lsa->hdr.ls_id = lsa_find_lsid(_tree, lsa->hdr.type,
-   lsa->hdr.adv_rtr, comp_asext, lsa);
+   lsa->hdr.ls_id = lsa_find_lsid(_tree, comp_asext, lsa);
 
if (age == MAX_AGE) {
/* inherit metric and ext_tag from the current LSA,
Index: rde.h
===
RCS file: /cvs/src/usr.sbin/ospf6d/rde.h,v
retrieving revision 1.24
diff -u -p -r1.24 rde.h
--- rde.h   21 Jan 2020 15:17:12 -  1.24
+++ rde.h   27 Jan 2020 17:11:52 -
@@ -145,9 +145,7 @@ void vertex_nexthop_add(struct vertex 
const struct in6_addr *, u_int32_t);
 int lsa_newer(struct lsa_hdr *, struct lsa_hdr *);
 int lsa_check(struct rde_nbr *, struct lsa *, u_int16_t);
-int lsa_self(struct lsa *);
-voidlsa_flush(struct rde_nbr *, struct lsa *);
-voidlsa_reflood(struct vertex *, struct lsa*);
+int lsa_self(struct rde_nbr *, struct lsa *, struct vertex *);
 int lsa_add(struct rde_nbr *, struct lsa *);
 voidlsa_del(struct rde_nbr *, struct lsa_hdr *);
 voidlsa_age(struct vertex *);
@@ -156,7 +154,7 @@ struct vertex   *lsa_find_rtr(struct area 
 struct vertex  *lsa_find_rtr_frag(struct area *, u_int32_t, unsigned int);
 struct vertex  *lsa_find_tree(struct lsa_tree *, u_int16_t, u_int32_t,
u_int32_t);
-u_int32_t   lsa_find_lsid(struct lsa_tree *, u_int16_t, u_int32_t,
+u_int32_t   lsa_find_lsid(struct lsa_tree *,
int (*)(struct lsa *, struct lsa *), struct lsa *);
 u_int16_t   lsa_num_links(struct vertex *);
 voidlsa_snap(struct rde_nbr *);
Index: rde_lsdb.c
===
RCS file: /cvs/src/usr.sbin/ospf6d/rde_lsdb.c,v
retrieving revision 1.42
diff -u -p -r1.42 rde_lsdb.c
--- rde_lsdb.c  21 Jan 2020 15:17:13 -  1.42
+++ rde_lsdb.c  27 Jan 2020 17:11:52 -
@@ -192,7 +192,7 @@ lsa_check(struct rde_nbr *nbr, struct ls
return (0);
}
if (ntohs(lsa->hdr.len) != len) {
-   log_warnx("lsa_check: bad packet size");
+   log_warnx("lsa_check: bad packet length");
return (0);
}
 
@@ -244,7 +244,7 @@ lsa_check(struct rde_nbr *nbr, struct ls
}
metric = ntohl(lsa->data.pref_sum.metric);
if (metric & ~LSA_METRIC_MASK) {
-   log_warnx("lsa_check: bad LSA summary metric");
+   log_warnx("lsa_check: bad LSA prefix summary metric");
return (0);
}
if (lsa_get_prefix(((char *)lsa) + sizeof(lsa->hdr) +
@@ -263,7 +263,7 @@ lsa_check(struct rde_nbr *nbr, struct ls
}
metric = ntohl(lsa->data.rtr_sum.metric);
if (metric & ~LSA_METRIC_MASK) {
-   log_warnx("lsa_check: bad LSA summary metric");
+   log_warnx("lsa_check: bad LSA router summary metric");
return (0);
  

Re: ospf6d: simplify lsa_snap()

2020-01-21 Thread Denis Fondras
On Tue, Jan 21, 2020 at 09:35:06AM +0100, Remi Locherer wrote:
> > @@ -235,6 +233,7 @@ lsa_check(struct rde_nbr *nbr, struct ls
> > case LSA_TYPE_NETWORK:
> > if ((len % sizeof(u_int32_t)) ||
> > len < sizeof(lsa->hdr) + sizeof(u_int32_t)) {
> > +   log_warnx("lsa_check: bad LSA network packet");
> 
> please use __func__
> 

None use __func__ currently.



Re: ospf(6)d: allow "type p2p" globally or per area

2020-01-21 Thread Denis Fondras
On Tue, Jan 21, 2020 at 09:41:28AM +0100, Remi Locherer wrote:
> On Mon, Jan 20, 2020 at 05:08:26PM +0100, Denis Fondras wrote:
> > On Sun, Jan 19, 2020 at 11:04:16PM +0100, Remi Locherer wrote:
> > > This makes the interface setting "type p2p" configurable globally or
> > > per area. ospf(6)d allows this for almost all interface related settings.
> > > 
> > > As a side-effect of this diff ospf(6)d -nv prints "type p2p" also for
> > > point-to-point interfaces like gif or gre. I think this is an advantage
> > > but I can also change that by re-introducing the iface->p2p variable.
> > > 
> > > OK?
> > > 
> > 
> > diff looks good. Is it really useful to set p2p globally ?
> 
> Yes, if the router only connects to other routers.
> And the diff makes "type p2p" works the same as the other interface
> settings do. And as the manual tells the user.
> 

OK denis@.



Re: bgpctl show neighbor errors better

2020-01-21 Thread Denis Fondras
On Tue, Jan 21, 2020 at 09:31:36AM +0100, Claudio Jeker wrote:
> So the 'Last error:' message for sessions that failed do often not include
> the suberror and also it is only shown for NOTIFICATIONS we sent but not
> for received notifications. The following diff fixes this.
> 
> So instead of:
>   Last error: Cease
> or
>   Last error: unknown error code
> 
> I now get:
>   Last error sent: Cease, recieved max-prefix exceeded
> or
>   Last error received: Cease, recieved max-prefix exceeded
> 
> -- 
> :wq Claudio
> 
> Index: bgpctl/bgpctl.c
> ===
> RCS file: /cvs/src/usr.sbin/bgpctl/bgpctl.c,v
> retrieving revision 1.256
> diff -u -p -r1.256 bgpctl.c
> --- bgpctl/bgpctl.c   9 Jan 2020 11:57:04 -   1.256
> +++ bgpctl/bgpctl.c   21 Jan 2020 08:18:59 -
> @@ -1300,36 +1300,68 @@ send_filterset(struct imsgbuf *i, struct
>  const char *
>  get_errstr(u_int8_t errcode, u_int8_t subcode)
>  {
> - static const char   *errstr = NULL;
> + static char  errbuf[256];
> + const char  *errstr = NULL;
> + const char  *suberr = NULL;
> + int  uk = 0;
>  
> - if (errcode && errcode < sizeof(errnames)/sizeof(char *))
> + if (errcode == 0)   /* no error */
> + return NULL;
> +
> + if (errcode < sizeof(errnames)/sizeof(char *))
>   errstr = errnames[errcode];
>  
>   switch (errcode) {
>   case ERR_HEADER:
> - if (subcode &&
> - subcode < sizeof(suberr_header_names)/sizeof(char *))
> - errstr = suberr_header_names[subcode];
> + if (subcode < sizeof(suberr_header_names)/sizeof(char *))
> + suberr = suberr_header_names[subcode];
> + else
> + uk = 1;

Would it be possible to have that chunk before the switch to avoid duplication ?

>   break;
>   case ERR_OPEN:
> - if (subcode &&
> - subcode < sizeof(suberr_open_names)/sizeof(char *))
> - errstr = suberr_open_names[subcode];
> + if (subcode < sizeof(suberr_open_names)/sizeof(char *))
> + suberr = suberr_open_names[subcode];
> + else
> + uk = 1;
>   break;
>   case ERR_UPDATE:
> - if (subcode &&
> - subcode < sizeof(suberr_update_names)/sizeof(char *))
> - errstr = suberr_update_names[subcode];
> + if (subcode < sizeof(suberr_update_names)/sizeof(char *))
> + suberr = suberr_update_names[subcode];
> + else
> + uk = 1;
>   break;
>   case ERR_HOLDTIMEREXPIRED:
> + if (subcode != 0)
> + uk = 1;
> + break;
>   case ERR_FSM:
> + if (subcode < sizeof(suberr_fsm_names)/sizeof(char *))
> + suberr = suberr_fsm_names[subcode];
> + else
> + uk = 1;
> + break;
>   case ERR_CEASE:
> + if (subcode < sizeof(suberr_cease_names)/sizeof(char *))
> + suberr = suberr_cease_names[subcode];
> + else
> + uk = 1;
>   break;
>   default:
> - return ("unknown error code");
> + snprintf(errbuf, sizeof(errbuf),
> + "unknown error code %u subcode %u", errcode, subcode);
> + return (errbuf);
>   }
>  
> - return (errstr);
> + if (uk)
> + snprintf(errbuf, sizeof(errbuf),
> + "%s, unknown subcode %u", errstr, subcode);
> + else if (suberr == NULL)
> + return (errstr);
> + else
> + snprintf(errbuf, sizeof(errbuf),
> + "%s, %s", errstr, suberr);
> +
> + return (errbuf);
>  }
>  
>  void
> Index: bgpctl/output.c
> ===
> RCS file: /cvs/src/usr.sbin/bgpctl/output.c,v
> retrieving revision 1.3
> diff -u -p -r1.3 output.c
> --- bgpctl/output.c   9 Jan 2020 11:57:04 -   1.3
> +++ bgpctl/output.c   21 Jan 2020 08:18:59 -
> @@ -221,12 +221,16 @@ show_neighbor_full(struct peer *p, struc
>   log_shutcomm(p->stats.last_shutcomm));
>   }
>   if (p->state == STATE_IDLE) {
> - static const char   *errstr;
> + const char *errstr;
>  
>   errstr = get_errstr(p->stats.last_sent_errcode,
>   p->stats.last_sent_suberr);
>   if (errstr)
> - printf("  Last error: %s\n\n", errstr);
> + printf("  Last error sent: %s\n\n", errstr);
> + errstr = get_errstr(p->stats.last_rcvd_errcode,
> + p->stats.last_rcvd_suberr);
> + if (errstr)
> + printf("  Last error received: %s\n\n", errstr);

Re: ospf(6)d: allow "type p2p" globally or per area

2020-01-20 Thread Denis Fondras
On Sun, Jan 19, 2020 at 11:04:16PM +0100, Remi Locherer wrote:
> This makes the interface setting "type p2p" configurable globally or
> per area. ospf(6)d allows this for almost all interface related settings.
> 
> As a side-effect of this diff ospf(6)d -nv prints "type p2p" also for
> point-to-point interfaces like gif or gre. I think this is an advantage
> but I can also change that by re-introducing the iface->p2p variable.
> 
> OK?
> 

diff looks good. Is it really useful to set p2p globally ?

> Remi
> 
> 
> 
> Index: ospf6d/ospf6d.h
> ===
> RCS file: /cvs/src/usr.sbin/ospf6d/ospf6d.h,v
> retrieving revision 1.44
> diff -u -p -r1.44 ospf6d.h
> --- ospf6d/ospf6d.h   3 Jan 2020 17:45:02 -   1.44
> +++ ospf6d/ospf6d.h   12 Jan 2020 21:44:41 -
> @@ -329,7 +329,6 @@ struct iface {
>   u_int8_t if_type;
>   u_int8_t linkstate;
>   u_int8_t priority;
> - u_int8_t p2p;
>   u_int8_t cflags;
>  #define F_IFACE_PASSIVE  0x01
>  #define F_IFACE_CONFIGURED   0x02
> Index: ospf6d/parse.y
> ===
> RCS file: /cvs/src/usr.sbin/ospf6d/parse.y,v
> retrieving revision 1.48
> diff -u -p -r1.48 parse.y
> --- ospf6d/parse.y26 Dec 2019 10:24:18 -  1.48
> +++ ospf6d/parse.y19 Jan 2020 21:51:56 -
> @@ -102,6 +102,7 @@ struct config_defaults {
>   u_int16_t   rxmt_interval;
>   u_int16_t   metric;
>   u_int8_tpriority;
> + u_int8_tp2p;
>  };
>  
>  struct config_defaultsglobaldefs;
> @@ -449,6 +450,9 @@ defaults  : METRIC NUMBER {
>   }
>   defs->rxmt_interval = $2;
>   }
> + | TYPE P2P  {
> + defs->p2p = 1;
> + }
>   ;
>  
>  optnl: '\n' optnl
> @@ -550,6 +554,8 @@ interface : INTERFACE STRING  {
>   iface->metric = defs->metric;
>   iface->priority = defs->priority;
>   iface->cflags |= F_IFACE_CONFIGURED;
> + if (defs->p2p == 1)
> + iface->type = IF_TYPE_POINTOPOINT;
>   iface = NULL;
>   /* interface is always part of an area */
>   defs = 
> @@ -566,10 +572,6 @@ interfaceopts_l  : interfaceopts_l interf
>   ;
>  
>  interfaceoptsl   : PASSIVE   { iface->cflags |= 
> F_IFACE_PASSIVE; }
> - | TYPE P2P  {
> - iface->p2p = 1;
> - iface->type = IF_TYPE_POINTOPOINT;
> - }
>   | DEMOTE STRING {
>   if (strlcpy(iface->demote_group, $2,
>   sizeof(iface->demote_group)) >=
> @@ -1034,6 +1036,7 @@ parse_config(char *filename, int opts)
>   defs->rxmt_interval = DEFAULT_RXMT_INTERVAL;
>   defs->metric = DEFAULT_METRIC;
>   defs->priority = DEFAULT_PRIORITY;
> + defs->p2p = 0;
>  
>   conf->spf_delay = DEFAULT_SPF_DELAY;
>   conf->spf_hold_time = DEFAULT_SPF_HOLDTIME;
> Index: ospf6d/printconf.c
> ===
> RCS file: /cvs/src/usr.sbin/ospf6d/printconf.c,v
> retrieving revision 1.9
> diff -u -p -r1.9 printconf.c
> --- ospf6d/printconf.c26 Dec 2019 10:24:18 -  1.9
> +++ ospf6d/printconf.c12 Jan 2020 21:43:06 -
> @@ -1,4 +1,5 @@
> -/*   $OpenBSD: printconf.c,v 1.9 2019/12/26 10:24:18 remi Exp $ */
> +/*  $OpenBSD: printconf.c,v 1.9 2019/12/26 10:24:18 remi Exp $
> +*/
>  
>  /*
>   * Copyright (c) 2004, 2005 Esben Norby 
> @@ -135,7 +136,7 @@ print_iface(struct iface *iface)
>   printf("\t\trouter-priority %d\n", iface->priority);
>   printf("\t\ttransmit-delay %d\n", iface->transmit_delay);
>  
> - if (iface->p2p)
> + if (iface->type == IF_TYPE_POINTOPOINT)
>   printf("\t\ttype p2p\n");
>  
>   printf("\t}\n");
> Index: ospfd/ospfd.c
> ===
> RCS file: /cvs/src/usr.sbin/ospfd/ospfd.c,v
> retrieving revision 1.110
> diff -u -p -r1.110 ospfd.c
> --- ospfd/ospfd.c 23 Nov 2019 15:05:21 -  1.110
> +++ ospfd/ospfd.c 18 Jan 2020 14:02:04 -
> @@ -893,7 +893,6 @@ merge_interfaces(struct area *a, struct 
>   if (i->self)
>   i->self->priority = i->priority;
>   i->flags = xi->flags; /* needed? */
> - i->type = xi->type; /* needed? */
>   i->if_type = xi->if_type; /* needed? */
>   i->linkstate = xi->linkstate; /* needed? */
>  
> @@ -915,11 +914,11 @@ merge_interfaces(struct area *a, struct 
>   if_fsm(i, IF_EVT_UP);
>   }

ospf6d: simplify lsa_snap()

2020-01-20 Thread Denis Fondras
No need to pass peerid to lsa_snap()

While at it, remove unused variable.

Index: rde.c
===
RCS file: /cvs/src/usr.sbin/ospf6d/rde.c,v
retrieving revision 1.82
diff -u -p -r1.82 rde.c
--- rde.c   2 Jan 2020 10:16:46 -   1.82
+++ rde.c   20 Jan 2020 09:23:01 -
@@ -345,7 +345,7 @@ rde_dispatch_imsg(int fd, short event, v
if (nbr == NULL)
break;
 
-   lsa_snap(nbr, imsg.hdr.peerid);
+   lsa_snap(nbr);
 
imsg_compose_event(iev_ospfe, IMSG_DB_END, 
imsg.hdr.peerid,
0, -1, NULL, 0);
Index: rde.h
===
RCS file: /cvs/src/usr.sbin/ospf6d/rde.h,v
retrieving revision 1.23
diff -u -p -r1.23 rde.h
--- rde.h   22 Dec 2019 11:19:06 -  1.23
+++ rde.h   20 Jan 2020 09:23:01 -
@@ -159,7 +159,7 @@ struct vertex   *lsa_find_tree(struct lsa_
 u_int32_t   lsa_find_lsid(struct lsa_tree *, u_int16_t, u_int32_t,
int (*)(struct lsa *, struct lsa *), struct lsa *);
 u_int16_t   lsa_num_links(struct vertex *);
-voidlsa_snap(struct rde_nbr *, u_int32_t);
+voidlsa_snap(struct rde_nbr *);
 voidlsa_dump(struct lsa_tree *, int, pid_t);
 voidlsa_merge(struct rde_nbr *, struct lsa *, struct vertex *);
 voidlsa_remove_invalid_sums(struct area *);
Index: rde_lsdb.c
===
RCS file: /cvs/src/usr.sbin/ospf6d/rde_lsdb.c,v
retrieving revision 1.41
diff -u -p -r1.41 rde_lsdb.c
--- rde_lsdb.c  2 Jan 2020 10:16:46 -   1.41
+++ rde_lsdb.c  20 Jan 2020 09:23:01 -
@@ -39,8 +39,6 @@ intlsa_get_prefix(void *, u_int16_t, 
 
 RB_GENERATE(lsa_tree, vertex, entry, lsa_compare)
 
-extern struct ospfd_conf   *rdeconf;
-
 void
 lsa_init(struct lsa_tree *t)
 {
@@ -235,6 +233,7 @@ lsa_check(struct rde_nbr *nbr, struct ls
case LSA_TYPE_NETWORK:
if ((len % sizeof(u_int32_t)) ||
len < sizeof(lsa->hdr) + sizeof(u_int32_t)) {
+   log_warnx("lsa_check: bad LSA network packet");
return (0);
}
break;
@@ -716,7 +715,7 @@ lsa_num_links(struct vertex *v)
 }
 
 void
-lsa_snap(struct rde_nbr *nbr, u_int32_t peerid)
+lsa_snap(struct rde_nbr *nbr)
 {
struct lsa_tree *tree = >area->lsa_tree;
struct vertex   *v;
@@ -727,11 +726,13 @@ lsa_snap(struct rde_nbr *nbr, u_int32_t 
continue;
lsa_age(v);
if (ntohs(v->lsa->hdr.age) >= MAX_AGE) {
-   rde_imsg_compose_ospfe(IMSG_LS_SNAP, peerid,
-   0, >lsa->hdr, ntohs(v->lsa->hdr.len));
+   rde_imsg_compose_ospfe(IMSG_LS_SNAP,
+   nbr->peerid, 0, >lsa->hdr,
+   ntohs(v->lsa->hdr.len));
} else {
-   rde_imsg_compose_ospfe(IMSG_DB_SNAPSHOT, peerid,
-   0, >lsa->hdr, sizeof(struct lsa_hdr));
+   rde_imsg_compose_ospfe(IMSG_DB_SNAPSHOT,
+   nbr->peerid, 0, >lsa->hdr,
+   sizeof(struct lsa_hdr));
}
}
if (tree == _tree)



Re: bgpd and time stamps

2020-01-09 Thread Denis Fondras
On Tue, Dec 31, 2019 at 04:32:24PM +0100, Claudio Jeker wrote:
> This changes bgpd to only use CLOCK_MONOTONIC via the getmonotime()
> function. Additionally it changes the export of RIB entries to report the
> last modified time relative to now. Other places also needed some fixup,
> like the mrt dump code since the Originated Time field in those messages
> is epoch based.
> 
> It would be nice to also send the last_read, last_write, and last_updown in
> a relative form to bgpctl but that is more complex.
> 
> In bgpctl fmt_timeframe is now for relative timestamps and fmt_monotime
> for those using CLOCK_MONOTONIC. The goal is to remove the latter once
> last_read and friends got changed.
> 
> OK?

OK denis@

> -- 
> :wq Claudio
> 
> Index: bgpctl/bgpctl.c
> ===
> RCS file: /cvs/src/usr.sbin/bgpctl/bgpctl.c,v
> retrieving revision 1.255
> diff -u -p -r1.255 bgpctl.c
> --- bgpctl/bgpctl.c   31 Dec 2019 14:09:27 -  1.255
> +++ bgpctl/bgpctl.c   31 Dec 2019 15:31:39 -
> @@ -595,8 +595,8 @@ print_neighbor_msgstats(struct peer *p)
>  #define TF_BUFS  8
>  #define TF_LEN   9
>  
> -static const char *
> -fmt_timeframe_core(time_t t)
> +const char *
> +fmt_timeframe(time_t t)
>  {
>   char*buf;
>   static char  tfbuf[TF_BUFS][TF_LEN];/* ring buffer */
> @@ -630,17 +630,18 @@ fmt_timeframe_core(time_t t)
>  }
>  
>  const char *
> -fmt_timeframe(time_t t)
> +fmt_monotime(time_t t)
>  {
> - time_t now;
> + struct timespec ts;
>  
>   if (t == 0)
>   return ("Never");
>  
> - now = time(NULL);
> - if (t > now)/* time in the future is not possible */
> - t = now;
> - return (fmt_timeframe_core(now - t));
> + if (clock_gettime(CLOCK_MONOTONIC, ) != 0)
> + err(1, "clock_gettime");
> + if (t > ts.tv_sec)  /* time in the future is not possible */
> + t = ts.tv_sec;
> + return (fmt_timeframe(ts.tv_sec - t));
>  }
>  
>  void
> @@ -1414,17 +1415,20 @@ show_mrt_dump(struct mrt_rib *mr, struct
>   struct parse_result  res;
>   struct ctl_show_rib_request *req = arg;
>   struct mrt_rib_entry*mre;
> + time_t   now;
>   u_int16_ti, j;
>  
>   memset(, 0, sizeof(res));
>   res.flags = req->flags;
> + now = time(NULL);
>  
>   for (i = 0; i < mr->nentries; i++) {
>   mre = >entries[i];
>   bzero(, sizeof(ctl));
>   ctl.prefix = mr->prefix;
>   ctl.prefixlen = mr->prefixlen;
> - ctl.lastchange = mre->originated;
> + if (mre->originated <= now)
> + ctl.age = now - mre->originated;
>   ctl.true_nexthop = mre->nexthop;
>   ctl.exit_nexthop = mre->nexthop;
>   ctl.origin = mre->origin;
> @@ -1490,14 +1494,17 @@ network_mrt_dump(struct mrt_rib *mr, str
>   struct ctl_show_rib_request *req = arg;
>   struct mrt_rib_entry*mre;
>   struct ibuf *msg;
> + time_t   now;
>   u_int16_ti, j;
>  
> + now = time(NULL);
>   for (i = 0; i < mr->nentries; i++) {
>   mre = >entries[i];
>   bzero(, sizeof(ctl));
>   ctl.prefix = mr->prefix;
>   ctl.prefixlen = mr->prefixlen;
> - ctl.lastchange = mre->originated;
> + if (mre->originated <= now)
> + ctl.age = now - mre->originated;
>   ctl.true_nexthop = mre->nexthop;
>   ctl.exit_nexthop = mre->nexthop;
>   ctl.origin = mre->origin;
> Index: bgpctl/bgpctl.h
> ===
> RCS file: /cvs/src/usr.sbin/bgpctl/bgpctl.h,v
> retrieving revision 1.2
> diff -u -p -r1.2 bgpctl.h
> --- bgpctl/bgpctl.h   31 Dec 2019 14:09:27 -  1.2
> +++ bgpctl/bgpctl.h   31 Dec 2019 15:31:39 -
> @@ -44,6 +44,7 @@ const char  *print_auth_method(enum auth_
>  const char   *fmt_mem(long long);
>  
>  const char   *fmt_timeframe(time_t);
> +const char   *fmt_monotime(time_t);
>  char *fmt_peer(const char *, const struct bgpd_addr *, int);
>  const char   *get_errstr(u_int8_t, u_int8_t);
>  
> Index: bgpctl/output.c
> ===
> RCS file: /cvs/src/usr.sbin/bgpctl/output.c,v
> retrieving revision 1.2
> diff -u -p -r1.2 output.c
> --- bgpctl/output.c   31 Dec 2019 14:09:27 -  1.2
> +++ bgpctl/output.c   31 Dec 2019 15:31:39 -
> @@ -111,7 +111,7 @@ show_summary(struct peer *p)
>   p->stats.msg_sent_update + p->stats.msg_sent_keepalive +
>   p->stats.msg_sent_rrefresh,
>   p->wbuf.queued,
> - fmt_timeframe(p->stats.last_updown));
> + fmt_monotime(p->stats.last_updown));
>  

Re: ospf(6)d.conf: define interface parameters per area or globally

2020-01-08 Thread Denis Fondras
On Wed, Jan 08, 2020 at 09:14:48AM +0100, Remi Locherer wrote:
> > I have a diff to allow parameters after interface or area definition.
> > Not sure if we want to do that though.
> 
> I would appreciate that! ;-)
> 

The ospfd diff needs some more work. Crypt authentication handling is not
perfect.

Index: ospf6d/ospf6d.h
===
RCS file: /cvs/src/usr.sbin/ospf6d/ospf6d.h,v
retrieving revision 1.44
diff -u -p -r1.44 ospf6d.h
--- ospf6d/ospf6d.h 3 Jan 2020 17:45:02 -   1.44
+++ ospf6d/ospf6d.h 8 Jan 2020 12:11:20 -
@@ -328,7 +328,7 @@ struct iface {
enum iface_type  type;
u_int8_t if_type;
u_int8_t linkstate;
-   u_int8_t priority;
+   int16_t  priority;
u_int8_t p2p;
u_int8_t cflags;
 #define F_IFACE_PASSIVE0x01
Index: ospf6d/parse.y
===
RCS file: /cvs/src/usr.sbin/ospf6d/parse.y,v
retrieving revision 1.48
diff -u -p -r1.48 parse.y
--- ospf6d/parse.y  26 Dec 2019 10:24:18 -  1.48
+++ ospf6d/parse.y  8 Jan 2020 12:11:20 -
@@ -101,7 +101,7 @@ struct config_defaults {
u_int16_t   hello_interval;
u_int16_t   rxmt_interval;
u_int16_t   metric;
-   u_int8_tpriority;
+   int16_t priority;
 };
 
 struct config_defaults  globaldefs;
@@ -111,6 +111,7 @@ struct config_defaults  *defs;
 
 struct area*conf_get_area(struct in_addr);
 int conf_check_rdomain(u_int);
+voidiface_settings(struct iface *, struct config_defaults *);
 
 typedef struct {
union {
@@ -465,9 +466,14 @@ comma  : ','
 area   : AREA areaid {
area = conf_get_area($2);
 
-   memcpy(, defs, sizeof(areadefs));
+   memset(, 0, sizeof(areadefs));
+   areadefs.priority = -1;
defs = 
} '{' optnl areaopts_l '}' {
+   struct iface*i;
+   LIST_FOREACH(i, >iface_list, entry) {
+   iface_settings(i, );
+   }
area = NULL;
defs = 
}
@@ -540,15 +546,12 @@ interface : INTERFACE STRING  {
iface->area = area;
LIST_INSERT_HEAD(>iface_list, iface, entry);
 
-   memcpy(, defs, sizeof(ifacedefs));
+   memset(, 0, sizeof(ifacedefs));
+   ifacedefs.priority = -1;
defs = 
} interface_block {
-   iface->dead_interval = defs->dead_interval;
-   iface->transmit_delay = defs->transmit_delay;
-   iface->hello_interval = defs->hello_interval;
-   iface->rxmt_interval = defs->rxmt_interval;
-   iface->metric = defs->metric;
-   iface->priority = defs->priority;
+   iface->priority = -1;
+   iface_settings(iface, defs);
iface->cflags |= F_IFACE_CONFIGURED;
iface = NULL;
/* interface is always part of an area */
@@ -1018,6 +1021,8 @@ popfile(void)
 struct ospfd_conf *
 parse_config(char *filename, int opts)
 {
+   struct area *a;
+   struct iface*i;
struct sym  *sym, *next;
 
if ((conf = calloc(1, sizeof(struct ospfd_conf))) == NULL)
@@ -1068,6 +1073,10 @@ parse_config(char *filename, int opts)
}
}
 
+   LIST_FOREACH(a, >area_list, entry)
+   LIST_FOREACH(i, >iface_list, entry)
+   iface_settings(i, defs);
+   
/* check that all interfaces belong to the configured rdomain */
errors += conf_check_rdomain(conf->rdomain);
 
@@ -1319,4 +1328,21 @@ prefix(const char *s, struct in6_addr *a
}
*plen = 128;
return (host(s, addr));
+}
+
+void
+iface_settings(struct iface *i, struct config_defaults *cfg)
+{
+   if (i->dead_interval == 0)
+   i->dead_interval = cfg->dead_interval;
+   if (i->transmit_delay == 0)
+   i->transmit_delay = cfg->transmit_delay;
+   if (i->hello_interval == 0)
+   i->hello_interval = cfg->hello_interval;
+   if (i->rxmt_interval == 0)
+   i->rxmt_interval = cfg->rxmt_interval;
+   if (i->metric == 0)
+   i->metric = cfg->metric;
+   if (i->priority == -1)
+   i->priority = cfg->priority;
 }
Index: ospfd/logmsg.c
===
RCS file: /cvs/src/usr.sbin/ospfd/logmsg.c,v
retrieving 

Re: ospf(6)d.conf: define interface parameters per area or globally

2020-01-04 Thread Denis Fondras
On Sat, Jan 04, 2020 at 11:11:36PM +0100, Remi Locherer wrote:
> Hi,
> 
> interface-specific parameters can be defined globally or per area.
> But they are applied to the interfaces only if the interfaces are
> declared afterwards.
> 

I have a diff to allow parameters after interface or area definition.
Not sure if we want to do that though.

> Or is the GLOBAL CONFIURATION section the better place for this?
> I opted for the AREA section because I consider it unlikely a user adds
> global parameters at the end of the config file. But who knows. ;-)
> 

In the MACRO section I would change the last sentence too (or even remove it as
it is close to the GLOBAL first paragraph).

Anyway OK denis@

> Remi
> 
> Index: ospfd/ospfd.conf.5
> ===
> RCS file: /cvs/src/usr.sbin/ospfd/ospfd.conf.5,v
> retrieving revision 1.58
> diff -u -p -r1.58 ospfd.conf.5
> --- ospfd/ospfd.conf.519 Nov 2019 09:55:55 -  1.58
> +++ ospfd/ospfd.conf.54 Jan 2020 21:48:00 -
> @@ -256,11 +256,13 @@ is set to a value other than 1 or if the
>  Areas are used for grouping interfaces.
>  All interface-specific parameters can
>  be configured per area, overruling the global settings.
> +These interface-specific parameters need to be defined before the interfaces.
>  .Bl -tag -width Ds
>  .It Ic area Ar id | address
>  Specify an area section, grouping one or more interfaces.
>  .Bd -literal -offset indent
>  area 0.0.0.0 {
> + hello-interval 3
>   interface em0
>   interface em1 {
>   metric 10
> Index: ospf6d/ospf6d.conf.5
> ===
> RCS file: /cvs/src/usr.sbin/ospf6d/ospf6d.conf.5,v
> retrieving revision 1.20
> diff -u -p -r1.20 ospf6d.conf.5
> --- ospf6d/ospf6d.conf.5  26 Dec 2019 10:24:18 -  1.20
> +++ ospf6d/ospf6d.conf.5  4 Jan 2020 21:48:30 -
> @@ -236,11 +236,13 @@ is set to a value different to 1 or if t
>  Areas are used for grouping interfaces.
>  All interface-specific parameters can
>  be configured per area, overruling the global settings.
> +These interface-specific parameters need to be defined before the interfaces.
>  .Bl -tag -width Ds
>  .It Ic area Ar address Ns | Ns Ar id
>  Specify an area section, grouping one or more interfaces.
>  .Bd -literal -offset indent
>  area 0.0.0.0 {
> + hello-interval 3
>   interface em0
>   interface em1 {
>   metric 10
> 



ospf6d: sync hello.c with ospfd

2020-01-02 Thread Denis Fondras
Sync with ospfd's hello.c

Index: hello.c
===
RCS file: /cvs/src/usr.sbin/ospf6d/hello.c,v
retrieving revision 1.21
diff -u -p -r1.21 hello.c
--- hello.c 23 Dec 2019 11:25:41 -  1.21
+++ hello.c 2 Jan 2020 16:11:19 -
@@ -41,8 +41,6 @@ send_hello(struct iface *iface)
struct hello_hdr hello;
struct nbr  *nbr;
struct ibuf *buf;
-   int  ret;
-   u_int32_topts;
 
switch (iface->type) {
case IF_TYPE_POINTOPOINT:
@@ -72,10 +70,8 @@ send_hello(struct iface *iface)
/* hello header */
hello.iface_id = htonl(iface->ifindex);
LSA_24_SETHI(hello.opts, iface->priority);
-   opts = area_ospf_options(iface->area);
-   LSA_24_SETLO(hello.opts, opts);
+   LSA_24_SETLO(hello.opts, area_ospf_options(iface->area));
hello.opts = htonl(hello.opts);
-
hello.hello_interval = htons(iface->hello_interval);
hello.rtr_dead_interval = htons(iface->dead_interval);
 
@@ -104,10 +100,11 @@ send_hello(struct iface *iface)
if (upd_ospf_hdr(buf, iface))
goto fail;
 
-   ret = send_packet(iface, buf, );
+   if (send_packet(iface, buf, ) == -1)
+   goto fail;
 
ibuf_free(buf);
-   return (ret);
+   return (0);
 fail:
log_warn("send_hello");
ibuf_free(buf);
@@ -120,7 +117,6 @@ recv_hello(struct iface *iface, struct i
 {
struct hello_hdr hello;
struct nbr  *nbr = NULL, *dr;
-   struct area *area;
u_int32_tnbr_id, opts;
int  nbr_change = 0;
 
@@ -148,12 +144,9 @@ recv_hello(struct iface *iface, struct i
return;
}
 
-   if ((area = iface->area) == NULL)
-   fatalx("interface lost area");
-
opts = LSA_24_GETLO(ntohl(hello.opts));
-   if ((opts & OSPF_OPTION_E && area->stub) ||
-   ((opts & OSPF_OPTION_E) == 0 && !area->stub)) {
+   if ((opts & OSPF_OPTION_E && iface->area->stub) ||
+   ((opts & OSPF_OPTION_E) == 0 && !iface->area->stub)) {
log_warnx("recv_hello: ExternalRoutingCapability mismatch, "
"interface %s", iface->name);
return;
@@ -161,8 +154,15 @@ recv_hello(struct iface *iface, struct i
 
/* match router-id */
LIST_FOREACH(nbr, >nbr_list, entry) {
-   if (nbr == iface->self)
+   if (nbr == iface->self) {
+   if (nbr->id.s_addr == rtr_id) {
+   log_warnx("recv_hello: Router-ID collision on "
+   "interface %s neighbor IP %s", iface->name,
+   log_in6addr(src));
+   return;
+   }
continue;
+   }
if (nbr->id.s_addr == rtr_id)
break;
}



ospf6d: sync database.c with ospfd(8)

2020-01-02 Thread Denis Fondras
This is mostly log messages sync.

Index: database.c
===
RCS file: /cvs/src/usr.sbin/ospf6d/database.c,v
retrieving revision 1.18
diff -u -p -r1.18 database.c
--- database.c  23 Dec 2019 07:33:49 -  1.18
+++ database.c  2 Jan 2020 14:31:46 -
@@ -43,7 +43,6 @@ send_db_description(struct nbr *nbr)
struct db_dscrp_hdr  dd_hdr;
struct lsa_entry*le, *nle;
struct ibuf *buf;
-   int  ret = 0;
u_int8_t bits = 0;
 
if ((buf = ibuf_open(nbr->iface->mtu - sizeof(struct ip6_hdr))) == NULL)
@@ -63,11 +62,10 @@ send_db_description(struct nbr *nbr)
case NBR_STA_INIT:
case NBR_STA_2_WAY:
case NBR_STA_SNAP:
-   log_debug("send_db_description: cannot send packet in state %s,"
-   " neighbor ID %s", nbr_state_name(nbr->state),
-   inet_ntoa(nbr->id));
-   ret = -1;
-   goto done;
+   log_debug("send_db_description: neighbor ID %s: "
+   "cannot send packet in state %s", inet_ntoa(nbr->id),
+   nbr_state_name(nbr->state));
+   goto fail;
case NBR_STA_XSTRT:
bits |= OSPF_DBD_MS | OSPF_DBD_M | OSPF_DBD_I;
nbr->dd_more = 1;
@@ -90,7 +88,7 @@ send_db_description(struct nbr *nbr)
 
/* build LSA list */
for (le = TAILQ_FIRST(>db_sum_list); le != NULL &&
-   buf->wpos + sizeof(struct lsa_hdr) < buf->max; le = nle) {
+   ibuf_left(buf) >=  sizeof(struct lsa_hdr); le = nle) {
nbr->dd_end = nle = TAILQ_NEXT(le, entry);
if (ibuf_add(buf, le->le_lsa, sizeof(struct lsa_hdr)))
goto fail;
@@ -146,10 +144,11 @@ send_db_description(struct nbr *nbr)
goto fail;
 
/* transmit packet */
-   ret = send_packet(nbr->iface, buf, );
-done:
+   if (send_packet(nbr->iface, buf, ) == -1)
+   goto fail;
+
ibuf_free(buf);
-   return (ret);
+   return (0);
 fail:
log_warn("send_db_description");
ibuf_free(buf);
@@ -163,8 +162,8 @@ recv_db_description(struct nbr *nbr, cha
int  dupe = 0;
 
if (len < sizeof(dd_hdr)) {
-   log_warnx("recv_db_description: "
-   "bad packet size, neighbor ID %s", inet_ntoa(nbr->id));
+   log_warnx("recv_db_description: neighbor ID %s: "
+   "bad packet size", inet_ntoa(nbr->id));
return;
}
memcpy(_hdr, buf, sizeof(dd_hdr));
@@ -173,9 +172,9 @@ recv_db_description(struct nbr *nbr, cha
 
/* db description packet sanity checks */
if (ntohs(dd_hdr.iface_mtu) > nbr->iface->mtu) {
-   log_warnx("recv_db_description: invalid MTU %d sent by "
-   "neighbor ID %s, expected %d", ntohs(dd_hdr.iface_mtu),
-   inet_ntoa(nbr->id), nbr->iface->mtu);
+   log_warnx("recv_db_description: neighbor ID %s: "
+   "invalid MTU %d expected %d", inet_ntoa(nbr->id),
+   ntohs(dd_hdr.iface_mtu), nbr->iface->mtu);
return;
}
 
@@ -183,7 +182,7 @@ recv_db_description(struct nbr *nbr, cha
nbr->last_rx_bits == dd_hdr.bits &&
ntohl(dd_hdr.dd_seq_num) == nbr->dd_seq_num - nbr->dd_master ?
1 : 0) {
-   log_debug("recv_db_description: dupe from ID %s",
+   log_debug("recv_db_description: dupe from neighbor ID %s",
inet_ntoa(nbr->id));
dupe = 1;
}
@@ -193,9 +192,9 @@ recv_db_description(struct nbr *nbr, cha
case NBR_STA_ATTEMPT:
case NBR_STA_2_WAY:
case NBR_STA_SNAP:
-   log_debug("recv_db_description: packet ignored in state %s, "
-   "neighbor ID %s", nbr_state_name(nbr->state),
-   inet_ntoa(nbr->id));
+   log_debug("recv_db_description: neighbor ID %s: "
+   "packet ignored in state %s", inet_ntoa(nbr->id),
+   nbr_state_name(nbr->state));
return;
case NBR_STA_INIT:
/* evaluate dr and bdr after issuing a 2-Way event */
@@ -224,9 +223,11 @@ recv_db_description(struct nbr *nbr, cha
} else if (!(dd_hdr.bits & (OSPF_DBD_I | OSPF_DBD_MS))) {
/* M only case: we are master */
if (ntohl(dd_hdr.dd_seq_num) != nbr->dd_seq_num) {
-   log_warnx("recv_db_description: invalid "
-   "seq num, mine %x his %x",
-   nbr->dd_seq_num, ntohl(dd_hdr.dd_seq_num));
+   log_warnx("recv_db_description: "
+   

ospf6d: control.c cleanup

2019-12-31 Thread Denis Fondras
Nothing fancy here, just some cleaning work.


Index: control.c
===
RCS file: /cvs/src/usr.sbin/ospf6d/control.c,v
retrieving revision 1.27
diff -u -p -r1.27 control.c
--- control.c   1 Sep 2018 19:21:10 -   1.27
+++ control.c   31 Dec 2019 16:57:07 -
@@ -64,7 +64,6 @@ control_check(char *path)
return (0);
 }
 
-
 int
 control_init(char *path)
 {
@@ -127,10 +126,11 @@ control_listen(void)
 void
 control_cleanup(char *path)
 {
+   if (path == NULL)
+   return;
event_del(_state.ev);
event_del(_state.evt);
-   if (path)
-   unlink(path);
+   unlink(path);
 }
 
 /* ARGSUSED */
@@ -237,7 +237,7 @@ control_dispatch_imsg(int fd, short even
 {
struct ctl_conn *c;
struct imsg  imsg;
-   int  n;
+   ssize_t  n;
unsigned int ifidx;
int  verbose;
 
@@ -289,7 +289,7 @@ control_dispatch_imsg(int fd, short even
sizeof(ifidx)) {
memcpy(, imsg.data, sizeof(ifidx));
ospfe_iface_ctl(c, ifidx);
-   imsg_compose(>iev.ibuf, IMSG_CTL_END, 0,
+   imsg_compose_event(>iev, IMSG_CTL_END, 0,
0, -1, NULL, 0);
}
break;
Index: ospfe.c
===
RCS file: /cvs/src/usr.sbin/ospf6d/ospfe.c,v
retrieving revision 1.59
diff -u -p -r1.59 ospfe.c
--- ospfe.c 28 Dec 2019 09:25:24 -  1.59
+++ ospfe.c 31 Dec 2019 16:57:07 -
@@ -175,10 +175,6 @@ ospfe(struct ospfd_conf *xconf, int pipe
/* remove unneeded config stuff */
conf_clear_redist_list(>redist_list);
 
-   /* listen on ospfd control socket */
-   TAILQ_INIT(_conns);
-   control_listen();
-
if ((pkt_ptr = calloc(1, READ_BUF_SIZE)) == NULL)
fatal("ospfe");
 



Re: bgpd, fairer imsg processing

2019-12-31 Thread Denis Fondras
On Mon, Dec 30, 2019 at 06:35:28PM +0100, Claudio Jeker wrote:
> The imsg processing in the RDE is sometimes a bit unfair. The problem is
> that peers sending many UPDATES starve out the others especially on
> intial table dumps. This comes from the fact that imsg are processed to
> completion and so the system sending more just gets more CPU.
> 
> This diff changes this and moves peer specific imsgs to a per peer imsg
> queue where messages are enqueued and later dequeued one at a time.
> This results in a quicker main poll loop since less work is done per read
> operation. Also on startup peers finish their initial sync relative to
> their table size. Additionally a big peer flapping will have less
> influence at the processing speed of other updates or withdraws.
> 
> This can be further optimized but lets keep the diffs small for a change
> :)

OK denis@

> -- 
> :wq Claudio
> 
> Index: Makefile
> ===
> RCS file: /cvs/src/usr.sbin/bgpd/Makefile,v
> retrieving revision 1.35
> diff -u -p -r1.35 Makefile
> --- Makefile  17 Jun 2019 11:02:19 -  1.35
> +++ Makefile  30 Dec 2019 12:30:18 -
> @@ -5,7 +5,7 @@ SRCS= bgpd.c session.c log.c logmsg.c pa
>   rde.c rde_rib.c rde_decide.c rde_prefix.c mrt.c kroute.c control.c \
>   pfkey.c rde_update.c rde_attr.c rde_community.c printconf.c \
>   rde_filter.c rde_sets.c rde_trie.c pftable.c name2id.c \
> - util.c carp.c timer.c
> + util.c carp.c timer.c rde_peer.c
>  CFLAGS+= -Wall -I${.CURDIR}
>  CFLAGS+= -Wstrict-prototypes -Wmissing-prototypes
>  CFLAGS+= -Wmissing-declarations
> Index: rde.c
> ===
> RCS file: /cvs/src/usr.sbin/bgpd/rde.c,v
> retrieving revision 1.493
> diff -u -p -r1.493 rde.c
> --- rde.c 16 Dec 2019 10:35:02 -  1.493
> +++ rde.c 30 Dec 2019 14:01:58 -
> @@ -49,6 +49,7 @@
>  void  rde_sighdlr(int);
>  void  rde_dispatch_imsg_session(struct imsgbuf *);
>  void  rde_dispatch_imsg_parent(struct imsgbuf *);
> +void  rde_dispatch_imsg_peer(struct rde_peer *, void *);
>  void  rde_update_dispatch(struct rde_peer *, struct imsg *);
>  int   rde_update_update(struct rde_peer *, struct filterstate *,
>struct bgpd_addr *, u_int8_t);
> @@ -95,6 +96,8 @@ u_int8_t rde_roa_validity(struct rde_pr
>  
>  void  peer_init(u_int32_t);
>  void  peer_shutdown(void);
> +void  peer_foreach(void (*)(struct rde_peer *, void *), void *);
> +int   peer_imsg_pending(void);
>  int   peer_localaddrs(struct rde_peer *, struct bgpd_addr *);
>  struct rde_peer *peer_match(struct ctl_neighbor *, u_int32_t);
>  struct rde_peer  *peer_add(u_int32_t, struct peer_config *);
> @@ -266,7 +269,7 @@ rde_main(int debug, int verbose)
>   }
>  
>   if (rib_dump_pending() || rde_update_queue_pending() ||
> - nexthop_pending())
> + nexthop_pending() || peer_imsg_pending())
>   timeout = 0;
>  
>   if (poll(pfd, i, timeout) == -1) {
> @@ -305,6 +308,7 @@ rde_main(int debug, int verbose)
>   mctx = LIST_NEXT(mctx, entry);
>   }
>  
> + peer_foreach(rde_dispatch_imsg_peer, NULL);
>   rib_dump_runner();
>   nexthop_runner();
>   if (ibuf_se && ibuf_se->w.queued < SESS_MSG_HIGH_MARK) {
> @@ -358,7 +362,6 @@ rde_dispatch_imsg_session(struct imsgbuf
>   struct imsg  imsg;
>   struct peer  p;
>   struct peer_config   pconf;
> - struct session_upsup;
>   struct ctl_show_rib  csr;
>   struct ctl_show_rib_request req;
>   struct rde_peer *peer;
> @@ -370,7 +373,6 @@ rde_dispatch_imsg_session(struct imsgbuf
>   size_t   aslen;
>   int  verbose;
>   u_int16_tlen;
> - u_int8_t aid;
>  
>   while (ibuf) {
>   if ((n = imsg_get(ibuf, )) == -1)
> @@ -380,106 +382,24 @@ rde_dispatch_imsg_session(struct imsgbuf
>  
>   switch (imsg.hdr.type) {
>   case IMSG_UPDATE:
> - if ((peer = peer_get(imsg.hdr.peerid)) == NULL) {
> - log_warnx("rde_dispatch: unknown peer id %d",
> - imsg.hdr.peerid);
> - break;
> - }
> - rde_update_dispatch(peer, );
> - break;
> - case IMSG_SESSION_ADD:
> - if (imsg.hdr.len - IMSG_HEADER_SIZE != sizeof(pconf))
> - fatalx("incorrect size of session request");
> - memcpy(, imsg.data, sizeof(pconf));
> - peer_add(imsg.hdr.peerid, );
> - break;
>  

ospf6d: remove useless orig_rtr_lsa()

2019-12-31 Thread Denis Fondras
Rename orig_rtr_lsa_area() to orig_rtr_lsa()

Now that area is part of iface, original orig_rtr_lsa() is useless. Also
verifying that area != NULL is not needed in some cases (these are leftovers of
the previous diff).


Index: interface.c
===
RCS file: /cvs/src/usr.sbin/ospf6d/interface.c,v
retrieving revision 1.27
diff -u -p -r1.27 interface.c
--- interface.c 23 Dec 2019 07:33:49 -  1.27
+++ interface.c 31 Dec 2019 12:44:15 -
@@ -144,7 +144,7 @@ if_fsm(struct iface *iface, enum iface_e
 
if (iface->state != old_state) {
area_track(iface->area);
-   orig_rtr_lsa(iface);
+   orig_rtr_lsa(iface->area);
orig_link_lsa(iface);
 
/* state change inform RDE */
@@ -395,7 +395,7 @@ if_act_start(struct iface *iface)
 
if (iface->cflags & F_IFACE_PASSIVE) {
/* for an update of stub network entries */
-   orig_rtr_lsa(iface);
+   orig_rtr_lsa(iface->area);
return (0);
}
 
@@ -569,7 +569,7 @@ start:
nbr_fsm(nbr, NBR_EVT_ADJ_OK);
}
 
-   orig_rtr_lsa(iface);
+   orig_rtr_lsa(iface->area);
if (iface->state & IF_STA_DR || old_state & IF_STA_DR)
orig_net_lsa(iface);
}
@@ -586,7 +586,7 @@ if_act_reset(struct iface *iface)
 
if (iface->cflags & F_IFACE_PASSIVE) {
/* for an update of stub network entries */
-   orig_rtr_lsa(iface);
+   orig_rtr_lsa(iface->area);
return (0);
}
 
Index: neighbor.c
===
RCS file: /cvs/src/usr.sbin/ospf6d/neighbor.c,v
retrieving revision 1.15
diff -u -p -r1.15 neighbor.c
--- neighbor.c  23 Dec 2019 07:33:49 -  1.15
+++ neighbor.c  31 Dec 2019 12:44:15 -
@@ -202,7 +202,7 @@ nbr_fsm(struct nbr *nbr, enum nbr_event 
 * neighbor changed from/to FULL
 * originate new rtr and net LSA
 */
-   orig_rtr_lsa(nbr->iface);
+   orig_rtr_lsa(nbr->iface->area);
if (nbr->iface->state & IF_STA_DR)
orig_net_lsa(nbr->iface);
 
@@ -226,7 +226,7 @@ nbr_fsm(struct nbr *nbr, enum nbr_event 
nbr_state_name(nbr->state));
 
if (nbr->iface->type == IF_TYPE_VIRTUALLINK) {
-   orig_rtr_lsa(nbr->iface);
+   orig_rtr_lsa(nbr->iface->area);
}
}
 
Index: ospf6d.c
===
RCS file: /cvs/src/usr.sbin/ospf6d/ospf6d.c,v
retrieving revision 1.45
diff -u -p -r1.45 ospf6d.c
--- ospf6d.c16 Dec 2019 08:28:33 -  1.45
+++ ospf6d.c31 Dec 2019 12:44:15 -
@@ -741,7 +741,7 @@ merge_config(struct ospfd_conf *conf, st
}
if (a->dirty) {
a->dirty = 0;
-   orig_rtr_lsa(LIST_FIRST(>iface_list));
+   orig_rtr_lsa(LIST_FIRST(>iface_list)->area);
}
}
}
Index: ospfe.c
===
RCS file: /cvs/src/usr.sbin/ospf6d/ospfe.c,v
retrieving revision 1.59
diff -u -p -r1.59 ospfe.c
--- ospfe.c 28 Dec 2019 09:25:24 -  1.59
+++ ospfe.c 31 Dec 2019 12:44:15 -
@@ -45,7 +45,6 @@
 voidospfe_sig_handler(int, short, void *);
 __dead void ospfe_shutdown(void);
 voidorig_rtr_lsa_all(struct area *);
-voidorig_rtr_lsa_area(struct area *);
 struct iface   *find_vlink(struct abr_rtr *);
 
 struct ospfd_conf  *oeconf = NULL, *nconf;
@@ -301,7 +300,7 @@ ospfe_dispatch_main(int fd, short event,
i->depend_ok =
ifstate_is_up(ifp);
if (ifstate_is_up(i))
-   orig_rtr_lsa(i);
+   orig_rtr_lsa(i->area);
}
}
}
@@ -600,8 +599,6 @@ ospfe_dispatch_rde(int fd, short event, 
 * flood on all area interfaces on
 * area 0.0.0.0 include also virtual links.
 */
-   if (nbr->iface->area == NULL)
-   fatalx("interface lost area");
LIST_FOREACH(iface,
>iface->area->iface_list, entry) {
 

ospf6d: refactor link state ack/req

2019-12-24 Thread Denis Fondras
Refactor link state ack/req in ospf6d so it looks closer to ospfd.

Index: lsack.c
===
RCS file: /cvs/src/usr.sbin/ospf6d/lsack.c,v
retrieving revision 1.7
diff -u -p -r1.7 lsack.c
--- lsack.c 11 Dec 2019 21:33:56 -  1.7
+++ lsack.c 24 Dec 2019 20:51:56 -
@@ -19,7 +19,7 @@
 #include 
 #include 
 #include 
-#include 
+#include 
 #include 
 
 #include 
@@ -30,39 +30,66 @@
 #include "log.h"
 #include "ospfe.h"
 
-voidstart_ls_ack_tx_timer_now(struct iface *);
+int send_ls_ack(struct iface *, struct in6_addr, struct ibuf *);
+struct ibuf*prepare_ls_ack(struct iface *);
+voidstart_ls_ack_tx_timer_now(struct iface *);
 
 /* link state acknowledgement packet handling */
-int
-send_ls_ack(struct iface *iface, struct in6_addr addr, void *data, size_t len)
+struct ibuf *
+prepare_ls_ack(struct iface *iface)
 {
struct ibuf *buf;
-   int  ret;
 
-   /* XXX IBUF_READ_SIZE */
-   if ((buf = ibuf_dynamic(PKG_DEF_SIZE, IBUF_READ_SIZE)) == NULL)
-   fatal("send_ls_ack");
+   if ((buf = ibuf_open(iface->mtu - sizeof(struct ip6_hdr))) == NULL) {
+   log_warn("prepare_ls_ack");
+   return (NULL);
+   }
 
/* OSPF header */
-   if (gen_ospf_hdr(buf, iface, PACKET_TYPE_LS_ACK))
-   goto fail;
+   if (gen_ospf_hdr(buf, iface, PACKET_TYPE_LS_ACK)) {
+   log_warn("prepare_ls_ack");
+   ibuf_free(buf);
+   return (NULL);
+   }
 
-   /* LS ack(s) */
-   if (ibuf_add(buf, data, len))
-   goto fail;
+   return (buf);
+}
 
+int
+send_ls_ack(struct iface *iface, struct in6_addr addr, struct ibuf *buf)
+{
/* calculate checksum */
-   if (upd_ospf_hdr(buf, iface))
-   goto fail;
+   if (upd_ospf_hdr(buf, iface)) {
+   log_warn("send_ls_ack");
+   return (-1);
+   }
 
-   ret = send_packet(iface, buf, );
+   if (send_packet(iface, buf, ) == -1) {
+   log_warn("send_ls_ack");
+   return (-1);
+   }
+   return (0);
+}
 
+int
+send_direct_ack(struct iface *iface, struct in6_addr addr, void *d, size_t len)
+{
+   struct ibuf *buf;
+   int  ret;
+
+   if ((buf = prepare_ls_ack(iface)) == NULL)
+   return (-1);
+
+   /* LS ack(s) */
+   if (ibuf_add(buf, d, len)) {
+   log_warn("send_direct_ack");
+   ibuf_free(buf);
+   return (-1);
+   }
+
+   ret = send_ls_ack(iface, addr, buf);
ibuf_free(buf);
return (ret);
-fail:
-   log_warn("send_ls_ack");
-   ibuf_free(buf);
-   return (-1);
 }
 
 void
@@ -207,41 +234,44 @@ ls_ack_tx_timer(int fd, short event, voi
 {
struct in6_addr  addr;
struct iface*iface = arg;
-   struct lsa_hdr  *lsa_hdr;
struct lsa_entry*le, *nle;
struct nbr  *nbr;
-   char*buf;
-   char*ptr;
-   int  cnt = 0;
-
-   if ((buf = calloc(1, READ_BUF_SIZE)) == NULL)
-   fatal("ls_ack_tx_timer");
+   struct ibuf *buf;
+   int  cnt;
 
while (!ls_ack_list_empty(iface)) {
-   ptr = buf;
+   if ((buf = prepare_ls_ack(iface)) == NULL)
+   fatal("ls_ack_tx_timer");
cnt = 0;
-   for (le = TAILQ_FIRST(>ls_ack_list); le != NULL &&
-   (ptr - buf < iface->mtu - PACKET_HDR); le = nle) {
+
+   for (le = TAILQ_FIRST(>ls_ack_list); le != NULL;
+   le = nle) {
nle = TAILQ_NEXT(le, entry);
-   memcpy(ptr, le->le_lsa, sizeof(struct lsa_hdr));
-   ptr += sizeof(*lsa_hdr);
+   if (ibuf_left(buf) < sizeof(struct lsa_hdr))
+   break;
+   if (ibuf_add(buf, le->le_lsa, sizeof(struct lsa_hdr)))
+   break;
ls_ack_list_free(iface, le);
cnt++;
}
+   if (cnt == 0) {
+   log_warnx("ls_ack_tx_timer: lost in space");
+   ibuf_free(buf);
+   return;
+   }
 
/* send LS ack(s) but first set correct destination */
switch (iface->type) {
case IF_TYPE_POINTOPOINT:
inet_pton(AF_INET6, AllSPFRouters, );
-   send_ls_ack(iface, addr, buf, ptr - buf);
+   send_ls_ack(iface, addr, buf);
break;
case IF_TYPE_BROADCAST:
if (iface->state & IF_STA_DRORBDR)
  

Re: ospf6d: type p2p

2019-12-24 Thread Denis Fondras
On Mon, Dec 23, 2019 at 11:09:42PM +0100, Remi Locherer wrote:
> Hi,
> 
> this brings support for interface "type p2p" to ospf6d (ospfd got it a few
> weeks ago).
> 
> The configuration looks like this:
> 
> area 0.0.0.0 {
>   interface em0 {
>   type p2p
>   }
> }
> 
> OK?
> 

OK denis@

> Remi
> 
> 
> Index: ospf6d.conf.5
> ===
> RCS file: /cvs/src/usr.sbin/ospf6d/ospf6d.conf.5,v
> retrieving revision 1.19
> diff -u -p -r1.19 ospf6d.conf.5
> --- ospf6d.conf.5 26 May 2019 09:27:09 -  1.19
> +++ ospf6d.conf.5 5 Oct 2019 14:17:29 -
> @@ -328,6 +328,9 @@ Router.
>  .It Ic transmit-delay Ar seconds
>  Set the transmit delay.
>  The default value is 1; valid range is 1\-3600 seconds.
> +.It Ic type p2p
> +Set the interface type to point to point.
> +This disables the election of a DR and BDR for the given interface.
>  .El
>  .Sh FILES
>  .Bl -tag -width "/etc/ospf6d.conf" -compact
> Index: ospf6d.h
> ===
> RCS file: /cvs/src/usr.sbin/ospf6d/ospf6d.h,v
> retrieving revision 1.42
> diff -u -p -r1.42 ospf6d.h
> --- ospf6d.h  23 Dec 2019 07:33:49 -  1.42
> +++ ospf6d.h  23 Dec 2019 09:08:23 -
> @@ -329,6 +329,7 @@ struct iface {
>   u_int8_t if_type;
>   u_int8_t linkstate;
>   u_int8_t priority;
> + u_int8_t p2p;
>   u_int8_t cflags;
>  #define F_IFACE_PASSIVE  0x01
>  #define F_IFACE_CONFIGURED   0x02
> Index: parse.y
> ===
> RCS file: /cvs/src/usr.sbin/ospf6d/parse.y,v
> retrieving revision 1.47
> diff -u -p -r1.47 parse.y
> --- parse.y   23 Dec 2019 07:33:49 -  1.47
> +++ parse.y   23 Dec 2019 10:40:28 -
> @@ -126,7 +126,7 @@ typedef struct {
>  
>  %token   AREA INTERFACE ROUTERID FIBPRIORITY FIBUPDATE REDISTRIBUTE 
> RTLABEL
>  %token   RDOMAIN STUB ROUTER SPFDELAY SPFHOLDTIME EXTTAG
> -%token   METRIC PASSIVE
> +%token   METRIC P2P PASSIVE
>  %token   HELLOINTERVAL TRANSMITDELAY
>  %token   RETRANSMITINTERVAL ROUTERDEADTIME ROUTERPRIORITY
>  %token   SET TYPE
> @@ -566,6 +566,10 @@ interfaceopts_l  : interfaceopts_l interf
>   ;
>  
>  interfaceoptsl   : PASSIVE   { iface->cflags |= 
> F_IFACE_PASSIVE; }
> + | TYPE P2P  {
> + iface->p2p = 1;
> + iface->type = IF_TYPE_POINTOPOINT;
> + }
>   | DEMOTE STRING {
>   if (strlcpy(iface->demote_group, $2,
>   sizeof(iface->demote_group)) >=
> @@ -645,6 +649,7 @@ lookup(char *s)
>   {"metric",  METRIC},
>   {"no",  NO},
>   {"on",  ON},
> + {"p2p", P2P},
>   {"passive", PASSIVE},
>   {"rdomain", RDOMAIN},
>   {"redistribute",REDISTRIBUTE},
> Index: printconf.c
> ===
> RCS file: /cvs/src/usr.sbin/ospf6d/printconf.c,v
> retrieving revision 1.8
> diff -u -p -r1.8 printconf.c
> --- printconf.c   29 Dec 2018 16:04:31 -  1.8
> +++ printconf.c   5 Oct 2019 14:14:19 -
> @@ -135,6 +135,9 @@ print_iface(struct iface *iface)
>   printf("\t\trouter-priority %d\n", iface->priority);
>   printf("\t\ttransmit-delay %d\n", iface->transmit_delay);
>  
> + if (iface->p2p)
> + printf("\t\ttype p2p\n");
> +
>   printf("\t}\n");
>  }
>  
> 



Re: ospf6d: add basic regress tests

2019-12-23 Thread Denis Fondras
On Mon, Dec 23, 2019 at 03:53:23PM +0100, Claudio Jeker wrote:
> On Mon, Dec 23, 2019 at 03:24:31PM +0100, Remi Locherer wrote:
> > On Sun, Dec 22, 2019 at 08:36:41PM +0100, Denis Fondras wrote:
> > > Add basic regress test to ospf6d.
> > 
> > Works for me. OK remi@
> > 
> > The tests also succeed when I reduce the sleep from 120 to 60.
> > A few lines end with a space. I marked them below.
> 
> I would suggest to minimize hold times etc. and reduce the timeout as
> much as possible. Regress test should not wait uneccessary long.
> 

Thank you guys. sleep 50s is the best I have come with so far.


> > > 
> > > Index: ospf6d/Makefile
> > > ===
> > > RCS file: ospf6d/Makefile
> > > diff -N ospf6d/Makefile
> > > --- /dev/null 1 Jan 1970 00:00:00 -
> > > +++ ospf6d/Makefile   22 Dec 2019 19:27:27 -
> > > @@ -0,0 +1,10 @@
> > > +# $OpenBSD$
> > > +
> > > +REGRESS_TARGETS  =   network_statement
> > > +
> > > +OSPF6D ?=/usr/sbin/ospf6d
> > > +
> > > +network_statement:
> > > + ${SUDO} ksh ${.CURDIR}/$@.sh ${OSPF6D} ${.CURDIR} 11 12 pair11 pair12
> > > +
> > > +.include 
> > > Index: ospf6d/network_statement.sh
> > > ===
> > > RCS file: ospf6d/network_statement.sh
> > > diff -N ospf6d/network_statement.sh
> > > --- /dev/null 1 Jan 1970 00:00:00 -
> > > +++ ospf6d/network_statement.sh   22 Dec 2019 19:27:27 -
> > > @@ -0,0 +1,107 @@
> > > +#!/bin/ksh
> > > +#$OpenBSD$
> > > +set -e
> > > +
> > > +OSPF6D=$1
> > > +OSPF6DCONFIGDIR=$2
> > > +RDOMAIN1=$3
> > > +RDOMAIN2=$4
> > > +PAIR1=$5
> > > +PAIR2=$6
> > > +
> > > +RDOMAINS="${RDOMAIN1} ${RDOMAIN2}"
> > > +PAIRS="${PAIR1} ${PAIR2}"
> > > +PAIR1IP=2001:db8::${RDOMAIN1}
> > > +PAIR2IP=2001:db8::${RDOMAIN2}
> > > +PAIR1PREFIX=2001:db8:${RDOMAIN1}::
> > > +PAIR2PREFIX=2001:db8:${RDOMAIN2}::
> > > +PAIR2PREFIX2=2001:db8:${RDOMAIN2}:${RDOMAIN2}::
> > > +
> > > +error_notify() {
> > > + echo cleanup
> > > + pkill -T ${RDOMAIN1} ospf6d || true
> > > + pkill -T ${RDOMAIN2} ospf6d || true
> > > + sleep 1
> > > + ifconfig ${PAIR2} destroy || true
> > > + ifconfig ${PAIR1} destroy || true
> > > + ifconfig vether${RDOMAIN1} destroy || true
> > > + ifconfig vether${RDOMAIN2} destroy || true
> > > + route -qn -T ${RDOMAIN1} flush || true
> > > + route -qn -T ${RDOMAIN2} flush || true
> > > + ifconfig lo${RDOMAIN1} destroy || true
> > > + ifconfig lo${RDOMAIN2} destroy || true
> > > + rm ospf6d.1.conf ospf6d.2.conf
> > > + if [ $1 -ne 0 ]; then
> > > + echo FAILED
> > > + exit 1
> > > + else
> > > + echo SUCCESS
> > > + fi
> > > +}
> > > +
> > > +if [ "$(id -u)" -ne 0 ]; then 
> > ^
> > 
> > > + echo need root privileges >&2
> > > + exit 1
> > > +fi
> > > +
> > > +trap 'error_notify $?' EXIT
> > > +
> > > +echo check if rdomains are busy
> > > +for n in ${RDOMAINS}; do
> > > + if /sbin/ifconfig | grep -v "^lo${n}:" | grep " rdomain ${n} "; then
> > > + echo routing domain ${n} is already used >&2
> > > + exit 1
> > > + fi
> > > +done
> > > +
> > > +echo check if interfaces are busy
> > > +for n in ${PAIRS}; do
> > > + /sbin/ifconfig "${n}" >/dev/null 2>&1 && \
> > > + ( echo interface ${n} is already used >&2; exit 1 )
> > > +done
> > > +
> > > +set -x
> > > +
> > > +echo setup
> > > +ifconfig ${PAIR1} inet6 rdomain ${RDOMAIN1} ${PAIR1IP}/64 up
> > > +ifconfig ${PAIR2} inet6 rdomain ${RDOMAIN2} ${PAIR2IP}/64 up
> > > +ifconfig ${PAIR1} patch ${PAIR2}
> > > +ifconfig lo${RDOMAIN1} inet 127.0.0.1/8
> > > +ifconfig lo${RDOMAIN2} inet 127.0.0.1/8
> > > +ifconfig vether${RDOMAIN1} inet6 rdomain ${RDOMAIN1} ${PAIR1PREFIX}/64 up
> > > +ifconfig vether${RDOMAIN2} inet6 rdomain ${RDOMAIN2} ${PAIR2PREFIX}/64 up
> > > +ifconfig vether${RDOMAIN2} inet6 rdomain ${RDOMAIN2} ${PAIR2PREFIX2}/64 
&g

Re: ospf6d: warn when a neighbor changes its source address

2019-12-22 Thread Denis Fondras
On Sun, Dec 22, 2019 at 10:06:40PM +0100, Remi Locherer wrote:
> this is similar to ospfd's hello.c rev 1.23.
> 
> OK?
> 
> Remi
> 
> 
> Index: hello.c
> ===
> RCS file: /cvs/src/usr.sbin/ospf6d/hello.c,v
> retrieving revision 1.19
> diff -u -p -r1.19 hello.c
> --- hello.c   11 Dec 2019 21:33:56 -  1.19
> +++ hello.c   22 Dec 2019 20:46:01 -
> @@ -173,10 +173,16 @@ recv_hello(struct iface *iface, struct i
>   nbr->dr.s_addr = hello.d_rtr;
>   nbr->bdr.s_addr = hello.bd_rtr;
>   nbr->priority = LSA_24_GETHI(ntohl(hello.opts));
> + /* XXX neighbor address shouldn't be stored on virtual links */
> + nbr->addr = *src;
> + }
> +
> + if (memcmp(>addr, src, sizeof(struct in6_addr)) != 0) {

Can you use IN6_ARE_ADDR_EQUAL() macro instead of memcmp() to be consistent with
other address comparison ?

Otherwise OK denis@

> + log_warnx("%s: neighbor ID %s changed its address to %s",
> + __func__, inet_ntoa(nbr->id), log_in6addr(src));
> + nbr->addr = *src;
>   }
>  
> - /* actually the neighbor address shouldn't be stored on virtual links */
> - nbr->addr = *src;
>   nbr->options = opts;
>  
>   nbr_fsm(nbr, NBR_EVT_HELLO_RCVD);
> 



ospf6d: add basic regress tests

2019-12-22 Thread Denis Fondras
Add basic regress test to ospf6d.

Index: ospf6d/Makefile
===
RCS file: ospf6d/Makefile
diff -N ospf6d/Makefile
--- /dev/null   1 Jan 1970 00:00:00 -
+++ ospf6d/Makefile 22 Dec 2019 19:27:27 -
@@ -0,0 +1,10 @@
+# $OpenBSD$
+
+REGRESS_TARGETS=   network_statement
+
+OSPF6D ?=  /usr/sbin/ospf6d
+
+network_statement:
+   ${SUDO} ksh ${.CURDIR}/$@.sh ${OSPF6D} ${.CURDIR} 11 12 pair11 pair12
+
+.include 
Index: ospf6d/network_statement.sh
===
RCS file: ospf6d/network_statement.sh
diff -N ospf6d/network_statement.sh
--- /dev/null   1 Jan 1970 00:00:00 -
+++ ospf6d/network_statement.sh 22 Dec 2019 19:27:27 -
@@ -0,0 +1,107 @@
+#!/bin/ksh
+#  $OpenBSD$
+set -e
+
+OSPF6D=$1
+OSPF6DCONFIGDIR=$2
+RDOMAIN1=$3
+RDOMAIN2=$4
+PAIR1=$5
+PAIR2=$6
+
+RDOMAINS="${RDOMAIN1} ${RDOMAIN2}"
+PAIRS="${PAIR1} ${PAIR2}"
+PAIR1IP=2001:db8::${RDOMAIN1}
+PAIR2IP=2001:db8::${RDOMAIN2}
+PAIR1PREFIX=2001:db8:${RDOMAIN1}::
+PAIR2PREFIX=2001:db8:${RDOMAIN2}::
+PAIR2PREFIX2=2001:db8:${RDOMAIN2}:${RDOMAIN2}::
+
+error_notify() {
+   echo cleanup
+   pkill -T ${RDOMAIN1} ospf6d || true
+   pkill -T ${RDOMAIN2} ospf6d || true
+   sleep 1
+   ifconfig ${PAIR2} destroy || true
+   ifconfig ${PAIR1} destroy || true
+   ifconfig vether${RDOMAIN1} destroy || true
+   ifconfig vether${RDOMAIN2} destroy || true
+   route -qn -T ${RDOMAIN1} flush || true
+   route -qn -T ${RDOMAIN2} flush || true
+   ifconfig lo${RDOMAIN1} destroy || true
+   ifconfig lo${RDOMAIN2} destroy || true
+   rm ospf6d.1.conf ospf6d.2.conf
+   if [ $1 -ne 0 ]; then
+   echo FAILED
+   exit 1
+   else
+   echo SUCCESS
+   fi
+}
+
+if [ "$(id -u)" -ne 0 ]; then 
+   echo need root privileges >&2
+   exit 1
+fi
+
+trap 'error_notify $?' EXIT
+
+echo check if rdomains are busy
+for n in ${RDOMAINS}; do
+   if /sbin/ifconfig | grep -v "^lo${n}:" | grep " rdomain ${n} "; then
+   echo routing domain ${n} is already used >&2
+   exit 1
+   fi
+done
+
+echo check if interfaces are busy
+for n in ${PAIRS}; do
+   /sbin/ifconfig "${n}" >/dev/null 2>&1 && \
+   ( echo interface ${n} is already used >&2; exit 1 )
+done
+
+set -x
+
+echo setup
+ifconfig ${PAIR1} inet6 rdomain ${RDOMAIN1} ${PAIR1IP}/64 up
+ifconfig ${PAIR2} inet6 rdomain ${RDOMAIN2} ${PAIR2IP}/64 up
+ifconfig ${PAIR1} patch ${PAIR2}
+ifconfig lo${RDOMAIN1} inet 127.0.0.1/8
+ifconfig lo${RDOMAIN2} inet 127.0.0.1/8
+ifconfig vether${RDOMAIN1} inet6 rdomain ${RDOMAIN1} ${PAIR1PREFIX}/64 up
+ifconfig vether${RDOMAIN2} inet6 rdomain ${RDOMAIN2} ${PAIR2PREFIX}/64 up
+ifconfig vether${RDOMAIN2} inet6 rdomain ${RDOMAIN2} ${PAIR2PREFIX2}/64 up
+sed "s/{RDOMAIN1}/${RDOMAIN1}/g;s/{PAIR1}/${PAIR1}/g" \
+ospf6d.network_statement.rdomain1.conf > ospf6d.1.conf
+chmod 0600 ospf6d.1.conf
+sed "s/{RDOMAIN2}/${RDOMAIN2}/g;s/{PAIR2}/${PAIR2}/g" \
+ospf6d.network_statement.rdomain2.conf > ospf6d.2.conf
+chmod 0600 ospf6d.2.conf 
+
+echo add routes
+route -T ${RDOMAIN2} add -inet6 default ${PAIR2PREFIX}1
+route -T ${RDOMAIN2} add 2001:db8:::/126 ${PAIR2PREFIX}2
+route -T ${RDOMAIN2} add 2001:db8:fffe::/64 ${PAIR2PREFIX}3 -label toOSPF
+
+echo start ospf6d
+route -T ${RDOMAIN1} exec ${OSPF6D} \
+-v -f ${OSPF6DCONFIGDIR}/ospf6d.1.conf
+route -T ${RDOMAIN2} exec ${OSPF6D} \
+-v -f ${OSPF6DCONFIGDIR}/ospf6d.2.conf
+
+sleep 120
+
+echo tests
+route -T ${RDOMAIN1} exec ospf6ctl sh fib
+route -T ${RDOMAIN1} exec ospf6ctl sh rib | \
+grep ${PAIR2PREFIX}/64
+route -T ${RDOMAIN1} exec ospf6ctl sh rib | \
+grep ${PAIR2PREFIX2}/64
+route -T ${RDOMAIN1} exec ospf6ctl sh rib | \
+grep "2001:db8:::/126"
+route -T ${RDOMAIN1} exec ospf6ctl sh rib | \
+grep "::/0"
+route -T ${RDOMAIN1} exec ospf6ctl sh rib | \
+grep "2001:db8:fffe::/64"
+
+exit 0
Index: ospf6d/ospf6d.network_statement.rdomain1.conf
===
RCS file: ospf6d/ospf6d.network_statement.rdomain1.conf
diff -N ospf6d/ospf6d.network_statement.rdomain1.conf
--- /dev/null   1 Jan 1970 00:00:00 -
+++ ospf6d/ospf6d.network_statement.rdomain1.conf   22 Dec 2019 19:27:27 
-
@@ -0,0 +1,10 @@
+router-id 1.1.1.1
+rdomain {RDOMAIN1}
+
+fib-priority 62
+
+area 10.0.0.1 {
+   interface lo{RDOMAIN1}
+   interface vether{RDOMAIN1}
+   interface {PAIR1}
+}
Index: ospf6d/ospf6d.network_statement.rdomain2.conf
===
RCS file: ospf6d/ospf6d.network_statement.rdomain2.conf
diff -N ospf6d/ospf6d.network_statement.rdomain2.conf
--- /dev/null   1 Jan 1970 00:00:00 -
+++ ospf6d/ospf6d.network_statement.rdomain2.conf   22 Dec 2019 19:27:27 
-
@@ -0,0 +1,12 @@
+router-id 2.2.2.2
+rdomain 

ospf6d: add reference to area in struct iface

2019-12-22 Thread Denis Fondras
area is now part of struct iface

Code looks cleaner and more like ospfd.

Index: area.c
===
RCS file: /cvs/src/usr.sbin/ospf6d/area.c,v
retrieving revision 1.4
diff -u -p -r1.4 area.c
--- area.c  28 Dec 2008 20:08:31 -  1.4
+++ area.c  22 Dec 2019 17:18:49 -
@@ -88,19 +88,24 @@ area_find(struct ospfd_conf *conf, struc
 }
 
 void
-area_track(struct area *area, int state)
+area_track(struct area *area)
 {
-   int old = area->active;
+   int  old = area->active;
+   struct iface*iface;
 
-   if (state & NBR_STA_FULL)
-   area->active++;
-   else if (area->active == 0)
-   fatalx("area_track: area already inactive");
-   else
-   area->active--;
-
-   if (area->active == 0 || old == 0)
+   area->active = 0;
+   LIST_FOREACH(iface, >iface_list, entry) {
+   if (iface->state & IF_STA_DOWN)
+   continue;
+   area->active = 1;
+   break;
+   }
+
+   if (area->active != old) {
+   ospfe_imsg_compose_rde(IMSG_AREA_CHANGE, area->id.s_addr, 0,
+   >active, sizeof(area->active));
ospfe_demote_area(area, old == 0);
+   }
 }
 
 int
@@ -110,7 +115,7 @@ area_border_router(struct ospfd_conf *co
int  active = 0;
 
LIST_FOREACH(area, >area_list, entry)
-   if (area->active > 0)
+   if (area->active)
active++;
 
return (active > 1);
@@ -124,5 +129,5 @@ area_ospf_options(struct area *area)
if (area && !area->stub)
opt |= OSPF_OPTION_E;
 
-   return opt;
+   return (opt);
 }
Index: database.c
===
RCS file: /cvs/src/usr.sbin/ospf6d/database.c,v
retrieving revision 1.17
diff -u -p -r1.17 database.c
--- database.c  11 Dec 2019 21:33:56 -  1.17
+++ database.c  22 Dec 2019 17:18:49 -
@@ -134,8 +134,7 @@ send_db_description(struct nbr *nbr)
fatalx("send_db_description: unknown interface type");
}
 
-   dd_hdr.opts = htonl(area_ospf_options(area_find(oeconf,
-   nbr->iface->area_id)));
+   dd_hdr.opts = htonl(area_ospf_options(nbr->iface->area));
dd_hdr.bits = bits;
dd_hdr.dd_seq_num = htonl(nbr->dd_seq_num);
 
Index: hello.c
===
RCS file: /cvs/src/usr.sbin/ospf6d/hello.c,v
retrieving revision 1.19
diff -u -p -r1.19 hello.c
--- hello.c 11 Dec 2019 21:33:56 -  1.19
+++ hello.c 22 Dec 2019 17:18:49 -
@@ -72,7 +72,7 @@ send_hello(struct iface *iface)
/* hello header */
hello.iface_id = htonl(iface->ifindex);
LSA_24_SETHI(hello.opts, iface->priority);
-   opts = area_ospf_options(area_find(oeconf, iface->area_id));
+   opts = area_ospf_options(iface->area);
LSA_24_SETLO(hello.opts, opts);
hello.opts = htonl(hello.opts);
 
@@ -148,7 +148,7 @@ recv_hello(struct iface *iface, struct i
return;
}
 
-   if ((area = area_find(oeconf, iface->area_id)) == NULL)
+   if ((area = iface->area) == NULL)
fatalx("interface lost area");
 
opts = LSA_24_GETLO(ntohl(hello.opts));
Index: interface.c
===
RCS file: /cvs/src/usr.sbin/ospf6d/interface.c,v
retrieving revision 1.26
diff -u -p -r1.26 interface.c
--- interface.c 22 Dec 2019 15:34:52 -  1.26
+++ interface.c 22 Dec 2019 17:18:49 -
@@ -143,6 +143,7 @@ if_fsm(struct iface *iface, enum iface_e
iface->state = new_state;
 
if (iface->state != old_state) {
+   area_track(iface->area);
orig_rtr_lsa(iface);
orig_link_lsa(iface);
 
@@ -649,7 +650,7 @@ if_to_ctl(struct iface *iface)
memcpy(ictl.name, iface->name, sizeof(ictl.name));
memcpy(, >addr, sizeof(ictl.addr));
ictl.rtr_id.s_addr = ospfe_router_id();
-   memcpy(, >area_id, sizeof(ictl.area));
+   memcpy(, >area->id, sizeof(ictl.area));
if (iface->dr) {
memcpy(_id, >dr->id, sizeof(ictl.dr_id));
memcpy(_addr, >dr->addr, sizeof(ictl.dr_addr));
Index: neighbor.c
===
RCS file: /cvs/src/usr.sbin/ospf6d/neighbor.c,v
retrieving revision 1.14
diff -u -p -r1.14 neighbor.c
--- neighbor.c  9 Feb 2018 03:53:37 -   1.14
+++ neighbor.c  22 Dec 2019 17:18:49 -
@@ -202,8 +202,6 @@ nbr_fsm(struct nbr *nbr, enum nbr_event 
 * neighbor changed from/to FULL
 * originate new rtr and net LSA
 */
-   area_track(area_find(oeconf, nbr->iface->area_id),
-   nbr->state);

ospf6d: scale send buffer

2019-12-22 Thread Denis Fondras
Trivial diff to scale send buffer on socket.

Index: interface.c
===
RCS file: /cvs/src/usr.sbin/ospf6d/interface.c,v
retrieving revision 1.25
diff -u -p -r1.25 interface.c
--- interface.c 28 Jun 2019 13:32:49 -  1.25
+++ interface.c 22 Dec 2019 14:09:20 -
@@ -708,7 +708,7 @@ if_to_ctl(struct iface *iface)
 
 /* misc */
 void
-if_set_recvbuf(int fd)
+if_set_sockbuf(int fd)
 {
int bsize;
 
@@ -718,7 +718,15 @@ if_set_recvbuf(int fd)
bsize /= 2;
 
if (bsize != 256 * 1024)
-   log_warnx("if_set_recvbuf: recvbuf size only %d", bsize);
+   log_warnx("if_set_sockbuf: recvbuf size only %d", bsize);
+
+   bsize = 64 * 1024;
+   while (setsockopt(fd, SOL_SOCKET, SO_SNDBUF, ,
+   sizeof(bsize)) == -1)
+   bsize /= 2;
+
+   if (bsize != 64 * 1024)
+   log_warnx("if_set_sockbuf: sendbuf size only %d", bsize);
 }
 
 int
Index: ospfe.c
===
RCS file: /cvs/src/usr.sbin/ospf6d/ospfe.c,v
retrieving revision 1.56
diff -u -p -r1.56 ospfe.c
--- ospfe.c 11 Jun 2019 05:00:09 -  1.56
+++ ospfe.c 22 Dec 2019 14:09:20 -
@@ -99,7 +99,7 @@ ospfe(struct ospfd_conf *xconf, int pipe
fatal("if_set_ipv6_checksum");
if (if_set_ipv6_pktinfo(xconf->ospf_socket, 1) == -1)
fatal("if_set_ipv6_pktinfo");
-   if_set_recvbuf(xconf->ospf_socket);
+   if_set_sockbuf(xconf->ospf_socket);
 
oeconf = xconf;
if (oeconf->flags & OSPFD_FLAG_NO_FIB_UPDATE)
Index: ospfe.h
===
RCS file: /cvs/src/usr.sbin/ospf6d/ospfe.h,v
retrieving revision 1.20
diff -u -p -r1.20 ospfe.h
--- ospfe.h 11 Dec 2019 21:33:56 -  1.20
+++ ospfe.h 22 Dec 2019 14:09:20 -
@@ -142,7 +142,7 @@ struct ctl_iface*if_to_ctl(struct iface
 int if_join_group(struct iface *, struct in6_addr *);
 int if_leave_group(struct iface *, struct in6_addr *);
 int if_set_mcast(struct iface *);
-voidif_set_recvbuf(int);
+voidif_set_sockbuf(int);
 int if_set_mcast_loop(int);
 int if_set_ipv6_pktinfo(int, int);
 int if_set_ipv6_checksum(int);



ospf6d: rename & move function

2019-12-22 Thread Denis Fondras
Rename and move calc_nexthop_clear()/calc_nexthop_add() to
vertex_nexthop_clear()/vertex_nexthop_add()

It brings ospf6d closer to ospfd.


Index: rde.h
===
RCS file: /cvs/src/usr.sbin/ospf6d/rde.h,v
retrieving revision 1.22
diff -u -p -r1.22 rde.h
--- rde.h   1 Jul 2010 19:47:04 -   1.22
+++ rde.h   18 Dec 2019 10:03:27 -
@@ -140,6 +140,9 @@ void orig_intra_area_prefix_lsas(struc
 voidlsa_init(struct lsa_tree *);
 int lsa_compare(struct vertex *, struct vertex *);
 voidvertex_free(struct vertex *);
+voidvertex_nexthop_clear(struct vertex *);
+voidvertex_nexthop_add(struct vertex *, struct vertex *,
+   const struct in6_addr *, u_int32_t);
 int lsa_newer(struct lsa_hdr *, struct lsa_hdr *);
 int lsa_check(struct rde_nbr *, struct lsa *, u_int16_t);
 int lsa_self(struct lsa *);
Index: rde_lsdb.c
===
RCS file: /cvs/src/usr.sbin/ospf6d/rde_lsdb.c,v
retrieving revision 1.38
diff -u -p -r1.38 rde_lsdb.c
--- rde_lsdb.c  18 Oct 2013 11:16:52 -  1.38
+++ rde_lsdb.c  18 Dec 2019 10:03:27 -
@@ -99,9 +99,39 @@ void
 vertex_free(struct vertex *v)
 {
RB_REMOVE(lsa_tree, v->lsa_tree, v);
+
(void)evtimer_del(>ev);
+   vertex_nexthop_clear(v);
free(v->lsa);
free(v);
+}
+
+void
+vertex_nexthop_clear(struct vertex *v)
+{
+   struct v_nexthop*vn;
+
+   while ((vn = TAILQ_FIRST(>nexthop))) {
+   TAILQ_REMOVE(>nexthop, vn, entry);
+   free(vn);
+   }
+}
+
+void
+vertex_nexthop_add(struct vertex *dst, struct vertex *parent,
+const struct in6_addr *nexthop, u_int32_t ifindex)
+{
+   struct v_nexthop*vn;
+
+   if ((vn = calloc(1, sizeof(*vn))) == NULL)
+   fatal("vertex_nexthop_add");
+
+   vn->prev = parent;
+   if (nexthop)
+   vn->nexthop = *nexthop;
+   vn->ifindex = ifindex;
+
+   TAILQ_INSERT_TAIL(>nexthop, vn, entry);
 }
 
 /* returns -1 if a is older, 1 if newer and 0 if equal to b */
Index: rde_spf.c
===
RCS file: /cvs/src/usr.sbin/ospf6d/rde_spf.c,v
retrieving revision 1.25
diff -u -p -r1.25 rde_spf.c
--- rde_spf.c   5 Dec 2015 06:45:19 -   1.25
+++ rde_spf.c   18 Dec 2019 10:03:27 -
@@ -36,9 +36,6 @@ RB_PROTOTYPE(rt_tree, rt_node, entry, rt
 RB_GENERATE(rt_tree, rt_node, entry, rt_compare)
 struct vertex  *spf_root = NULL;
 
-voidcalc_nexthop_clear(struct vertex *);
-voidcalc_nexthop_add(struct vertex *, struct vertex *,
-const struct in6_addr *, u_int32_t);
 struct in6_addr*calc_nexthop_lladdr(struct vertex *, struct 
lsa_rtr_link *,
 unsigned int);
 voidcalc_nexthop_transit_nbr(struct vertex *, struct vertex *,
@@ -142,7 +139,7 @@ spf_calc(struct area *area)
continue;
if (d < w->cost) {
w->cost = d;
-   calc_nexthop_clear(w);
+   vertex_nexthop_clear(w);
calc_nexthop(w, v, area, rtr_link);
/*
 * need to readd to candidate list
@@ -156,7 +153,7 @@ spf_calc(struct area *area)
} else if (w->cost == LS_INFINITY && d < LS_INFINITY) {
w->cost = d;
 
-   calc_nexthop_clear(w);
+   vertex_nexthop_clear(w);
calc_nexthop(w, v, area, rtr_link);
cand_list_add(w);
}
@@ -420,26 +417,25 @@ asext_calc(struct vertex *v)
}
 
area.s_addr = 0;
-   calc_nexthop_clear(v);
+   vertex_nexthop_clear(v);
TAILQ_FOREACH(rn, >nexthop, entry) {
if (rn->invalid)
continue;
 
if (rn->connected && r->d_type == DT_NET) {
if (metric & LSA_ASEXT_F_FLAG)
-   calc_nexthop_add(v, NULL, _addr,
+   vertex_nexthop_add(v, NULL, _addr,
rn->ifindex);
else
fatalx("asext_calc: I'm sorry Dave, "
"I'm afraid I can't do that.");
} else
-   calc_nexthop_add(v, NULL, >nexthop,
+   

Re: ospf6d: rework priority handling

2019-12-16 Thread Denis Fondras
On Sun, Dec 15, 2019 at 04:07:11PM +0100, Sebastian Benoit wrote:
> unrelated to this diff: I wonder if the manpage (of both ospfd and pspf6d)
> should mention that changing fib-priority with a reload is equivalent toa
> uncouple/couple?
> 

If I understand correctly what you mean, I don't think they are equivalent.
un/couple is implied with reload but only reading conf file ("reload") will
change fib_prio value.



ospf6d: rework priority handling

2019-12-15 Thread Denis Fondras


Index: kroute.c
===
RCS file: /cvs/src/usr.sbin/ospf6d/kroute.c,v
retrieving revision 1.61
diff -u -p -r1.61 kroute.c
--- kroute.c12 Dec 2019 08:21:34 -  1.61
+++ kroute.c15 Dec 2019 08:42:10 -
@@ -97,10 +97,11 @@ RB_PROTOTYPE(kroute_tree, kroute_node, e
 RB_GENERATE(kroute_tree, kroute_node, entry, kroute_compare)
 
 int
-kr_init(int fs, u_int rdomain, u_int8_t fib_prio)
+kr_init(int fs, u_int rdomain, int redis_label_or_prefix, u_int8_t fib_prio)
 {
int opt = 0, rcvbuf, default_rcvbuf;
socklen_t   optlen;
+   int filter_prio = fib_prio;
 
kr_state.fib_sync = fs;
kr_state.rdomain = rdomain;
@@ -117,6 +118,18 @@ kr_init(int fs, u_int rdomain, u_int8_t 
, sizeof(opt)) == -1)
log_warn("kr_init: setsockopt");/* not fatal */
 
+   if (redis_label_or_prefix) {
+   filter_prio = 0;
+   log_info("%s: priority filter disabled", __func__);
+   } else
+   log_debug("%s: priority filter enabled", __func__);
+
+   if (setsockopt(kr_state.fd, AF_ROUTE, ROUTE_PRIOFILTER, _prio,
+   sizeof(filter_prio)) == -1) {
+   log_warn("%s: setsockopt AF_ROUTE ROUTE_PRIOFILTER", __func__);
+   /* not fatal */
+   }
+
/* grow receive buffer, don't wanna miss messages */
optlen = sizeof(default_rcvbuf);
if (getsockopt(kr_state.fd, SOL_SOCKET, SO_RCVBUF,
@@ -353,6 +366,21 @@ kr_fib_decouple(void)
log_info("kernel routing table decoupled");
 }
 
+void
+kr_fib_update_prio(u_int8_t fib_prio)
+{
+   struct kroute_node  *kr;
+
+   RB_FOREACH(kr, kroute_tree, )
+   if ((kr->r.flags & F_OSPFD_INSERTED))
+   kr->r.priority = fib_prio;
+
+   log_info("fib priority changed from %hhu to %hhu", kr_state.fib_prio,
+   fib_prio);
+
+   kr_state.fib_prio = fib_prio;
+}
+
 /* ARGSUSED */
 void
 kr_dispatch_msg(int fd, short event, void *bula)
@@ -522,11 +550,25 @@ kr_redistribute(struct kroute_node *kh)
 }
 
 void
-kr_reload(void)
+kr_reload(int redis_label_or_prefix)
 {
struct kroute_node  *kr, *kn;
u_int32_tdummy;
int  r;
+   int  filter_prio = kr_state.fib_prio;
+
+   /* update the priority filter */
+   if (redis_label_or_prefix) {
+   filter_prio = 0;
+   log_info("%s: priority filter disabled", __func__);
+   } else
+   log_debug("%s: priority filter enabled", __func__);
+
+   if (setsockopt(kr_state.fd, AF_ROUTE, ROUTE_PRIOFILTER, _prio,
+   sizeof(filter_prio)) == -1) {
+   log_warn("%s: setsockopt AF_ROUTE ROUTE_PRIOFILTER", __func__);
+   /* not fatal */
+   }
 
RB_FOREACH(kr, kroute_tree, ) {
for (kn = kr; kn; kn = kn->next) {
Index: ospf6d.c
===
RCS file: /cvs/src/usr.sbin/ospf6d/ospf6d.c,v
retrieving revision 1.44
diff -u -p -r1.44 ospf6d.c
--- ospf6d.c25 Mar 2019 20:53:33 -  1.44
+++ ospf6d.c15 Dec 2019 08:42:10 -
@@ -280,7 +280,8 @@ main(int argc, char *argv[])
fatal("unveil");
 
if (kr_init(!(ospfd_conf->flags & OSPFD_FLAG_NO_FIB_UPDATE),
-   ospfd_conf->rdomain, ospfd_conf->fib_priority) == -1)
+   ospfd_conf->rdomain, ospfd_conf->redist_label_or_prefix,
+   ospfd_conf->fib_priority) == -1)
fatalx("kr_init failed");
 
event_dispatch();
@@ -631,7 +632,7 @@ ospf_reload(void)
 
merge_config(ospfd_conf, xconf);
/* update redistribute lists */
-   kr_reload();
+   kr_reload(ospfd_conf->redist_label_or_prefix);
return (0);
 #else
return (-1);
@@ -654,12 +655,16 @@ merge_config(struct ospfd_conf *conf, st
struct area *a, *xa, *na;
struct iface*iface;
struct redistribute *r;
+   int  rchange = 0;
 
/* change of rtr_id needs a restart */
conf->flags = xconf->flags;
conf->spf_delay = xconf->spf_delay;
conf->spf_hold_time = xconf->spf_hold_time;
-   conf->redistribute = xconf->redistribute;
+   if (SIMPLEQ_EMPTY(>redist_list) !=
+   SIMPLEQ_EMPTY(>redist_list))
+   rchange = 1;
+   conf->redist_label_or_prefix = xconf->redist_label_or_prefix;
 
if (ospfd_process == PROC_MAIN) {
/* main process does neither use areas nor interfaces */
@@ -671,6 +676,15 @@ merge_config(struct ospfd_conf *conf, st
SIMPLEQ_REMOVE_HEAD(>redist_list, entry);
SIMPLEQ_INSERT_TAIL(>redist_list, r, entry);
}
+
+   /* adjust FIB priority if changed */
+   if (conf->fib_priority != 

ospf6d: makes area part of struct iface

2019-12-14 Thread Denis Fondras
As the subject says.
By request of remi@ (https://marc.info/?l=openbsd-tech=157635822315646=2)

Index: database.c
===
RCS file: /cvs/src/usr.sbin/ospf6d/database.c,v
retrieving revision 1.17
diff -u -p -r1.17 database.c
--- database.c  11 Dec 2019 21:33:56 -  1.17
+++ database.c  14 Dec 2019 21:58:38 -
@@ -134,8 +134,7 @@ send_db_description(struct nbr *nbr)
fatalx("send_db_description: unknown interface type");
}
 
-   dd_hdr.opts = htonl(area_ospf_options(area_find(oeconf,
-   nbr->iface->area_id)));
+   dd_hdr.opts = htonl(area_ospf_options(nbr->iface->area));
dd_hdr.bits = bits;
dd_hdr.dd_seq_num = htonl(nbr->dd_seq_num);
 
Index: hello.c
===
RCS file: /cvs/src/usr.sbin/ospf6d/hello.c,v
retrieving revision 1.19
diff -u -p -r1.19 hello.c
--- hello.c 11 Dec 2019 21:33:56 -  1.19
+++ hello.c 14 Dec 2019 21:58:38 -
@@ -72,7 +72,7 @@ send_hello(struct iface *iface)
/* hello header */
hello.iface_id = htonl(iface->ifindex);
LSA_24_SETHI(hello.opts, iface->priority);
-   opts = area_ospf_options(area_find(oeconf, iface->area_id));
+   opts = area_ospf_options(iface->area);
LSA_24_SETLO(hello.opts, opts);
hello.opts = htonl(hello.opts);
 
@@ -148,7 +148,7 @@ recv_hello(struct iface *iface, struct i
return;
}
 
-   if ((area = area_find(oeconf, iface->area_id)) == NULL)
+   if ((area = iface->area) == NULL)
fatalx("interface lost area");
 
opts = LSA_24_GETLO(ntohl(hello.opts));
Index: interface.c
===
RCS file: /cvs/src/usr.sbin/ospf6d/interface.c,v
retrieving revision 1.25
diff -u -p -r1.25 interface.c
--- interface.c 28 Jun 2019 13:32:49 -  1.25
+++ interface.c 14 Dec 2019 21:58:38 -
@@ -649,7 +649,7 @@ if_to_ctl(struct iface *iface)
memcpy(ictl.name, iface->name, sizeof(ictl.name));
memcpy(, >addr, sizeof(ictl.addr));
ictl.rtr_id.s_addr = ospfe_router_id();
-   memcpy(, >area_id, sizeof(ictl.area));
+   memcpy(, >area->id, sizeof(ictl.area));
if (iface->dr) {
memcpy(_id, >dr->id, sizeof(ictl.dr_id));
memcpy(_addr, >dr->addr, sizeof(ictl.dr_addr));
Index: neighbor.c
===
RCS file: /cvs/src/usr.sbin/ospf6d/neighbor.c,v
retrieving revision 1.14
diff -u -p -r1.14 neighbor.c
--- neighbor.c  9 Feb 2018 03:53:37 -   1.14
+++ neighbor.c  14 Dec 2019 21:58:38 -
@@ -202,8 +202,7 @@ nbr_fsm(struct nbr *nbr, enum nbr_event 
 * neighbor changed from/to FULL
 * originate new rtr and net LSA
 */
-   area_track(area_find(oeconf, nbr->iface->area_id),
-   nbr->state);
+   area_track(nbr->iface->area, nbr->state);
orig_rtr_lsa(nbr->iface);
if (nbr->iface->state & IF_STA_DR)
orig_net_lsa(nbr->iface);
@@ -319,7 +318,7 @@ nbr_new(u_int32_t nbr_id, struct iface *
if (addr)
rn.addr = *addr;
rn.id.s_addr = nbr->id.s_addr;
-   rn.area_id.s_addr = nbr->iface->area_id.s_addr;
+   rn.area_id.s_addr = nbr->iface->area->id.s_addr;
rn.ifindex = nbr->iface->ifindex;
rn.iface_id = nbr->iface_id;
rn.state = nbr->state;
@@ -660,7 +659,7 @@ nbr_to_ctl(struct nbr *nbr)
memcpy(, >addr, sizeof(nctl.addr));
memcpy(, >dr, sizeof(nctl.dr));
memcpy(, >bdr, sizeof(nctl.bdr));
-   memcpy(, >iface->area_id, sizeof(nctl.area));
+   memcpy(, >iface->area->id, sizeof(nctl.area));
 
/* this list is 99% of the time empty so that's OK for now */
nctl.db_sum_lst_cnt = 0;
Index: ospf6d.h
===
RCS file: /cvs/src/usr.sbin/ospf6d/ospf6d.h,v
retrieving revision 1.40
diff -u -p -r1.40 ospf6d.h
--- ospf6d.h11 Jun 2019 05:00:09 -  1.40
+++ ospf6d.h14 Dec 2019 21:58:38 -
@@ -304,10 +304,10 @@ struct iface {
struct in6_addr  addr;
struct in6_addr  dst;
struct in_addr   abr_id;
-   struct in_addr   area_id;
struct nbr  *dr;/* designated router */
struct nbr  *bdr;   /* backup designated router */
struct nbr  *self;
+   struct area *area;
 
u_int64_tbaudrate;
u_int32_tls_ack_cnt;
Index: ospfe.c
===
RCS file: /cvs/src/usr.sbin/ospf6d/ospfe.c,v
retrieving revision 1.56
diff -u -p -r1.56 

  1   2   3   4   >