21st century lam(1)

2018-07-11 Thread Ingo Schwarze
Hi,

some time ago, i went on a rampage to improve UTF-8 support in
userland utilities.  But there are still a few stragglers among the
more obscure beasts out there.  For example, have you met lam(1)?

When LC_CTYPE=en_US.UTF-8 is set, let's fix the column alignment 
in the presence of width 0 and width 2 UTF-8 characters, of course
without dying from invalid bytes that may also be around.

Following the pattern we discovered in the past, this utility once
again needs its own multibyte char utility function, different from
the ones needed in ls(1), ps(1), and rs(1).  But as usual, this one
is quite simple, too.  All the same, i'd rather keep it in its own
file and not encumber the main code with it.

Of course, now that we measure widths with wcwidth(3), printf(%*.*s)
is no longer sufficient to do truncation and alignment; instead,
we have to do truncation and alignment explicitly, taking the
various character display widths into account.  But doing that
is not too complicated.

OK?
  Ingo


Index: Makefile
===
RCS file: /cvs/src/usr.bin/lam/Makefile,v
retrieving revision 1.3
diff -u -p -r1.3 Makefile
--- Makefile21 Sep 1997 11:49:24 -  1.3
+++ Makefile11 Jul 2018 21:02:28 -
@@ -1,5 +1,6 @@
 #  $OpenBSD: Makefile,v 1.3 1997/09/21 11:49:24 deraadt Exp $
 
 PROG=  lam
+SRCS=  lam.c utf8.c
 
 .include 
Index: lam.1
===
RCS file: /cvs/src/usr.bin/lam/lam.1,v
retrieving revision 1.9
diff -u -p -r1.9 lam.1
--- lam.1   4 Jan 2016 23:21:28 -   1.9
+++ lam.1   11 Jul 2018 21:02:28 -
@@ -74,8 +74,8 @@ is the minimum field width and
 the maximum field width.
 If
 .Ar min
-begins with a zero, zeros will be added to make up the field width,
-and if it begins with a
+begins with a zero, zeros will be prepended to make up the field width
+instead of blanks, and if it begins with a
 .Sq \&- ,
 the fragment will be left-adjusted
 within the field.
@@ -98,6 +98,22 @@ The newline normally appended to each ou
 .Pp
 To print files simultaneously for easy viewing use
 .Xr pr 1 .
+.Sh ENVIRONMENT
+.Bl -tag -width LC_CTYPE
+.It Ev LC_CTYPE
+The character encoding
+.Xr locale 1 .
+It determines the display widths of characters used by the
+.Fl f
+and
+.Fl p
+options.
+If unset or set to
+.Qq C ,
+.Qq POSIX ,
+or an unsupported value, each byte is regarded as a character
+of display width 1.
+.El
 .Sh EXAMPLES
 Join four files together along each line:
 .Pp
Index: lam.c
===
RCS file: /cvs/src/usr.bin/lam/lam.c,v
retrieving revision 1.21
diff -u -p -r1.21 lam.c
--- lam.c   11 Jul 2018 11:42:17 -  1.21
+++ lam.c   11 Jul 2018 21:02:28 -
@@ -39,6 +39,7 @@
 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -48,11 +49,13 @@
 
 struct openfile {  /* open file structure */
FILE*fp;/* file pointer */
+   int minwidth;   /* pad this column to this width */
+   int maxwidth;   /* truncate this column */
short   eof;/* eof flag */
short   pad;/* pad flag for missing columns */
chareol;/* end of line character */
+   charalign;  /* '0' for zero fill, '-' for left align */
char*sepstring; /* string to print before each line */
-   char*format;/* printf(3) style string spec. */
 }  input[NOFILE_MAX + 1];  /* last one is for the last -s arg. */
 #define INPUTSIZE sizeof(input) / sizeof(*input)
 
@@ -61,6 +64,8 @@ int   nofinalnl;  /* normally append \n to
 char   line[BIGBUFSIZ];
 char   *linep;
 
+int mbswidth_truncate(char *, int);  /* utf8.c */
+
 voidusage(void);
 char   *gatherline(struct openfile *);
 voidgetargs(int, char *[]);
@@ -71,6 +76,8 @@ main(int argc, char *argv[])
 {
int i;
 
+   setlocale(LC_CTYPE, "");
+
if (pledge("stdio rpath", NULL) == -1)
err(1, "pledge");
 
@@ -106,9 +113,9 @@ void
 getargs(int argc, char *argv[])
 {
struct openfile *ip = input;
-   char *p;
+   const char *errstr;
+   char *p, *q;
int ch, P, S, F, T;
-   size_t siz;
 
P = S = F = T = 0;  /* capitalized options */
while (optind < argc) {
@@ -120,17 +127,28 @@ getargs(int argc, char *argv[])
case 'F': case 'f':
F = (ch == 'F');
/* Validate format string argument. */
-   for (p = optarg; *p != '\0'; p++)
-   if (!isdigit((unsigned char)*p) &&
-   *p != '.' && *p != '-')
-   errx(1, "%s: invalid width specified",
-optarg);
-   /* '%' + width + 's' + '\0' */

kill RTM_Losing in route6d

2018-07-11 Thread Claudio Jeker
See subject, it is not using it in any sensible way.

-- 
:wq Claudio

Index: route6d.c
===
RCS file: /cvs/src/usr.sbin/route6d/route6d.c,v
retrieving revision 1.96
diff -u -p -r1.96 route6d.c
--- route6d.c   1 Jul 2018 15:42:37 -   1.96
+++ route6d.c   11 Jul 2018 20:28:36 -
@@ -1604,7 +1604,6 @@ rtrecv(void)
case RTM_ADD:
rtable++;
return;
-   case RTM_LOSING:
case RTM_MISS:
case RTM_RESOLVE:
case RTM_GET:
@@ -1641,7 +1640,6 @@ rtrecv(void)
case RTM_NEWADDR:
case RTM_IFINFO:
case RTM_ADD:
-   case RTM_LOSING:
case RTM_MISS:
case RTM_RESOLVE:
case RTM_GET:
@@ -2256,7 +2254,6 @@ do { \
RTTYPE("DELETE", RTM_DELETE);
RTTYPE("CHANGE", RTM_CHANGE);
RTTYPE("GET", RTM_GET);
-   RTTYPE("LOSING", RTM_LOSING);
RTTYPE("REDIRECT", RTM_REDIRECT);
RTTYPE("MISS", RTM_MISS);
RTTYPE("RESOLVE", RTM_RESOLVE);



Re: bgpd: check if we are running in an rtable or a rdomain

2018-07-11 Thread Claudio Jeker
On Wed, Jul 11, 2018 at 10:18:59PM +0200, Sebastian Benoit wrote:
> 
> ok?

OK claudio@
 
> (benno_check_rdomain.diff)
> 
> diff --git usr.sbin/bgpd/config.c usr.sbin/bgpd/config.c
> index 2a2e5dfa314..4f8134e6b68 100644
> --- usr.sbin/bgpd/config.c
> +++ usr.sbin/bgpd/config.c
> @@ -46,6 +46,7 @@ struct bgpd_config *
>  new_config(void)
>  {
>   struct bgpd_config  *conf;
> + u_intrdomid;
>  
>   if ((conf = calloc(1, sizeof(struct bgpd_config))) == NULL)
>   fatal(NULL);
> @@ -54,6 +55,10 @@ new_config(void)
>   conf->bgpid = get_bgpid();
>   conf->fib_priority = RTP_BGP;
>   conf->default_tableid = getrtable();
> + ktable_exists(conf->default_tableid, &rdomid);
> + if (rdomid != conf->default_tableid)
> + fatalx("current routing table %u is not a routing domain",
> + conf->default_tableid);
>  
>   if (asprintf(&conf->csock, "%s.%d", SOCKET_NAME,
>   conf->default_tableid) == -1)
> 

-- 
:wq Claudio



bgpd: check if we are running in an rtable or a rdomain

2018-07-11 Thread Sebastian Benoit


ok?

(benno_check_rdomain.diff)

diff --git usr.sbin/bgpd/config.c usr.sbin/bgpd/config.c
index 2a2e5dfa314..4f8134e6b68 100644
--- usr.sbin/bgpd/config.c
+++ usr.sbin/bgpd/config.c
@@ -46,6 +46,7 @@ struct bgpd_config *
 new_config(void)
 {
struct bgpd_config  *conf;
+   u_intrdomid;
 
if ((conf = calloc(1, sizeof(struct bgpd_config))) == NULL)
fatal(NULL);
@@ -54,6 +55,10 @@ new_config(void)
conf->bgpid = get_bgpid();
conf->fib_priority = RTP_BGP;
conf->default_tableid = getrtable();
+   ktable_exists(conf->default_tableid, &rdomid);
+   if (rdomid != conf->default_tableid)
+   fatalx("current routing table %u is not a routing domain",
+   conf->default_tableid);
 
if (asprintf(&conf->csock, "%s.%d", SOCKET_NAME,
conf->default_tableid) == -1)



Re: __func__ to panic() calls in sys/net*

2018-07-11 Thread Sebastian Benoit
nayden(nay...@ndtm.net) on 2018.07.11 13:27:33 -0600:
> Hello,
> 
> tb@ hinted to me that sys/net* can benefit from more __func__ 
> springkling and I these are the potentially useful places that
> I found.
> 
> ok?

if noone working on these files currently stopsyou, ok benno@

> 
> Index: net/if_pppx.c
> ===
> RCS file: /home/nayden/cvsync/src/sys/net/if_pppx.c,v
> retrieving revision 1.65
> diff -u -p -r1.65 if_pppx.c
> --- net/if_pppx.c 15 Jun 2018 12:39:38 -  1.65
> +++ net/if_pppx.c 11 Jul 2018 18:22:55 -
> @@ -839,7 +839,7 @@ pppx_add_session(struct pppx_dev *pxd, s
>   }
>  
>   if (RBT_INSERT(pppx_ifs, &pppx_ifs, pxi) != NULL)
> - panic("pppx_ifs modified while lock was held");
> + panic("%s: pppx_ifs modified while lock was held", __func__);
>   LIST_INSERT_HEAD(&pxd->pxd_pxis, pxi, pxi_list);
>   rw_exit_write(&pppx_ifs_lk);
>  
> @@ -991,7 +991,7 @@ pppx_if_destroy(struct pppx_dev *pxd, st
>  
>   rw_enter_write(&pppx_ifs_lk);
>   if (RBT_REMOVE(pppx_ifs, &pppx_ifs, pxi) == NULL)
> - panic("pppx_ifs modified while lock was held");
> + panic("%s: pppx_ifs modified while lock was held", __func__);
>   LIST_REMOVE(pxi, pxi_list);
>   rw_exit_write(&pppx_ifs_lk);
>  
> Index: net/pf_if.c
> ===
> RCS file: /home/nayden/cvsync/src/sys/net/pf_if.c,v
> retrieving revision 1.94
> diff -u -p -r1.94 pf_if.c
> --- net/pf_if.c   11 Jul 2018 09:05:51 -  1.94
> +++ net/pf_if.c   11 Jul 2018 18:23:56 -
> @@ -227,7 +227,7 @@ pfi_attach_ifnet(struct ifnet *ifp)
>   pfi_initialize();
>   pfi_update++;
>   if ((kif = pfi_kif_get(ifp->if_xname)) == NULL)
> - panic("pfi_kif_get failed");
> + panic("%s: pfi_kif_get failed", __func__);
>  
>   kif->pfik_ifp = ifp;
>   ifp->if_pf_kif = (caddr_t)kif;
> @@ -265,7 +265,7 @@ pfi_attach_ifgroup(struct ifg_group *ifg
>   pfi_initialize();
>   pfi_update++;
>   if ((kif = pfi_kif_get(ifg->ifg_group)) == NULL)
> - panic("pfi_kif_get failed");
> + panic("%s: pfi_kif_get failed", __func__);
>  
>   kif->pfik_group = ifg;
>   ifg->ifg_pf_kif = (caddr_t)kif;
> @@ -293,7 +293,7 @@ pfi_group_change(const char *group)
>  
>   pfi_update++;
>   if ((kif = pfi_kif_get(group)) == NULL)
> - panic("pfi_kif_get failed");
> + panic("%s: pfi_kif_get failed", __func__);
>  
>   pfi_kif_update(kif);
>  }
> @@ -305,7 +305,7 @@ pfi_group_addmember(const char *group, s
>  
>   if ((gkif = pfi_kif_get(group)) == NULL ||
>   (ikif = pfi_kif_get(ifp->if_xname)) == NULL)
> - panic("pfi_kif_get failed");
> + panic("%s: pfi_kif_get failed", __func__);
>   ikif->pfik_flags |= gkif->pfik_flags;
>  
>   pfi_group_change(group);
> Index: net80211/ieee80211.c
> ===
> RCS file: /home/nayden/cvsync/src/sys/net80211/ieee80211.c,v
> retrieving revision 1.68
> diff -u -p -r1.68 ieee80211.c
> --- net80211/ieee80211.c  28 Apr 2018 14:49:07 -  1.68
> +++ net80211/ieee80211.c  11 Jul 2018 18:43:15 -
> @@ -823,7 +823,7 @@ ieee80211_setmode(struct ieee80211com *i
>* channel list before committing to the new mode.
>*/
>   if (mode >= nitems(chanflags))
> - panic("unexpected mode %u", mode);
> + panic("%s: unexpected mode %u", __func__, mode);
>   modeflags = chanflags[mode];
>   for (i = 0; i <= IEEE80211_CHAN_MAX; i++) {
>   c = &ic->ic_channels[i];
> @@ -969,7 +969,7 @@ ieee80211_mcs2media(struct ieee80211com 
>   case IEEE80211_MODE_11B:
>   case IEEE80211_MODE_11G:
>   /* these modes use rates, not MCS */
> - panic("unexpected mode %d", mode);
> + panic("%s: unexpected mode %d", __func__, mode);
>   break;
>   case IEEE80211_MODE_AUTO:
>   case IEEE80211_MODE_11N:
> @@ -1062,7 +1062,7 @@ ieee80211_rate2media(struct ieee80211com
>   break;
>   case IEEE80211_MODE_11N:
>   /* 11n uses MCS, not rates. */
> - panic("unexpected mode %d", mode);
> + panic("%s: unexpected mode %d", __func__, mode);
>   break;
>   }
>   for (i = 0; i < nitems(rates); i++)
> @@ -1135,7 +1135,7 @@ ieee80211_rate2plcp(u_int8_t rate, enum 
>   case 108:   return 0x0c;
>   }
>  } else
> - panic("unexpected mode %u", mode);
> + panic("%s: unexpected mode %u", __func__, mode);
>  
>   DPRINTF(("unsupported rate %u\n", rate));
>  
> @@ -1168,7 +1168,7 @@ ieee80211_plcp2rate(u_int8_t plcp, enum 
>   case 0x0c:  return 108;
>   }
>   } else
> - pani

__func__ to panic() calls in sys/net*

2018-07-11 Thread nayden
Hello,

tb@ hinted to me that sys/net* can benefit from more __func__ 
springkling and I these are the potentially useful places that
I found.

ok?

Index: net/if_pppx.c
===
RCS file: /home/nayden/cvsync/src/sys/net/if_pppx.c,v
retrieving revision 1.65
diff -u -p -r1.65 if_pppx.c
--- net/if_pppx.c   15 Jun 2018 12:39:38 -  1.65
+++ net/if_pppx.c   11 Jul 2018 18:22:55 -
@@ -839,7 +839,7 @@ pppx_add_session(struct pppx_dev *pxd, s
}
 
if (RBT_INSERT(pppx_ifs, &pppx_ifs, pxi) != NULL)
-   panic("pppx_ifs modified while lock was held");
+   panic("%s: pppx_ifs modified while lock was held", __func__);
LIST_INSERT_HEAD(&pxd->pxd_pxis, pxi, pxi_list);
rw_exit_write(&pppx_ifs_lk);
 
@@ -991,7 +991,7 @@ pppx_if_destroy(struct pppx_dev *pxd, st
 
rw_enter_write(&pppx_ifs_lk);
if (RBT_REMOVE(pppx_ifs, &pppx_ifs, pxi) == NULL)
-   panic("pppx_ifs modified while lock was held");
+   panic("%s: pppx_ifs modified while lock was held", __func__);
LIST_REMOVE(pxi, pxi_list);
rw_exit_write(&pppx_ifs_lk);
 
Index: net/pf_if.c
===
RCS file: /home/nayden/cvsync/src/sys/net/pf_if.c,v
retrieving revision 1.94
diff -u -p -r1.94 pf_if.c
--- net/pf_if.c 11 Jul 2018 09:05:51 -  1.94
+++ net/pf_if.c 11 Jul 2018 18:23:56 -
@@ -227,7 +227,7 @@ pfi_attach_ifnet(struct ifnet *ifp)
pfi_initialize();
pfi_update++;
if ((kif = pfi_kif_get(ifp->if_xname)) == NULL)
-   panic("pfi_kif_get failed");
+   panic("%s: pfi_kif_get failed", __func__);
 
kif->pfik_ifp = ifp;
ifp->if_pf_kif = (caddr_t)kif;
@@ -265,7 +265,7 @@ pfi_attach_ifgroup(struct ifg_group *ifg
pfi_initialize();
pfi_update++;
if ((kif = pfi_kif_get(ifg->ifg_group)) == NULL)
-   panic("pfi_kif_get failed");
+   panic("%s: pfi_kif_get failed", __func__);
 
kif->pfik_group = ifg;
ifg->ifg_pf_kif = (caddr_t)kif;
@@ -293,7 +293,7 @@ pfi_group_change(const char *group)
 
pfi_update++;
if ((kif = pfi_kif_get(group)) == NULL)
-   panic("pfi_kif_get failed");
+   panic("%s: pfi_kif_get failed", __func__);
 
pfi_kif_update(kif);
 }
@@ -305,7 +305,7 @@ pfi_group_addmember(const char *group, s
 
if ((gkif = pfi_kif_get(group)) == NULL ||
(ikif = pfi_kif_get(ifp->if_xname)) == NULL)
-   panic("pfi_kif_get failed");
+   panic("%s: pfi_kif_get failed", __func__);
ikif->pfik_flags |= gkif->pfik_flags;
 
pfi_group_change(group);
Index: net80211/ieee80211.c
===
RCS file: /home/nayden/cvsync/src/sys/net80211/ieee80211.c,v
retrieving revision 1.68
diff -u -p -r1.68 ieee80211.c
--- net80211/ieee80211.c28 Apr 2018 14:49:07 -  1.68
+++ net80211/ieee80211.c11 Jul 2018 18:43:15 -
@@ -823,7 +823,7 @@ ieee80211_setmode(struct ieee80211com *i
 * channel list before committing to the new mode.
 */
if (mode >= nitems(chanflags))
-   panic("unexpected mode %u", mode);
+   panic("%s: unexpected mode %u", __func__, mode);
modeflags = chanflags[mode];
for (i = 0; i <= IEEE80211_CHAN_MAX; i++) {
c = &ic->ic_channels[i];
@@ -969,7 +969,7 @@ ieee80211_mcs2media(struct ieee80211com 
case IEEE80211_MODE_11B:
case IEEE80211_MODE_11G:
/* these modes use rates, not MCS */
-   panic("unexpected mode %d", mode);
+   panic("%s: unexpected mode %d", __func__, mode);
break;
case IEEE80211_MODE_AUTO:
case IEEE80211_MODE_11N:
@@ -1062,7 +1062,7 @@ ieee80211_rate2media(struct ieee80211com
break;
case IEEE80211_MODE_11N:
/* 11n uses MCS, not rates. */
-   panic("unexpected mode %d", mode);
+   panic("%s: unexpected mode %d", __func__, mode);
break;
}
for (i = 0; i < nitems(rates); i++)
@@ -1135,7 +1135,7 @@ ieee80211_rate2plcp(u_int8_t rate, enum 
case 108:   return 0x0c;
}
 } else
-   panic("unexpected mode %u", mode);
+   panic("%s: unexpected mode %u", __func__, mode);
 
DPRINTF(("unsupported rate %u\n", rate));
 
@@ -1168,7 +1168,7 @@ ieee80211_plcp2rate(u_int8_t plcp, enum 
case 0x0c:  return 108;
}
} else
-   panic("unexpected mode %u", mode);
+   panic("%s: unexpected mode %u", __func__, mode);
 
DPRINTF(("unsupported plcp %u\n", plcp));
 
Index: net80211/ieee80211_mira.c
===

ospf6d: add support for rdomains

2018-07-11 Thread Remi Locherer
Hi,

This adds rdomain support to ospf6d. It works the same as in ospfd.

OK?

Remi


Index: ospf6ctl/ospf6ctl.c
===
RCS file: /cvs/src/usr.sbin/ospf6ctl/ospf6ctl.c,v
retrieving revision 1.48
diff -u -p -r1.48 ospf6ctl.c
--- ospf6ctl/ospf6ctl.c 6 Jun 2018 05:51:43 -   1.48
+++ ospf6ctl/ospf6ctl.c 11 Jul 2018 14:29:49 -
@@ -90,13 +90,16 @@ main(int argc, char *argv[])
struct parse_result *res;
struct imsg  imsg;
unsigned int ifidx = 0;
-   int  ctl_sock;
+   int  ctl_sock, r;
int  done = 0, verbose = 0;
int  n;
int  ch;
char*sockname;
 
-   sockname = OSPF6D_SOCKET;
+   r = getrtable();
+   if (asprintf(&sockname, "%s.%d", OSPF6D_SOCKET, r) == -1)
+   err(1, "asprintf");
+
while ((ch = getopt(argc, argv, "s:")) != -1) {
switch (ch) {
case 's':
Index: ospf6d/interface.c
===
RCS file: /cvs/src/usr.sbin/ospf6d/interface.c,v
retrieving revision 1.23
diff -u -p -r1.23 interface.c
--- ospf6d/interface.c  11 Mar 2018 13:17:35 -  1.23
+++ ospf6d/interface.c  11 Jul 2018 18:02:42 -
@@ -235,13 +235,14 @@ if_new(u_short ifindex, char *ifname)
 
 void
 if_update(struct iface *iface, int mtu, int flags, u_int8_t type,
-u_int8_t state, u_int64_t rate)
+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;
 
/* set type */
if (flags & IFF_POINTOPOINT)
Index: ospf6d/kroute.c
===
RCS file: /cvs/src/usr.sbin/ospf6d/kroute.c,v
retrieving revision 1.56
diff -u -p -r1.56 kroute.c
--- ospf6d/kroute.c 10 Jul 2018 12:17:38 -  1.56
+++ ospf6d/kroute.c 11 Jul 2018 14:10:26 -
@@ -47,6 +47,7 @@ struct {
int fib_sync;
int fd;
struct eventev;
+   u_int   rdomain;
 } kr_state;
 
 struct kroute_node {
@@ -94,12 +95,13 @@ RB_PROTOTYPE(kroute_tree, kroute_node, e
 RB_GENERATE(kroute_tree, kroute_node, entry, kroute_compare)
 
 int
-kr_init(int fs)
+kr_init(int fs, u_int rdomain)
 {
int opt = 0, rcvbuf, default_rcvbuf;
socklen_t   optlen;
 
kr_state.fib_sync = fs;
+   kr_state.rdomain = rdomain;
 
if ((kr_state.fd = socket(AF_ROUTE,
SOCK_RAW | SOCK_CLOEXEC | SOCK_NONBLOCK, AF_INET6)) == -1) {
@@ -718,7 +720,7 @@ kif_update(u_short ifindex, int flags, s
}
 
if_update(iface, ifd->ifi_mtu, flags, ifd->ifi_type,
-   ifd->ifi_link_state, ifd->ifi_baudrate);
+   ifd->ifi_link_state, ifd->ifi_baudrate, ifd->ifi_rdomain);
 
return (iface);
 }
@@ -1016,6 +1018,7 @@ send_rtmsg(int fd, int action, struct kr
hdr.rtm_version = RTM_VERSION;
hdr.rtm_type = action;
hdr.rtm_priority = RTP_OSPF;
+   hdr.rtm_tableid = kr_state.rdomain; /* rtableid */
if (action == RTM_CHANGE)
hdr.rtm_fmask = RTF_REJECT|RTF_BLACKHOLE;
else
@@ -1147,7 +1150,7 @@ fetchtable(void)
mib[3] = AF_INET6;
mib[4] = NET_RT_DUMP;
mib[5] = 0;
-   mib[6] = 0; /* rtableid */
+   mib[6] = kr_state.rdomain;  /* rtableid */
 
if (sysctl(mib, 7, NULL, &len, NULL, 0) == -1) {
log_warn("sysctl");
@@ -1381,7 +1384,7 @@ dispatch_rtmsg(void)
sa = (struct sockaddr *)(next + rtm->rtm_hdrlen);
get_rtaddrs(rtm->rtm_addrs, sa, rti_info);
 
-   if (rtm->rtm_tableid != 0)
+   if (rtm->rtm_tableid != kr_state.rdomain)
continue;
 
if (rtm->rtm_pid == kr_state.pid) /* caused by us */
Index: ospf6d/ospf6d.c
===
RCS file: /cvs/src/usr.sbin/ospf6d/ospf6d.c,v
retrieving revision 1.36
diff -u -p -r1.36 ospf6d.c
--- ospf6d/ospf6d.c 9 Jul 2018 13:19:46 -   1.36
+++ ospf6d/ospf6d.c 11 Jul 2018 14:24:49 -
@@ -113,11 +113,10 @@ main(int argc, char *argv[])
int  ipforwarding;
int  mib[4];
size_t   len;
-   char*sockname;
+   char*sockname = NULL;
 
conffile = CONF_FILE;
ospfd_process = PROC_MAIN;
-   sockname = OSPF6D_SOCKET;
 
log_init(1, LOG_DAEMON);/* log to stderr until daemonized */
log_procini

bgpd: better hash functions

2018-07-11 Thread Claudio Jeker
Especially the rde_aspath hash function is horrible.
Fix this by adding more bits to the SipHash which results in a better
spread. Also switch the stored hases to 64bit and save the one for
rde_aspath as well since it the compare a lot quicker.

-- 
:wq Claudio

Index: rde.h
===
RCS file: /cvs/src/usr.sbin/bgpd/rde.h,v
retrieving revision 1.177
diff -u -p -r1.177 rde.h
--- rde.h   11 Jul 2018 16:34:36 -  1.177
+++ rde.h   11 Jul 2018 17:35:27 -
@@ -140,8 +140,8 @@ enum attrtypes {
 struct attr {
LIST_ENTRY(attr) entry;
u_char  *data;
+   u_int64_thash;
int  refcnt;
-   u_int32_thash;
u_int16_tlen;
u_int8_t flags;
u_int8_t type;
@@ -154,11 +154,6 @@ struct mpattr {
u_int16_tunreach_len;
 };
 
-struct path_table {
-   struct aspath_head  *path_hashtbl;
-   u_int32_tpath_hashmask;
-};
-
 #defineF_ATTR_ORIGIN   0x1
 #defineF_ATTR_ASPATH   0x2
 #defineF_ATTR_NEXTHOP  0x4
@@ -195,10 +190,11 @@ struct rde_aspath {
struct rde_peer *peer;
struct aspath   *aspath;
struct nexthop  *nexthop;   /* may be NULL */
+   u_int64_thash;
+   u_int32_tflags; /* internally used */
u_int32_tmed;   /* multi exit disc */
u_int32_tlpref; /* local pref */
u_int32_tweight;/* low prio lpref */
-   u_int32_tflags; /* internally used */
u_int16_trtlabelid; /* route label id */
u_int16_tpftableid; /* pf table id */
u_int8_t origin;
@@ -358,6 +354,7 @@ int  attr_optadd(struct rde_aspath *, u
 struct attr*attr_optget(const struct rde_aspath *, u_int8_t);
 voidattr_copy(struct rde_aspath *, const struct rde_aspath *);
 int attr_compare(struct rde_aspath *, struct rde_aspath *);
+u_int64_t   attr_hash(struct rde_aspath *);
 voidattr_freeall(struct rde_aspath *);
 voidattr_free(struct rde_aspath *, struct attr *);
 #define attr_optlen(x) \
Index: rde_attr.c
===
RCS file: /cvs/src/usr.sbin/bgpd/rde_attr.c,v
retrieving revision 1.103
diff -u -p -r1.103 rde_attr.c
--- rde_attr.c  11 Jul 2018 16:34:36 -  1.103
+++ rde_attr.c  11 Jul 2018 17:35:27 -
@@ -99,7 +99,7 @@ void   attr_put(struct attr *);
 
 struct attr_table {
struct attr_list*hashtbl;
-   u_int32_thashmask;
+   u_int64_thashmask;
 } attrtable;
 
 SIPHASH_KEY attrtablekey;
@@ -287,7 +287,6 @@ attr_diff(struct attr *oa, struct attr *
return (-1);
 
fatalx("attr_diff: equal attributes encountered");
-   return (0);
 }
 
 int
@@ -313,6 +312,18 @@ attr_compare(struct rde_aspath *a, struc
return (0);
 }
 
+u_int64_t
+attr_hash(struct rde_aspath *a)
+{
+   u_int64_t   hash = 0;
+   u_int8_tl;
+
+   for (l = 0; l < a->others_len; l++)
+   if (a->others[l] != NULL)
+   hash ^= a->others[l]->hash;
+   return (hash);
+}
+
 void
 attr_free(struct rde_aspath *asp, struct attr *attr)
 {
@@ -384,7 +395,7 @@ attr_lookup(u_int8_t flags, u_int8_t typ
 {
struct attr_list*head;
struct attr *a;
-   u_int32_thash;
+   u_int64_thash;
SIPHASH_CTX ctx;
 
flags &= ~ATTR_DEFMASK; /* normalize mask */
Index: rde_rib.c
===
RCS file: /cvs/src/usr.sbin/bgpd/rde_rib.c,v
retrieving revision 1.169
diff -u -p -r1.169 rde_rib.c
--- rde_rib.c   11 Jul 2018 16:34:36 -  1.169
+++ rde_rib.c   11 Jul 2018 17:35:28 -
@@ -348,17 +348,17 @@ rib_restart(struct rib_context *ctx)
 /* path specific functions */
 
 static struct rde_aspath *path_lookup(struct rde_aspath *, struct rde_peer *);
-static voidpath_link(struct rde_aspath *, struct rde_peer *);
+static u_int64_t path_hash(struct rde_aspath *);
+static void path_link(struct rde_aspath *, struct rde_peer *);
 
-struct path_table pathtable;
+struct path_table {
+   struct aspath_head  *path_hashtbl;
+   u_int64_tpath_hashmask;
+} pathtable;
 
 SIPHASH_KEY pathtablekey;
 
-/* XXX the hash should also include communities and the other attrs */
-

Re: Remove i386 specific mention for pcvtfonts in hier.7

2018-07-11 Thread Jason McIntyre
On Wed, Jul 11, 2018 at 10:34:39AM +0200, Frederic Cambus wrote:
> Hi tech@,
> 
> Remove the i386 specific mention for pcvtfonts, they are also installed
> on alpha and amd64.
> 
> From share/misc/Makefile:
> 
> .if (${MACHINE} == "i386") || (${MACHINE} == "amd64") || \
> (${MACHINE} == "alpha")
> SUBDIR= pcvtfonts
> .endif
> 
> Comments? OK?
> 
> Index: share/man/man7/hier.7
> ===
> RCS file: /cvs/src/share/man/man7/hier.7,v
> retrieving revision 1.159
> diff -u -p -r1.159 hier.7
> --- share/man/man7/hier.7 8 Nov 2017 11:24:24 -   1.159
> +++ share/man/man7/hier.7 11 Jul 2018 08:24:33 -
> @@ -407,7 +407,7 @@ Miscellaneous system-wide ASCII text fil
>  Terminal characteristics database (see
>  .Xr termcap 5 ) .
>  .It pcvtfonts/
> -Additional i386 console fonts.
> +Additional console fonts.
>  .El
>  .Pp
>  .It mk/
> 

hi.

no objection from me. we could say "for some architectures" i suppose,
but that maybe doesn;t add much.

jmc



Re: ifconfig,route,netstat: s/tableid/rtable/ for consistency

2018-07-11 Thread Alexander Bluhm
On Tue, Apr 10, 2018 at 11:23:24PM +0200, Klemens Nanni wrote:
> Several tools may operate on specific routing tables (or routing domains
> in special cases).
> 
> With the exception of `tableid' in ifconfig(8), route(8) and netstat(1),
> all other manuals denote the respective argument as `rtable'.
> 
> Looking for use cases of rdomain(4), `man -k ar~rtable' does not list
> those tools, so I'd like to rename arguments from `tableid' to`rtable'.
> Looking for `table' obviously shows all of them, but also includes other
> (false) positives.
> 
> The following diff changes the wording in besaid manuals as well as
> route's usage for consistency and to ease searching.
> 
> Variable names in code have not been touched.
> 
> Feedback?

OK bluhm@

> Index: sbin/ifconfig/ifconfig.8
> ===
> RCS file: /cvs/src/sbin/ifconfig/ifconfig.8,v
> retrieving revision 1.305
> diff -u -p -r1.305 ifconfig.8
> --- sbin/ifconfig/ifconfig.8  16 Mar 2018 19:45:13 -  1.305
> +++ sbin/ifconfig/ifconfig.8  10 Apr 2018 20:42:02 -
> @@ -1613,7 +1613,7 @@ for a complete list of the available pro
>  .Ar tunnel-interface
>  .Op Oo Fl Oc Ns Cm keepalive Ar period count
>  .Op Oo Fl Oc Ns Cm tunnel Ar src_address dest_address
> -.Op Cm tunneldomain Ar tableid
> +.Op Cm tunneldomain Ar rtable
>  .Op Oo Fl Oc Ns Cm tunneldf
>  .Op Cm tunnelttl Ar ttl
>  .Op Oo Fl Oc Ns Cm vnetflowid
> @@ -1658,13 +1658,13 @@ The optional destination port can be spe
>  which further encapsulate the packets in UDP datagrams.
>  .It Cm -tunnel
>  Remove the source and destination tunnel addresses.
> -.It Cm tunneldomain Ar tableid
> +.It Cm tunneldomain Ar rtable
>  Use routing table
> -.Ar tableid
> +.Ar rtable
>  instead of the default table.
>  The tunnel does not need to terminate in the same routing domain as the
>  interface itself.
> -.Ar tableid
> +.Ar rtable
>  can be set to any valid routing table ID;
>  the corresponding routing domain is derived from this table.
>  .It Cm tunneldf
> Index: sbin/route/route.8
> ===
> RCS file: /cvs/src/sbin/route/route.8,v
> retrieving revision 1.83
> diff -u -p -r1.83 route.8
> --- sbin/route/route.86 Sep 2017 20:21:22 -   1.83
> +++ sbin/route/route.810 Apr 2018 20:42:02 -
> @@ -39,7 +39,7 @@
>  .Sh SYNOPSIS
>  .Nm route
>  .Op Fl dnqtv
> -.Op Fl T Ar tableid
> +.Op Fl T Ar rtable
>  .Ar command
>  .Oo
>  .Op Ar modifiers
> @@ -84,7 +84,7 @@ may require correct operation of the net
>  to forgo this, especially when attempting to repair networking operations.)
>  .It Fl q
>  Suppress all output.
> -.It Fl T Ar tableid
> +.It Fl T Ar rtable
>  Select an alternate routing table to modify or query.
>  The default is to use the current routing table.
>  .It Fl t
> @@ -101,18 +101,18 @@ utility provides the following simple co
>  .Bl -tag -width Fl
>  .It Xo
>  .Nm route
> -.Op Fl T Ar tableid
> +.Op Fl T Ar rtable
>  .Cm exec
>  .Op Ar command ...
>  .Xc
>  Execute a command forcing the process and its children to use the
>  routing table and appropriate routing domain as specified with the
> -.Fl T Ar tableid
> +.Fl T Ar rtable
>  option.
>  .It Xo
>  .Nm route
>  .Op Fl nqv
> -.Op Fl T Ar tableid
> +.Op Fl T Ar rtable
>  .Cm flush
>  .Op Ar modifiers
>  .Xc
> @@ -130,7 +130,7 @@ modifiers.
>  .It Xo
>  .Nm route
>  .Op Fl nv
> -.Op Fl T Ar tableid
> +.Op Fl T Ar rtable
>  .Cm get
>  .Op Ar modifiers
>  .Ar address
> @@ -160,7 +160,7 @@ are shown.
>  .It Xo
>  .Nm route
>  .Op Fl nv
> -.Op Fl T Ar tableid
> +.Op Fl T Ar rtable
>  .Cm show
>  .Op Ar family
>  .Op Fl gateway
> @@ -194,7 +194,7 @@ have the syntax:
>  .It Xo
>  .Nm route
>  .Op Fl dnqtv
> -.Op Fl T Ar tableid
> +.Op Fl T Ar rtable
>  .Cm add
>  .Op Ar modifiers
>  .Ar destination gateway
> @@ -202,7 +202,7 @@ have the syntax:
>  .It Xo
>  .Nm route
>  .Op Fl dnqtv
> -.Op Fl T Ar tableid
> +.Op Fl T Ar rtable
>  .Cm change
>  .Op Ar modifiers
>  .Ar destination gateway
> @@ -210,7 +210,7 @@ have the syntax:
>  .It Xo
>  .Nm route
>  .Op Fl dnqtv
> -.Op Fl T Ar tableid
> +.Op Fl T Ar rtable
>  .Cm del Ns Op Cm ete
>  .Op Ar modifiers
>  .Ar destination gateway
> Index: usr.bin/netstat/netstat.1
> ===
> RCS file: /cvs/src/usr.bin/netstat/netstat.1,v
> retrieving revision 1.81
> diff -u -p -r1.81 netstat.1
> --- usr.bin/netstat/netstat.1 12 Aug 2017 03:21:02 -  1.81
> +++ usr.bin/netstat/netstat.1 10 Apr 2018 20:42:02 -
> @@ -50,7 +50,7 @@
>  .Op Fl p Ar protocol
>  .Op Fl M Ar core
>  .Op Fl N Ar system
> -.Op Fl T Ar tableid
> +.Op Fl T Ar rtable
>  .Ek
>  .Nm netstat
>  .Op Fl bdhn
> @@ -272,7 +272,7 @@ option, also print routing labels.
>  .It Fl s
>  Show per-protocol statistics.
>  If this option is repeated, counters with a value of zero are suppressed.
> -.It Fl T Ar tableid
> +.It Fl T Ar rtable
>  Select an alte

Re: ospf6d: depend on

2018-07-11 Thread Florian Riehm

OK friehm@

On 07/11/18 18:21, Remi Locherer wrote:

On Wed, Jul 11, 2018 at 02:59:30PM +0200, Florian Riehm wrote:

Hi,

successfully tested. I like the feature!

Thanks!


Some (mostly cosmetic) comments inline.

I fixed them. Updated diff below.

  

Index: ospfe.c
===
RCS file: /cvs/src/usr.sbin/ospf6d/ospfe.c,v
retrieving revision 1.51
diff -u -p -r1.51 ospfe.c
--- ospfe.c 12 Aug 2017 16:27:50 -  1.51
+++ ospfe.c 11 Jul 2018 11:29:44 -
@@ -295,9 +295,27 @@ ospfe_dispatch_main(int fd, short event,
fatalx("IFINFO imsg with wrong len");
ifp = imsg.data;
+   LIST_FOREACH(area, &oeconf->area_list, entry) {
+   LIST_FOREACH(i, &area->iface_list, entry) {
+   if (strcmp(i->dependon,
+   ifp->name) == 0) {
+   log_warnx("interface %s"
+   " changed state, %s"
+   " depends on it",
+   ifp->name, i->name);
+   i->depend_ok =
+   ifstate_is_up(ifp);
+   if (ifstate_is_up(i))
+   orig_rtr_lsa(i);
+   }
+   }
+   }
+
+   if (!(ifp->cflags & F_IFACE_CONFIGURED))
+   break;
iface = if_find(ifp->ifindex);
if (iface == NULL)
-   fatalx("interface lost in ospfe");
+   break;
You added the F_IFACE_CONFIGURED check in your second version of the diff,
because I found a bug. Is it still necessary to remove fatalx("interface lost in
ospfe") ?


No it is not necessary anymore. I added the fatalx back.

OK?

Index: kroute.c
===
RCS file: /cvs/src/usr.sbin/ospf6d/kroute.c,v
retrieving revision 1.56
diff -u -p -r1.56 kroute.c
--- kroute.c10 Jul 2018 12:17:38 -  1.56
+++ kroute.c11 Jul 2018 13:23:28 -
@@ -810,13 +810,9 @@ if_change(u_short ifindex, int flags, st
return;
}
  
-	/* inform engine and rde about state change if interface is used */

-   if (iface->cflags & F_IFACE_CONFIGURED) {
-   main_imsg_compose_ospfe(IMSG_IFINFO, 0, iface,
-   sizeof(struct iface));
-   main_imsg_compose_rde(IMSG_IFINFO, 0, iface,
-   sizeof(struct iface));
-   }
+   /* inform engine and rde about state change */
+   main_imsg_compose_rde(IMSG_IFINFO, 0, iface, sizeof(struct iface));
+   main_imsg_compose_ospfe(IMSG_IFINFO, 0, iface, sizeof(struct iface));
  
  	isvalid = (iface->flags & IFF_UP) &&

LINK_STATE_IS_UP(iface->linkstate);
Index: ospf6d.c
===
RCS file: /cvs/src/usr.sbin/ospf6d/ospf6d.c,v
retrieving revision 1.36
diff -u -p -r1.36 ospf6d.c
--- ospf6d.c9 Jul 2018 13:19:46 -   1.36
+++ ospf6d.c9 Jul 2018 14:22:32 -
@@ -29,6 +29,7 @@
  
  #include 

  #include 
+#include 
  
  #include 

  #include 
@@ -485,17 +486,27 @@ ospf_redistribute(struct kroute *kr, u_i
  {
struct redistribute *r;
struct in6_addr  ina, inb;
+   struct iface*iface;
u_int8_t is_default = 0;
+   int  depend_ok;
  
  	/* only allow ::/0 via REDIST_DEFAULT */

if (IN6_IS_ADDR_UNSPECIFIED(&kr->prefix) && kr->prefixlen == 0)
is_default = 1;
  
  	SIMPLEQ_FOREACH(r, &ospfd_conf->redist_list, entry) {

+   if (r->dependon[0] != '\0') {
+   if ((iface = if_findname(r->dependon)))
+   depend_ok = ifstate_is_up(iface);
+   else
+   depend_ok = 0;
+   } else
+   depend_ok = 1;
+
switch (r->type & ~REDIST_NO) {
case REDIST_LABEL:
if (kr->rtlabel == r->label) {
-   *metric = r->metric;
+   *metric = depend_ok ? r->metric : MAX_METRIC;
return (r->type & REDIST_NO ? 0 : 1);
}
break;
@@ -510,7 +521,7 @@ ospf_redistribute(struct kroute *kr, u_i
if (kr->flags & F_DYNAMIC)
continue;
if (kr->flags & F_STATIC) {
-   

Re: ospf6d: depend on

2018-07-11 Thread Jeremie Courreges-Anglas
On Wed, Jul 11 2018, Remi Locherer  wrote:
> On Wed, Jul 11, 2018 at 02:59:30PM +0200, Florian Riehm wrote:
>> Hi,
>> 
>> successfully tested. I like the feature!
> Thanks!
>
>> Some (mostly cosmetic) comments inline.
> I fixed them. Updated diff below.

LGTM, ok jca@

-- 
jca | PGP : 0x1524E7EE / 5135 92C1 AD36 5293 2BDF  DDCC 0DFA 74AE 1524 E7EE



Re: ospf6d: depend on

2018-07-11 Thread Remi Locherer
On Wed, Jul 11, 2018 at 02:59:30PM +0200, Florian Riehm wrote:
> Hi,
> 
> successfully tested. I like the feature!
Thanks!

> Some (mostly cosmetic) comments inline.
I fixed them. Updated diff below.

 
> Index: ospfe.c
> ===
> RCS file: /cvs/src/usr.sbin/ospf6d/ospfe.c,v
> retrieving revision 1.51
> diff -u -p -r1.51 ospfe.c
> --- ospfe.c   12 Aug 2017 16:27:50 -  1.51
> +++ ospfe.c   11 Jul 2018 11:29:44 -
> @@ -295,9 +295,27 @@ ospfe_dispatch_main(int fd, short event,
>   fatalx("IFINFO imsg with wrong len");
>   ifp = imsg.data;
> + LIST_FOREACH(area, &oeconf->area_list, entry) {
> + LIST_FOREACH(i, &area->iface_list, entry) {
> + if (strcmp(i->dependon,
> + ifp->name) == 0) {
> + log_warnx("interface %s"
> + " changed state, %s"
> + " depends on it",
> + ifp->name, i->name);
> + i->depend_ok =
> + ifstate_is_up(ifp);
> + if (ifstate_is_up(i))
> + orig_rtr_lsa(i);
> + }
> + }
> + }
> +
> + if (!(ifp->cflags & F_IFACE_CONFIGURED))
> + break;
>   iface = if_find(ifp->ifindex);
>   if (iface == NULL)
> - fatalx("interface lost in ospfe");
> + break;
> You added the F_IFACE_CONFIGURED check in your second version of the diff,
> because I found a bug. Is it still necessary to remove fatalx("interface lost 
> in
> ospfe") ?

No it is not necessary anymore. I added the fatalx back.

OK?

Index: kroute.c
===
RCS file: /cvs/src/usr.sbin/ospf6d/kroute.c,v
retrieving revision 1.56
diff -u -p -r1.56 kroute.c
--- kroute.c10 Jul 2018 12:17:38 -  1.56
+++ kroute.c11 Jul 2018 13:23:28 -
@@ -810,13 +810,9 @@ if_change(u_short ifindex, int flags, st
return;
}
 
-   /* inform engine and rde about state change if interface is used */
-   if (iface->cflags & F_IFACE_CONFIGURED) {
-   main_imsg_compose_ospfe(IMSG_IFINFO, 0, iface,
-   sizeof(struct iface));
-   main_imsg_compose_rde(IMSG_IFINFO, 0, iface,
-   sizeof(struct iface));
-   }
+   /* inform engine and rde about state change */
+   main_imsg_compose_rde(IMSG_IFINFO, 0, iface, sizeof(struct iface));
+   main_imsg_compose_ospfe(IMSG_IFINFO, 0, iface, sizeof(struct iface));
 
isvalid = (iface->flags & IFF_UP) &&
LINK_STATE_IS_UP(iface->linkstate);
Index: ospf6d.c
===
RCS file: /cvs/src/usr.sbin/ospf6d/ospf6d.c,v
retrieving revision 1.36
diff -u -p -r1.36 ospf6d.c
--- ospf6d.c9 Jul 2018 13:19:46 -   1.36
+++ ospf6d.c9 Jul 2018 14:22:32 -
@@ -29,6 +29,7 @@
 
 #include 
 #include 
+#include 
 
 #include 
 #include 
@@ -485,17 +486,27 @@ ospf_redistribute(struct kroute *kr, u_i
 {
struct redistribute *r;
struct in6_addr  ina, inb;
+   struct iface*iface;
u_int8_t is_default = 0;
+   int  depend_ok;
 
/* only allow ::/0 via REDIST_DEFAULT */
if (IN6_IS_ADDR_UNSPECIFIED(&kr->prefix) && kr->prefixlen == 0)
is_default = 1;
 
SIMPLEQ_FOREACH(r, &ospfd_conf->redist_list, entry) {
+   if (r->dependon[0] != '\0') {
+   if ((iface = if_findname(r->dependon)))
+   depend_ok = ifstate_is_up(iface);
+   else
+   depend_ok = 0;
+   } else
+   depend_ok = 1;
+
switch (r->type & ~REDIST_NO) {
case REDIST_LABEL:
if (kr->rtlabel == r->label) {
-   *metric = r->metric;
+   *metric = depend_ok ? r->metric : MAX_METRIC;
return (r->type & REDIST_NO ? 0 : 1);
}
break;
@@ -510,7 +521,7 @@ ospf_redistribute(struct kroute *kr, u_i
if (kr->flags & F_DYNAMIC)
continue;
if (kr->flags & F_STATIC) {
-   *metric = r->m

Re: new usb id for urtwn

2018-07-11 Thread Mikhail
Sorry, new patch attached.

On Wed, Jul 11, 2018 at 4:45 PM, Stuart Henderson  wrote:
> On 2018/07/11 16:27, Mikhail wrote:
>> Ping? Ok?
>>
>> On Thu, 21 Jun 2018 at 18:28, Mikhail  wrote:
>>
>> > Taken from FreeBSD:
>> >
>> > diff --git a/sys/dev/usb/if_urtwn.c b/sys/dev/usb/if_urtwn.c
>> > index 0e204a196b1..d9aee16b05f 100644
>> > --- a/sys/dev/usb/if_urtwn.c
>> > +++ b/sys/dev/usb/if_urtwn.c
>> > @@ -306,6 +306,7 @@ static const struct urtwn_type {
>> > URTWN_DEV_8192CU(TRENDNET,  RTL8192CU),
>> > URTWN_DEV_8192CU(ZYXEL, RTL8192CU),
>> > /* URTWN_RTL8188E */
>> > +   URTWN_DEV_8188EU(ABOCOM,RTL8188EU),
>> > URTWN_DEV_8188EU(DLINK, DWA123D1),
>> > URTWN_DEV_8188EU(DLINK, DWA125D1),
>> > URTWN_DEV_8188EU(ELECOM,WDC150SU2M),
>> >
>
> Not OK. Try compiling it...
>
diff --git a/sys/dev/usb/if_urtwn.c b/sys/dev/usb/if_urtwn.c
index 0e204a196b1..e6152e8fb13 100644
--- a/sys/dev/usb/if_urtwn.c
+++ b/sys/dev/usb/if_urtwn.c
@@ -306,6 +306,7 @@ static const struct urtwn_type {
 	URTWN_DEV_8192CU(TRENDNET,	RTL8192CU),
 	URTWN_DEV_8192CU(ZYXEL,		RTL8192CU),
 	/* URTWN_RTL8188E */
+	URTWN_DEV_8188EU(ABOCOM,RTL8188EU),
 	URTWN_DEV_8188EU(DLINK,		DWA123D1),
 	URTWN_DEV_8188EU(DLINK,		DWA125D1),
 	URTWN_DEV_8188EU(ELECOM,	WDC150SU2M),
diff --git a/sys/dev/usb/usbdevs.h b/sys/dev/usb/usbdevs.h
index 0fc246400a5..d8688378143 100644
--- a/sys/dev/usb/usbdevs.h
+++ b/sys/dev/usb/usbdevs.h
@@ -727,6 +727,7 @@
 #define	USB_PRODUCT_ABOCOM_XX9	0x4104		/* XX9 */
 #define	USB_PRODUCT_ABOCOM_WL54	0x6001		/* WL54 */
 #define	USB_PRODUCT_ABOCOM_RTL8192CU	0x8178		/* RTL8192CU */
+#define	USB_PRODUCT_ABOCOM_RTL8188EU	0x8179		/* RTL8188EU */
 #define	USB_PRODUCT_ABOCOM_RTL8188CU_1	0x8188		/* RTL8188CU */
 #define	USB_PRODUCT_ABOCOM_RTL8188CU_2	0x8189		/* RTL8188CU */
 #define	USB_PRODUCT_ABOCOM_XX10	0xabc1		/* XX10 */


Re: new usb id for urtwn

2018-07-11 Thread Stuart Henderson
On 2018/07/11 16:27, Mikhail wrote:
> Ping? Ok?
> 
> On Thu, 21 Jun 2018 at 18:28, Mikhail  wrote:
> 
> > Taken from FreeBSD:
> >
> > diff --git a/sys/dev/usb/if_urtwn.c b/sys/dev/usb/if_urtwn.c
> > index 0e204a196b1..d9aee16b05f 100644
> > --- a/sys/dev/usb/if_urtwn.c
> > +++ b/sys/dev/usb/if_urtwn.c
> > @@ -306,6 +306,7 @@ static const struct urtwn_type {
> > URTWN_DEV_8192CU(TRENDNET,  RTL8192CU),
> > URTWN_DEV_8192CU(ZYXEL, RTL8192CU),
> > /* URTWN_RTL8188E */
> > +   URTWN_DEV_8188EU(ABOCOM,RTL8188EU),
> > URTWN_DEV_8188EU(DLINK, DWA123D1),
> > URTWN_DEV_8188EU(DLINK, DWA125D1),
> > URTWN_DEV_8188EU(ELECOM,WDC150SU2M),
> >

Not OK. Try compiling it...



Re: new usb id for urtwn

2018-07-11 Thread Mikhail
Ping? Ok?

On Thu, 21 Jun 2018 at 18:28, Mikhail  wrote:

> Taken from FreeBSD:
>
> diff --git a/sys/dev/usb/if_urtwn.c b/sys/dev/usb/if_urtwn.c
> index 0e204a196b1..d9aee16b05f 100644
> --- a/sys/dev/usb/if_urtwn.c
> +++ b/sys/dev/usb/if_urtwn.c
> @@ -306,6 +306,7 @@ static const struct urtwn_type {
> URTWN_DEV_8192CU(TRENDNET,  RTL8192CU),
> URTWN_DEV_8192CU(ZYXEL, RTL8192CU),
> /* URTWN_RTL8188E */
> +   URTWN_DEV_8188EU(ABOCOM,RTL8188EU),
> URTWN_DEV_8188EU(DLINK, DWA123D1),
> URTWN_DEV_8188EU(DLINK, DWA125D1),
> URTWN_DEV_8188EU(ELECOM,WDC150SU2M),
>


Re: signal to process or posix thread

2018-07-11 Thread Alexander Bluhm
On Wed, Jul 11, 2018 at 03:40:23PM +0300, Paul Irofti wrote:
> > This is my original diff with some twaeks from visa@.
> 
> While I think this is a step in the right direction I don't think is the
> proper solution to the problem.

It is not intended as final solution.  My problem is that posixtestsuite
does not finish during regress.  Signals are not processes resulting
in hangs.  Then it is aborted by an overall timeout.

> I don't think this handles pthread_kill() signals and I agree with mpi@
> that the path should be split between thread signals and process signals.

The NetBSD approach seem correct.  We need a pending signal list
per thread and per process.  This is just a bunch of work.

> I will try to come up with something better in the following days.
> In the meantime if you guys want to commit this bit, I will not
> object.

I am happy that pirofti@ jumps in for the correct fix.  I would
prefer if I could get oks for my version now.  Then we would finish
posixtestsuite during regress in time and see daily results here
again.

http://bluhm.genua.de/testsuite/posixtestsuite/posixtestsuite.html

This would also help to visualize the effects of pirofti@'s fix.

bluhm

> > Index: kern/kern_sig.c
> > ===
> > RCS file: /data/mirror/openbsd/cvs/src/sys/kern/kern_sig.c,v
> > retrieving revision 1.220
> > diff -u -p -r1.220 kern_sig.c
> > --- kern/kern_sig.c 28 Apr 2018 03:13:04 -  1.220
> > +++ kern/kern_sig.c 9 Jul 2018 20:36:07 -
> > @@ -1155,14 +1155,17 @@ issignal(struct proc *p)
> > int s;
> >  
> > for (;;) {
> > -   mask = p->p_siglist & ~p->p_sigmask;
> > +   mask = SIGPENDING(p);
> > if (pr->ps_flags & PS_PPWAIT)
> > mask &= ~stopsigmask;
> > if (mask == 0)  /* no signal to send */
> > return (0);
> > signum = ffs((long)mask);
> > mask = sigmask(signum);
> > -   atomic_clearbits_int(&p->p_siglist, mask);
> > +   if (p->p_siglist & mask)
> > +   atomic_clearbits_int(&p->p_siglist, mask);
> > +   else
> > +   atomic_clearbits_int(&pr->ps_mainproc->p_siglist, mask);
> >  
> > /*
> >  * We should see pending but ignored signals
> > @@ -1840,7 +1843,7 @@ userret(struct proc *p)
> > KERNEL_UNLOCK();
> > }
> >  
> > -   if (SIGPENDING(p)) {
> > +   if (SIGPENDING(p) != 0) {
> > KERNEL_LOCK();
> > while ((signum = CURSIG(p)) != 0)
> > postsig(p, signum);
> > Index: sys/signalvar.h
> > ===
> > RCS file: /data/mirror/openbsd/cvs/src/sys/sys/signalvar.h,v
> > retrieving revision 1.30
> > diff -u -p -r1.30 signalvar.h
> > --- sys/signalvar.h 24 Mar 2018 04:13:59 -  1.30
> > +++ sys/signalvar.h 9 Jul 2018 20:52:50 -
> > @@ -68,7 +68,9 @@ structsigacts {
> >  /*
> >   * Check if process p has an unmasked signal pending.
> >   */
> > -#defineSIGPENDING(p)   (((p)->p_siglist & ~(p)->p_sigmask) != 0)
> > +#defineSIGPENDING(p)   
> > \
> > +   (((p)->p_siglist | (p)->p_p->ps_mainproc->p_siglist) &  \
> > +   ~(p)->p_sigmask)
> >  
> >  /*
> >   * Determine signal that should be delivered to process p, the current
> > @@ -76,10 +78,9 @@ struct   sigacts {
> >   * action, the process stops in issignal().
> >   */
> >  #defineCURSIG(p)   
> > \
> > -   (((p)->p_siglist == 0 ||\
> > -   (((p)->p_p->ps_flags & PS_TRACED) == 0 &&   \
> > -   ((p)->p_siglist & ~(p)->p_sigmask) == 0)) ? \
> > -   0 : issignal(p))
> > +   (p)->p_siglist | (p)->p_p->ps_mainproc->p_siglist) == 0) || \
> > +   (((p)->p_p->ps_flags & PS_TRACED) == 0 && SIGPENDING(p) == 0))  \
> > +   ? 0 : issignal(p))
> >  
> >  /*
> >   * Clear a pending signal from a process.



Re: ospf6d: depend on

2018-07-11 Thread Florian Riehm

Hi,

successfully tested. I like the feature!

Some (mostly cosmetic) comments inline.


Index: ospfe.c
===
RCS file: /cvs/src/usr.sbin/ospf6d/ospfe.c,v
retrieving revision 1.51
diff -u -p -r1.51 ospfe.c
--- ospfe.c 12 Aug 2017 16:27:50 -  1.51
+++ ospfe.c 11 Jul 2018 11:29:44 -
@@ -295,9 +295,27 @@ ospfe_dispatch_main(int fd, short event,
fatalx("IFINFO imsg with wrong len");
ifp = imsg.data;
 
+			LIST_FOREACH(area, &oeconf->area_list, entry) {

+   LIST_FOREACH(i, &area->iface_list, entry) {
+   if (strcmp(i->dependon,
+   ifp->name) == 0) {
+   log_warnx("interface %s"
+   " changed state, %s"
+   " depends on it",
+   ifp->name, i->name);
+   i->depend_ok =
+   ifstate_is_up(ifp);
+   if (ifstate_is_up(i))
+   orig_rtr_lsa(i);
+   }
+   }
+   }
+
+   if (!(ifp->cflags & F_IFACE_CONFIGURED))
+   break;
iface = if_find(ifp->ifindex);
if (iface == NULL)
-   fatalx("interface lost in ospfe");
+   break;
You added the F_IFACE_CONFIGURED check in your second version of the diff,
because I found a bug. Is it still necessary to remove fatalx("interface lost in
ospfe") ?
 
 			wasvalid = (iface->flags & IFF_UP) &&

LINK_STATE_IS_UP(iface->linkstate);
@@ -834,7 +852,11 @@ orig_rtr_lsa_area(struct area *area)
log_debug("orig_rtr_lsa: point-to-point, "
"interface %s", iface->name);
rtr_link.type = LINK_TYPE_POINTTOPOINT;
-   rtr_link.metric = htons(iface->metric);
+   if (iface->dependon[0] != '\0' &&
+   iface->depend_ok ==0)
Whitespace before 0
+   rtr_link.metric = MAX_METRIC;
+   else
+   rtr_link.metric = htons(iface->metric);
rtr_link.iface_id = htonl(iface->ifindex);
rtr_link.nbr_iface_id = htonl(nbr->iface_id);
rtr_link.nbr_rtr_id = nbr->id.s_addr;
@@ -859,7 +881,12 @@ orig_rtr_lsa_area(struct area *area)
"interface %s", iface->name);
 
 	rtr_link.type = LINK_TYPE_TRANSIT_NET;

-   rtr_link.metric = htons(iface->metric);
+   if (iface->dependon[0] != '\0' &&
+   iface->depend_ok ==0)
Whitespace before 0
+   rtr_link.metric = MAX_METRIC;
+   else
+   rtr_link.metric =
+   htons(iface->metric);
rtr_link.iface_id = 
htonl(iface->ifindex);
rtr_link.nbr_iface_id = 
htonl(iface->dr->iface_id);
rtr_link.nbr_rtr_id = 
iface->dr->id.s_addr;
Index: rde.c
===
RCS file: /cvs/src/usr.sbin/ospf6d/rde.c,v
retrieving revision 1.76
diff -u -p -r1.76 rde.c
--- rde.c   12 Jun 2018 20:12:36 -  1.76
+++ rde.c   10 Jul 2018 09:52:42 -
@@ -706,6 +706,25 @@ rde_dispatch_parent(int fd, short event,
fatalx("IFINFO imsg with wrong len");
 
 			ifp = imsg.data;

+
+   LIST_FOREACH(area, &rdeconf->area_list, entry) {
+   orig_lsa = 0;
+   LIST_FOREACH(i, &area->iface_list, entry) {
+   if (strcmp(i->dependon,
+   ifp->name) == 0) {
+   i->depend_ok =
+   ifstate_is_up(ifp);
+   if (ifstate_is_up(i)) {
+   orig_lsa = 1;
+   }
unnecessary curly braces



Re: ospfd printconf: print rdomain

2018-07-11 Thread Klemens Nanni
OK



Re: signal to process or posix thread

2018-07-11 Thread Paul Irofti
On Mon, Jul 09, 2018 at 10:59:54PM +0200, Alexander Bluhm wrote:
> On Mon, Jul 09, 2018 at 11:27:55AM -0900, Philip Guenther wrote:
> > Those signals are handled by the first thread that
> > > doesn't have them masked. In that case, it should be put on the pending
> > > list of the process and any unmasking operation should check the pending
> > > list on whether a signal should be delivered delayed.
> > >
> > 
> > Yep.
> 
> This is my original diff with some twaeks from visa@.

While I think this is a step in the right direction I don't think is the
proper solution to the problem.

I don't think this handles pthread_kill() signals and I agree with mpi@
that the path should be split between thread signals and process signals.

I am tracking this issue myself for almost two weeks now and while
indeed this diff seems to workaround the posixsuite issue, it does still
manifest in complex scenarios like lang/mono.

I will try to come up with something better in the following days.
In the meantime if you guys want to commit this bit, I will not
object.

> Index: kern/kern_sig.c
> ===
> RCS file: /data/mirror/openbsd/cvs/src/sys/kern/kern_sig.c,v
> retrieving revision 1.220
> diff -u -p -r1.220 kern_sig.c
> --- kern/kern_sig.c   28 Apr 2018 03:13:04 -  1.220
> +++ kern/kern_sig.c   9 Jul 2018 20:36:07 -
> @@ -1155,14 +1155,17 @@ issignal(struct proc *p)
>   int s;
>  
>   for (;;) {
> - mask = p->p_siglist & ~p->p_sigmask;
> + mask = SIGPENDING(p);
>   if (pr->ps_flags & PS_PPWAIT)
>   mask &= ~stopsigmask;
>   if (mask == 0)  /* no signal to send */
>   return (0);
>   signum = ffs((long)mask);
>   mask = sigmask(signum);
> - atomic_clearbits_int(&p->p_siglist, mask);
> + if (p->p_siglist & mask)
> + atomic_clearbits_int(&p->p_siglist, mask);
> + else
> + atomic_clearbits_int(&pr->ps_mainproc->p_siglist, mask);
>  
>   /*
>* We should see pending but ignored signals
> @@ -1840,7 +1843,7 @@ userret(struct proc *p)
>   KERNEL_UNLOCK();
>   }
>  
> - if (SIGPENDING(p)) {
> + if (SIGPENDING(p) != 0) {
>   KERNEL_LOCK();
>   while ((signum = CURSIG(p)) != 0)
>   postsig(p, signum);
> Index: sys/signalvar.h
> ===
> RCS file: /data/mirror/openbsd/cvs/src/sys/sys/signalvar.h,v
> retrieving revision 1.30
> diff -u -p -r1.30 signalvar.h
> --- sys/signalvar.h   24 Mar 2018 04:13:59 -  1.30
> +++ sys/signalvar.h   9 Jul 2018 20:52:50 -
> @@ -68,7 +68,9 @@ struct  sigacts {
>  /*
>   * Check if process p has an unmasked signal pending.
>   */
> -#define  SIGPENDING(p)   (((p)->p_siglist & ~(p)->p_sigmask) != 0)
> +#define  SIGPENDING(p)   
> \
> + (((p)->p_siglist | (p)->p_p->ps_mainproc->p_siglist) &  \
> + ~(p)->p_sigmask)
>  
>  /*
>   * Determine signal that should be delivered to process p, the current
> @@ -76,10 +78,9 @@ struct sigacts {
>   * action, the process stops in issignal().
>   */
>  #define  CURSIG(p)   
> \
> - (((p)->p_siglist == 0 ||\
> - (((p)->p_p->ps_flags & PS_TRACED) == 0 &&   \
> - ((p)->p_siglist & ~(p)->p_sigmask) == 0)) ? \
> - 0 : issignal(p))
> + (p)->p_siglist | (p)->p_p->ps_mainproc->p_siglist) == 0) || \
> + (((p)->p_p->ps_flags & PS_TRACED) == 0 && SIGPENDING(p) == 0))  \
> + ? 0 : issignal(p))
>  
>  /*
>   * Clear a pending signal from a process.



ospfd printconf: print rdomain

2018-07-11 Thread Remi Locherer
This makes "ospfd -nv" print the rdomain config option if present.

OK?

Remi

Index: printconf.c
===
RCS file: /cvs/src/usr.sbin/ospfd/printconf.c,v
retrieving revision 1.18
diff -u -p -r1.18 printconf.c
--- printconf.c 5 Feb 2018 12:11:28 -   1.18
+++ printconf.c 11 Jul 2018 12:23:38 -
@@ -44,6 +44,9 @@ print_mainconf(struct ospfd_conf *conf)
else
printf("fib-update yes\n");
 
+   if (conf->rdomain)
+   printf("rdomain %d\n", conf->rdomain);
+
if (conf->rfc1583compat)
printf("rfc1583compat yes\n");
else



Re: ospf6d: depend on

2018-07-11 Thread Remi Locherer
On Tue, Jul 10, 2018 at 03:22:43PM +0200, Remi Locherer wrote:
> Hi,
> 
> With the "depend on" option routes are sent out with a metric of 65535 if
> the referenced interface is down or in state backup. This is especially
> useful on a carp cluster to ensure all traffic goes to the carp master.
> 
> This is similar to what we have for ospfd.
> 
> A configuration using this feature looks like this:
> 
> 
> redistribute default depend on carp0
> redistribute rtlabel toOSPF depend on carp0
> area 0.0.0.0 {
> interface vether0 {
> depend on carp0
> }
> interface vether77 {
> passive
> depend on carp0
> }
> }
> 
> 
> 3 LSA types are affected by this:
> - ext lsa (redistribute)
> - router lsa (active interfaces)
> - intra area lsa (passive interfaces)

friehm's lab pointed out that I missed a check in ospfe.
Updated diff below.

OK?

Remi


Index: kroute.c
===
RCS file: /cvs/src/usr.sbin/ospf6d/kroute.c,v
retrieving revision 1.56
diff -u -p -r1.56 kroute.c
--- kroute.c10 Jul 2018 12:17:38 -  1.56
+++ kroute.c10 Jul 2018 12:38:26 -
@@ -810,13 +810,9 @@ if_change(u_short ifindex, int flags, st
return;
}
 
-   /* inform engine and rde about state change if interface is used */
-   if (iface->cflags & F_IFACE_CONFIGURED) {
-   main_imsg_compose_ospfe(IMSG_IFINFO, 0, iface,
-   sizeof(struct iface));
-   main_imsg_compose_rde(IMSG_IFINFO, 0, iface,
-   sizeof(struct iface));
-   }
+   /* inform engine and rde about state change */
+   main_imsg_compose_rde(IMSG_IFINFO, 0, iface, sizeof(struct iface));
+   main_imsg_compose_ospfe(IMSG_IFINFO, 0, iface, sizeof(struct iface));
 
isvalid = (iface->flags & IFF_UP) &&
LINK_STATE_IS_UP(iface->linkstate);
Index: ospf6d.c
===
RCS file: /cvs/src/usr.sbin/ospf6d/ospf6d.c,v
retrieving revision 1.36
diff -u -p -r1.36 ospf6d.c
--- ospf6d.c9 Jul 2018 13:19:46 -   1.36
+++ ospf6d.c9 Jul 2018 14:22:32 -
@@ -29,6 +29,7 @@
 
 #include 
 #include 
+#include 
 
 #include 
 #include 
@@ -485,17 +486,27 @@ ospf_redistribute(struct kroute *kr, u_i
 {
struct redistribute *r;
struct in6_addr  ina, inb;
+   struct iface*iface;
u_int8_t is_default = 0;
+   int  depend_ok;
 
/* only allow ::/0 via REDIST_DEFAULT */
if (IN6_IS_ADDR_UNSPECIFIED(&kr->prefix) && kr->prefixlen == 0)
is_default = 1;
 
SIMPLEQ_FOREACH(r, &ospfd_conf->redist_list, entry) {
+   if (r->dependon[0] != '\0') {
+   if ((iface = if_findname(r->dependon)))
+   depend_ok = ifstate_is_up(iface);
+   else
+   depend_ok = 0;
+   } else
+   depend_ok = 1;
+
switch (r->type & ~REDIST_NO) {
case REDIST_LABEL:
if (kr->rtlabel == r->label) {
-   *metric = r->metric;
+   *metric = depend_ok ? r->metric : MAX_METRIC;
return (r->type & REDIST_NO ? 0 : 1);
}
break;
@@ -510,7 +521,7 @@ ospf_redistribute(struct kroute *kr, u_i
if (kr->flags & F_DYNAMIC)
continue;
if (kr->flags & F_STATIC) {
-   *metric = r->metric;
+   *metric = depend_ok ? r->metric : MAX_METRIC;
return (r->type & REDIST_NO ? 0 : 1);
}
break;
@@ -520,7 +531,7 @@ ospf_redistribute(struct kroute *kr, u_i
if (kr->flags & F_DYNAMIC)
continue;
if (kr->flags & F_CONNECTED) {
-   *metric = r->metric;
+   *metric = depend_ok ? r->metric : MAX_METRIC;
return (r->type & REDIST_NO ? 0 : 1);
}
break;
@@ -531,7 +542,8 @@ ospf_redistribute(struct kroute *kr, u_i
if (IN6_IS_ADDR_UNSPECIFIED(&r->addr) &&
r->prefixlen == 0) {
if (is_default) {
-   *metric = r->metric;
+   *metric = depend_ok ? r->metric :
+   MAX_METRIC;
return (r->type & REDIST_NO ? 0 : 1);
} else
   

Re: ospf6ctl parse.y: remove wrong comment

2018-07-11 Thread Jeremie Courreges-Anglas
On Wed, Jul 11 2018, Remi Locherer  wrote:
> in parse.y from ospfd this comment is followed by
>   md_list_clr(&globaldefs.md_list);
> which does not exist in ospd6d.
>
> OK?

Sure.

> Remi
>
>
> Index: parse.y
> ===
> RCS file: /cvs/src/usr.sbin/ospf6d/parse.y,v
> retrieving revision 1.34
> diff -u -p -r1.34 parse.y
> --- parse.y   9 Jul 2018 12:05:11 -   1.34
> +++ parse.y   11 Jul 2018 10:06:59 -
> @@ -985,7 +985,6 @@ parse_config(char *filename, int opts)
>   }
>   }
>  
> - /* free global config defaults */
>   if (errors) {
>   clear_config(conf);
>   return (NULL);
>


-- 
jca | PGP : 0x1524E7EE / 5135 92C1 AD36 5293 2BDF  DDCC 0DFA 74AE 1524 E7EE



Re: ospfd: change control socket to ospfd.sock.

2018-07-11 Thread Jeremie Courreges-Anglas
On Wed, Jul 11 2018, Remi Locherer  wrote:
> Hi,
>
> This changes the name of the ospfd control socket to include the rdomain.
> It's similar to what bgpd does.
>
> OK?

ok with the change suggested by friehm@

-- 
jca | PGP : 0x1524E7EE / 5135 92C1 AD36 5293 2BDF  DDCC 0DFA 74AE 1524 E7EE



Re: usbdevs(8): fewer buttons

2018-07-11 Thread Jeremie Courreges-Anglas
On Wed, Jul 11 2018, Martin Pieuchot  wrote:
> Instead of having a button for printing the driver(s) attached to a USB
> device, do it when invoked with '-v'.  This allows me to recycle '-d'.
>
> I'm now using it, like pcidump(8) does, to specify a specific device
> node.
>
> My plan is then to use '-f' to force a device to attach as ugen(4).  In
> that case the output would be:
>
>  $ usbdevs -v
>  ...
>  addr 02: 04f2:b45d Chicony Electronics Co.,Ltd., Integrated Camera
>   high speed, power 500 mA, config 1, rev 0.29, iSerialNumber 0x0001
>   driver: ugen0 (forced)
>  
> ok?

ok jca@

-- 
jca | PGP : 0x1524E7EE / 5135 92C1 AD36 5293 2BDF  DDCC 0DFA 74AE 1524 E7EE



ospf6ctl parse.y: remove wrong comment

2018-07-11 Thread Remi Locherer
in parse.y from ospfd this comment is followed by
md_list_clr(&globaldefs.md_list);
which does not exist in ospd6d.

OK?

Remi


Index: parse.y
===
RCS file: /cvs/src/usr.sbin/ospf6d/parse.y,v
retrieving revision 1.34
diff -u -p -r1.34 parse.y
--- parse.y 9 Jul 2018 12:05:11 -   1.34
+++ parse.y 11 Jul 2018 10:06:59 -
@@ -985,7 +985,6 @@ parse_config(char *filename, int opts)
}
}
 
-   /* free global config defaults */
if (errors) {
clear_config(conf);
return (NULL);



usbdevs(8): fewer buttons

2018-07-11 Thread Martin Pieuchot
Instead of having a button for printing the driver(s) attached to a USB
device, do it when invoked with '-v'.  This allows me to recycle '-d'.

I'm now using it, like pcidump(8) does, to specify a specific device
node.

My plan is then to use '-f' to force a device to attach as ugen(4).  In
that case the output would be:

 $ usbdevs -v
 ...
 addr 02: 04f2:b45d Chicony Electronics Co.,Ltd., Integrated Camera
  high speed, power 500 mA, config 1, rev 0.29, iSerialNumber 0x0001
  driver: ugen0 (forced)
 
ok?

Index: usbdevs.8
===
RCS file: /cvs/src/usr.sbin/usbdevs/usbdevs.8,v
retrieving revision 1.11
diff -u -p -r1.11 usbdevs.8
--- usbdevs.8   8 Jul 2018 20:04:44 -   1.11
+++ usbdevs.8   11 Jul 2018 09:31:39 -
@@ -36,22 +36,19 @@
 .Nd show USB devices connected to the system
 .Sh SYNOPSIS
 .Nm
-.Op Fl dv
+.Op Fl v
 .Op Fl a Ar addr
-.Op Fl f Ar dev
+.Op Fl d Ar usbdev
 .Sh DESCRIPTION
 .Nm
 prints a listing of all USB devices connected to the system
 with some information about each device.
-The indentation of each line indicates its distance from the root.
 .Pp
 The options are as follows:
 .Bl -tag -width Fl
 .It Fl a Ar addr
 Only print information about the device at the given address.
-.It Fl d
-Show the device drivers associated with each device.
-.It Fl f Ar dev
+.It Fl d Ar usbdev
 Only print information for the given USB controller.
 .It Fl v
 Be verbose.
Index: usbdevs.c
===
RCS file: /cvs/src/usr.sbin/usbdevs/usbdevs.c,v
retrieving revision 1.28
diff -u -p -r1.28 usbdevs.c
--- usbdevs.c   10 Jul 2018 09:18:36 -  1.28
+++ usbdevs.c   11 Jul 2018 09:30:15 -
@@ -51,7 +51,6 @@
 #define USBDEV "/dev/usb"
 
 int verbose = 0;
-int showdevs = 0;
 
 void usage(void);
 void usbdev(int f, uint8_t);
@@ -64,7 +63,7 @@ extern char *__progname;
 void
 usage(void)
 {
-   fprintf(stderr, "usage: %s [-dv] [-a addr] [-f dev]\n", __progname);
+   fprintf(stderr, "usage: %s [-v] [-a addr] [-d usbdev]\n", __progname);
exit(1);
 }
 
@@ -124,7 +123,7 @@ usbdev(int f, uint8_t addr)
}
printf("\n");
 
-   if (showdevs) {
+   if (verbose) {
for (i = 0; i < USB_MAX_DEVNAMES; i++)
if (di.udi_devnames[i][0])
printf("\t driver: %s\n", di.udi_devnames[i]);
@@ -238,7 +237,7 @@ main(int argc, char **argv)
int addr = 0;
int ncont;
 
-   while ((ch = getopt(argc, argv, "a:df:v?")) != -1) {
+   while ((ch = getopt(argc, argv, "a:d:v?")) != -1) {
switch (ch) {
case 'a':
addr = strtonum(optarg, 1, USB_MAX_DEVICES, &errstr);
@@ -246,9 +245,6 @@ main(int argc, char **argv)
errx(1, "addr %s", errstr);
break;
case 'd':
-   showdevs = 1;
-   break;
-   case 'f':
dev = optarg;
break;
case 'v':



Re: ospfd: change control socket to ospfd.sock.

2018-07-11 Thread Florian Riehm

Please initialize *sockname with NULL, then OK .

On 07/11/18 00:33, Remi Locherer wrote:

Hi,

This changes the name of the ospfd control socket to include the rdomain.
It's similar to what bgpd does.

OK?

Remi


Index: ospfd/ospfd.c
===
RCS file: /cvs/src/usr.sbin/ospfd/ospfd.c,v
retrieving revision 1.98
diff -u -p -r1.98 ospfd.c
--- ospfd/ospfd.c   9 Jul 2018 13:19:46 -   1.98
+++ ospfd/ospfd.c   10 Jul 2018 22:24:02 -
@@ -119,7 +119,6 @@ main(int argc, char *argv[])
  
  	conffile = CONF_FILE;

ospfd_process = PROC_MAIN;
-   sockname = OSPFD_SOCKET;
  
  	log_init(1, LOG_DAEMON);	/* log to stderr until daemonized */

log_procinit(log_procnames[ospfd_process]);
@@ -185,6 +184,13 @@ main(int argc, char *argv[])
kif_clear();
exit(1);
}
+
+   if (sockname == NULL) {
+   if (asprintf(&sockname, "%s.%d", OSPFD_SOCKET,
+   ospfd_conf->rdomain) == -1)
+   err(1, "asprintf");
+   }
+
ospfd_conf->csock = sockname;
  
  	if (ospfd_conf->opts & OSPFD_OPT_NOACTION) {

Index: ospfctl/ospfctl.c
===
RCS file: /cvs/src/usr.sbin/ospfctl/ospfctl.c,v
retrieving revision 1.64
diff -u -p -r1.64 ospfctl.c
--- ospfctl/ospfctl.c   5 Dec 2016 22:39:25 -   1.64
+++ ospfctl/ospfctl.c   10 Jul 2018 21:32:27 -
@@ -89,13 +89,16 @@ main(int argc, char *argv[])
struct parse_result *res;
struct imsg  imsg;
unsigned int ifidx = 0;
-   int  ctl_sock;
+   int  ctl_sock, r;
int  done = 0;
int  n, verbose = 0;
int  ch;
char*sockname;
  
-	sockname = OSPFD_SOCKET;

+   r = getrtable();
+   if (asprintf(&sockname, "%s.%d", OSPFD_SOCKET, r) == -1)
+   err(1, "asprintf");
+
while ((ch = getopt(argc, argv, "s:")) != -1) {
switch (ch) {
case 's':





Re: Remove i386 specific mention for pcvtfonts in hier.7

2018-07-11 Thread Matthieu Herrb
On Wed, Jul 11, 2018 at 10:34:39AM +0200, Frederic Cambus wrote:
> Hi tech@,
> 
> Remove the i386 specific mention for pcvtfonts, they are also installed
> on alpha and amd64.

I guess they could be installed on all archirectures. 
load_font is supported on many of them and the risk of forgetting to
add new ones to that Makefile is high :)

> 
> From share/misc/Makefile:
> 
> .if (${MACHINE} == "i386") || (${MACHINE} == "amd64") || \
> (${MACHINE} == "alpha")
> SUBDIR= pcvtfonts
> .endif
> 
> Comments? OK?
> 
> Index: share/man/man7/hier.7
> ===
> RCS file: /cvs/src/share/man/man7/hier.7,v
> retrieving revision 1.159
> diff -u -p -r1.159 hier.7
> --- share/man/man7/hier.7 8 Nov 2017 11:24:24 -   1.159
> +++ share/man/man7/hier.7 11 Jul 2018 08:24:33 -
> @@ -407,7 +407,7 @@ Miscellaneous system-wide ASCII text fil
>  Terminal characteristics database (see
>  .Xr termcap 5 ) .
>  .It pcvtfonts/
> -Additional i386 console fonts.
> +Additional console fonts.
>  .El
>  .Pp
>  .It mk/

-- 
Matthieu Herrb



Re: bgpd: announce prefixes with priority n

2018-07-11 Thread Remi Locherer
On Wed, Jul 11, 2018 at 12:43:41AM +0200, Sebastian Benoit wrote:
> hi,
> 
> allows you to announce prefixes from the kernel routing table selected by
> priority.
> 
> lightly tested, as in, the config part works.
> 
>   network inet priority 32
> 
> ok?

works in my lab setup. OK remi@

> 
> (benno_bgpd_announce_network_by_priority.diff)
> 
> diff --git usr.sbin/bgpd/bgpd.conf.5 usr.sbin/bgpd/bgpd.conf.5
> index d49a239ca22..f44805155f0 100644
> --- usr.sbin/bgpd/bgpd.conf.5
> +++ usr.sbin/bgpd/bgpd.conf.5
> @@ -273,6 +273,11 @@ Log received and sent updates.
>  .Pq Ic inet Ns | Ns Ic inet6
>  .Ic rtlabel Ar label Op Ic set ...\&
>  .Xc
> +.It Xo
> +.Ic network
> +.Pq Ic inet Ns | Ns Ic inet6
> +.Ic priority Ar number Op Ic set ...\&
> +.Xc
>  .\" NOT IMPLEMENTED. DO WE WANT THIS?
>  .\" .It Xo
>  .\" .Ic network prefix-set
> @@ -291,6 +296,11 @@ If set to
>  routes with the specified
>  .Ar label
>  will be announced.
> +If set to
> +.Ic priority ,
> +routes with the specified
> +.Ar priority
> +will be announced.
>  .Bd -literal -offset indent
>  network 192.168.7.0/24
>  .Ed
> diff --git usr.sbin/bgpd/bgpd.h usr.sbin/bgpd/bgpd.h
> index 5d53b019d97..bb8c4df42e6 100644
> --- usr.sbin/bgpd/bgpd.h
> +++ usr.sbin/bgpd/bgpd.h
> @@ -344,7 +344,8 @@ enum network_type {
>   NETWORK_STATIC,
>   NETWORK_CONNECTED,
>   NETWORK_RTLABEL,
> - NETWORK_MRTCLONE
> + NETWORK_MRTCLONE,
> + NETWORK_PRIORITY
>  };
>  
>  struct network_config {
> @@ -355,6 +356,7 @@ struct network_config {
>   u_int16_trtlabel;
>   enum network_typetype;
>   u_int8_t prefixlen;
> + u_int8_t priority;
>   u_int8_t old;   /* used for reloading */
>  };
>  
> diff --git usr.sbin/bgpd/kroute.c usr.sbin/bgpd/kroute.c
> index be4811d132a..73d6c43c359 100644
> --- usr.sbin/bgpd/kroute.c
> +++ usr.sbin/bgpd/kroute.c
> @@ -1127,6 +1127,10 @@ kr_net_match(struct ktable *kt, struct kroute *kr)
>   case NETWORK_MRTCLONE:
>   /* can not happen */
>   break;
> + case NETWORK_PRIORITY:
> + if (kr->priority == xn->net.priority)
> + return (xn);
> + break;
>   }
>   }
>   return (NULL);
> @@ -1163,6 +1167,10 @@ kr_net_match6(struct ktable *kt, struct kroute6 *kr6)
>   case NETWORK_MRTCLONE:
>   /* can not happen */
>   break;
> + case NETWORK_PRIORITY:
> + if (kr6->priority == xn->net.priority)
> + return (xn);
> + break;
>   }
>   }
>   return (NULL);
> diff --git usr.sbin/bgpd/parse.y usr.sbin/bgpd/parse.y
> index 2257473f7ce..86f8069e9a3 100644
> --- usr.sbin/bgpd/parse.y
> +++ usr.sbin/bgpd/parse.y
> @@ -211,7 +211,7 @@ typedef struct {
>  %token   COMMUNITY EXTCOMMUNITY LARGECOMMUNITY
>  %token   PREFIX PREFIXLEN PREFIXSET SOURCEAS TRANSITAS PEERAS DELETE 
> MAXASLEN
>  %token   MAXASSEQ SET LOCALPREF MED METRIC NEXTHOP REJECT BLACKHOLE 
> NOMODIFY SELF
> -%token   PREPEND_SELF PREPEND_PEER PFTABLE WEIGHT RTLABEL ORIGIN
> +%token   PREPEND_SELF PREPEND_PEER PFTABLE WEIGHT RTLABEL ORIGIN PRIORITY
>  %token   ERROR INCLUDE
>  %token   IPSEC ESP AH SPI IKE
>  %token   IPV4 IPV6
> @@ -794,6 +794,30 @@ network  : NETWORK prefix filter_set {
>  
>   TAILQ_INSERT_TAIL(netconf, n, entry);
>   }
> + | NETWORK family PRIORITY NUMBER filter_set {
> + struct network  *n;
> + if ($4 < RTP_LOCAL && $4 > RTP_MAX) {
> + yyerror("priority %lld > max %d or < min %d", 
> $4,
> + RTP_MAX, RTP_LOCAL);
> + YYERROR;
> + }
> +
> + if ((n = calloc(1, sizeof(struct network))) == NULL)
> + fatal("new_network");
> + if (afi2aid($2, SAFI_UNICAST, &n->net.prefix.aid) ==
> + -1) {
> + yyerror("unknown family");
> + filterset_free($5);
> + free($5);
> + YYERROR;
> + }
> + n->net.type = NETWORK_PRIORITY;
> + n->net.priority = $4;
> + filterset_move($5, &n->net.attrset);
> + free($5);
> +
> + TAILQ_INSERT_TAIL(netconf, n, entry);
> + }
>   | NETWORK family nettype filter_set {
>   struct network  *n;
>  
> @@ -2576,6 +2600,7 @@ lookup(char *s)
>   { "prefixlen",  PREFIXLEN},
>   { "prepend-neighbor",   PREPEND_PEER},
>   { "prepe

Remove i386 specific mention for pcvtfonts in hier.7

2018-07-11 Thread Frederic Cambus
Hi tech@,

Remove the i386 specific mention for pcvtfonts, they are also installed
on alpha and amd64.

>From share/misc/Makefile:

.if (${MACHINE} == "i386") || (${MACHINE} == "amd64") || \
(${MACHINE} == "alpha")
SUBDIR= pcvtfonts
.endif

Comments? OK?

Index: share/man/man7/hier.7
===
RCS file: /cvs/src/share/man/man7/hier.7,v
retrieving revision 1.159
diff -u -p -r1.159 hier.7
--- share/man/man7/hier.7   8 Nov 2017 11:24:24 -   1.159
+++ share/man/man7/hier.7   11 Jul 2018 08:24:33 -
@@ -407,7 +407,7 @@ Miscellaneous system-wide ASCII text fil
 Terminal characteristics database (see
 .Xr termcap 5 ) .
 .It pcvtfonts/
-Additional i386 console fonts.
+Additional console fonts.
 .El
 .Pp
 .It mk/



Re: rc(8): don't hide failures from route6d & rtadvd

2018-07-11 Thread Peter Hessler
net.inet6.ip6.forwarding=0
OK(failed)


On 2018 Jul 11 (Wed) at 09:58:18 +0200 (+0200), Florian Obser wrote:
:at least rtadvd has it's own check and failes to start if forwarding
:is not enabled, not sure what route6d is doing.
:
:rc(8) should not silently hide errors.
:
:OK?
:
:diff --git etc/rc etc/rc
:index 21f009306cb..938f4858301 100644
:--- etc/rc
:+++ etc/rc
:@@ -575,14 +575,7 @@ run_upgrade_script sysmerge
: 
: echo -n 'starting network daemons:'
: start_daemon ldomd sshd switchd snmpd ldpd ripd ospfd ospf6d bgpd ifstated
:-start_daemon relayd dhcpd dhcrelay mrouted dvmrpd radiusd eigrpd
:-
:-if ifconfig lo0 inet6 >/dev/null 2>&1; then
:-  if (($(sysctl -n net.inet6.ip6.forwarding) == 1)); then
:-  start_daemon route6d rtadvd
:-  fi
:-fi
:-
:+start_daemon relayd dhcpd dhcrelay mrouted dvmrpd radiusd eigrpd route6d 
rtadvd
: start_daemon hostapd lpd smtpd slowcgi httpd ftpd
: start_daemon ftpproxy ftpproxy6 tftpd tftpproxy identd inetd rarpd bootparamd
: start_daemon rbootd mopd vmd spamd spamlogd sndiod
:
:
:-- 
:I'm not entirely sure you are real.
:

-- 
An age is called Dark not because the light fails to shine, but because
people refuse to see it.
-- James Michener, "Space"



Re: Time to retire RTM_LOSING

2018-07-11 Thread Claudio Jeker
On Wed, Jul 11, 2018 at 10:10:50AM +0200, Martin Pieuchot wrote:
> On 11/07/18(Wed) 09:55, Claudio Jeker wrote:
> > On busy servers I seen multiple RTM_LOSING message per second being
> > generated. This is not helpful (especially since nothing is doing
> > something with it). This diff removes the part where RTM_LOSING is
> > generated
> 
> I'm fine with that.  However what about adding a tcp_trace() call
> instead?  This could still be useful for debugging.

tcp_timer_rexmt() which is the only caller of in_losing() is already doing 
a tcp_trace call at the end which is hit in that case.
tcp_trace(TA_TIMER, ostate, tp, otp, NULL, TCPT_REXMT, 0);
There is some other cases in tcp_timer_rexmt() which skip the tcp_trace()
especially the block that calls into icmp_mtudisc().
Will talk to bluhm@ about this once he shows up.
 
> >   but at the same time adds some RTM_ADD / RTM_DELETE messages for
> > the dynamic routes added by the PMTU handlers. In my opinion adding even
> > dynamic routes to the routing table should be communicated on the routing
> > socket (also the removes because of the timeout will already show up).
> > Only lightly tested since I'm not having access to the box I have seen
> > this anymore.
> 
> I like it.  I'd only call rtm_send(9) if rtrequest() didn't returned an
> error, like it is done in rt_ifa_add/del().

Right, it does not make sense to report that error up.
Adapted the diff to do that.
 
-- 
:wq Claudio

Index: netinet/in_pcb.c
===
RCS file: /cvs/src/sys/netinet/in_pcb.c,v
retrieving revision 1.239
diff -u -p -r1.239 in_pcb.c
--- netinet/in_pcb.c14 Jun 2018 17:16:03 -  1.239
+++ netinet/in_pcb.c10 Jul 2018 21:31:59 -
@@ -709,21 +709,11 @@ in_pcbnotifyall(struct inpcbtable *table
 void
 in_losing(struct inpcb *inp)
 {
-   struct rtentry *rt;
-   struct rt_addrinfo info;
-   struct sockaddr_in6 sa_mask;
+   struct rtentry *rt = inp->inp_route.ro_rt;
 
-   if ((rt = inp->inp_route.ro_rt)) {
-   inp->inp_route.ro_rt = 0;
+   if (rt) {
+   inp->inp_route.ro_rt = NULL;
 
-   memset(&info, 0, sizeof(info));
-   info.rti_flags = rt->rt_flags;
-   info.rti_info[RTAX_DST] = &inp->inp_route.ro_dst;
-   info.rti_info[RTAX_GATEWAY] = rt->rt_gateway;
-   info.rti_info[RTAX_NETMASK] = rt_plen2mask(rt, &sa_mask);
-
-   rtm_miss(RTM_LOSING, &info, rt->rt_flags, rt->rt_priority,
-   rt->rt_ifidx, 0, inp->inp_rtableid);
if (rt->rt_flags & RTF_DYNAMIC) {
struct ifnet *ifp;
 
@@ -734,10 +724,8 @@ in_losing(struct inpcb *inp)
 * so we're dealing with a stale cache and have
 * nothing to do.
 */
-   if (ifp != NULL) {
-   rtrequest_delete(&info, rt->rt_priority, ifp,
-   NULL, inp->inp_rtableid);
-   }
+   if (ifp != NULL)
+   rtdeletemsg(rt, ifp, inp->inp_rtableid);
if_put(ifp);
}
/*
Index: netinet/ip_icmp.c
===
RCS file: /cvs/src/sys/netinet/ip_icmp.c,v
retrieving revision 1.175
diff -u -p -r1.175 ip_icmp.c
--- netinet/ip_icmp.c   21 May 2018 15:52:22 -  1.175
+++ netinet/ip_icmp.c   11 Jul 2018 08:18:04 -
@@ -990,6 +990,7 @@ icmp_mtudisc_clone(struct in_addr dst, u
nrt->rt_rmx = rt->rt_rmx;
rtfree(rt);
rt = nrt;
+   rtm_send(rt, RTM_ADD, error, rtableid);
}
error = rt_timer_add(rt, icmp_mtudisc_timeout, ip_mtudisc_timeout_q,
rtableid);
Index: netinet6/icmp6.c
===
RCS file: /cvs/src/sys/netinet6/icmp6.c,v
retrieving revision 1.224
diff -u -p -r1.224 icmp6.c
--- netinet6/icmp6.c2 Jun 2018 16:38:21 -   1.224
+++ netinet6/icmp6.c11 Jul 2018 08:17:24 -
@@ -1806,6 +1806,7 @@ icmp6_mtudisc_clone(struct sockaddr *dst
nrt->rt_rmx = rt->rt_rmx;
rtfree(rt);
rt = nrt;
+   rtm_send(rt, RTM_ADD, error, rtableid);
}
error = rt_timer_add(rt, icmp6_mtudisc_timeout, icmp6_mtudisc_timeout_q,
rtableid);



Re: soii addresses for interfaces without layer 2 addresses

2018-07-11 Thread Florian Obser
On Wed, Jul 11, 2018 at 10:04:53AM +0200, Martin Pieuchot wrote:
> On 10/07/18(Tue) 18:01, Florian Obser wrote:
> > When an interface doesn't have a layer 2 address in6_get_soii_ifid()
> > failes and then later on a in in6_get_ifid() a layer 2 address is
> > "borrowed" from from another interface.
> > 
> > Do the "borrowing" in in6_get_soii_ifid(), too so that semantically
> > opaque interface identifiers work for these kind of interfaces, too.
> 
> Why do we need to borrow?  Can't we generate a random one?

Sure, this was just an afterthough to the "stable IPv6 link local
addresses for interfaces without layer 2 addresses" diff.

phessler and me are still debating / wondering if we should get rid of
soii for link local addresses entirly. Since we haven't completly made
up our mind (actually, I asked for more time) it goes the same way as
in6_get_ifid() for now.

I find the whole borrowing here and in in6_get_ifid() stupid and want
to get rid of it, I haven't made up my mind yet on how.

> 
> > diff --git in6_ifattach.c in6_ifattach.c
> > index f40b1905fe4..adc54b1a4da 100644
> > --- in6_ifattach.c
> > +++ in6_ifattach.c
> > @@ -216,8 +216,9 @@ in6_get_hw_ifid(struct ifnet *ifp, struct in6_addr *in6)
> >   * in6 - upper 64bits are preserved
> >   */
> >  int
> > -in6_get_soii_ifid(struct ifnet *ifp, struct in6_addr *in6)
> > +in6_get_soii_ifid(struct ifnet *ifp0, struct in6_addr *in6)
> >  {
> > +   struct ifnet *ifp;
> > SHA2_CTX ctx;
> > u_int8_t digest[SHA512_DIGEST_LENGTH];
> > struct in6_addr prefix;
> > @@ -225,10 +226,25 @@ in6_get_soii_ifid(struct ifnet *ifp, struct in6_addr 
> > *in6)
> > int dad_counter = 0; /* XXX not used */
> > char *addr;
> >  
> > -   if (ifp->if_xflags & IFXF_INET6_NOSOII)
> > +   if (ifp0->if_xflags & IFXF_INET6_NOSOII)
> > return -1;
> >  
> > -   sdl = ifp->if_sadl;
> > +   sdl = ifp0->if_sadl;
> > +
> > +   if (sdl == NULL || sdl->sdl_alen == 0) {
> > +   /*
> > +* try to get it from some other hardware interface like
> > +* in in6_get_ifid()
> > +*/
> > +   TAILQ_FOREACH(ifp, &ifnet, if_list) {
> > +   if (ifp == ifp0)
> > +   continue;
> > +   sdl = ifp->if_sadl;
> > +   if (sdl != NULL && sdl->sdl_alen != 0)
> > +   break;
> > +   }
> > +   }
> > +
> > if (sdl == NULL || sdl->sdl_alen == 0)
> > return -1;
> >  
> > 
> > 
> > -- 
> > I'm not entirely sure you are real.
> > 
> 

-- 
I'm not entirely sure you are real.



Re: Time to retire RTM_LOSING

2018-07-11 Thread Martin Pieuchot
On 11/07/18(Wed) 09:55, Claudio Jeker wrote:
> On busy servers I seen multiple RTM_LOSING message per second being
> generated. This is not helpful (especially since nothing is doing
> something with it). This diff removes the part where RTM_LOSING is
> generated

I'm fine with that.  However what about adding a tcp_trace() call
instead?  This could still be useful for debugging.

>   but at the same time adds some RTM_ADD / RTM_DELETE messages for
> the dynamic routes added by the PMTU handlers. In my opinion adding even
> dynamic routes to the routing table should be communicated on the routing
> socket (also the removes because of the timeout will already show up).
> Only lightly tested since I'm not having access to the box I have seen
> this anymore.

I like it.  I'd only call rtm_send(9) if rtrequest() didn't returned an
error, like it is done in rt_ifa_add/del().

> Index: netinet/in_pcb.c
> ===
> RCS file: /cvs/src/sys/netinet/in_pcb.c,v
> retrieving revision 1.239
> diff -u -p -r1.239 in_pcb.c
> --- netinet/in_pcb.c  14 Jun 2018 17:16:03 -  1.239
> +++ netinet/in_pcb.c  10 Jul 2018 21:19:09 -
> @@ -709,21 +709,11 @@ in_pcbnotifyall(struct inpcbtable *table
>  void
>  in_losing(struct inpcb *inp)
>  {
> - struct rtentry *rt;
> - struct rt_addrinfo info;
> - struct sockaddr_in6 sa_mask;
> + struct rtentry *rt = inp->inp_route.ro_rt;
>  
> - if ((rt = inp->inp_route.ro_rt)) {
> - inp->inp_route.ro_rt = 0;
> + if (rt) {
> + inp->inp_route.ro_rt = NULL;
>  
> - memset(&info, 0, sizeof(info));
> - info.rti_flags = rt->rt_flags;
> - info.rti_info[RTAX_DST] = &inp->inp_route.ro_dst;
> - info.rti_info[RTAX_GATEWAY] = rt->rt_gateway;
> - info.rti_info[RTAX_NETMASK] = rt_plen2mask(rt, &sa_mask);
> -
> - rtm_miss(RTM_LOSING, &info, rt->rt_flags, rt->rt_priority,
> - rt->rt_ifidx, 0, inp->inp_rtableid);
>   if (rt->rt_flags & RTF_DYNAMIC) {
>   struct ifnet *ifp;
>  
> @@ -734,10 +724,8 @@ in_losing(struct inpcb *inp)
>* so we're dealing with a stale cache and have
>* nothing to do.
>*/
> - if (ifp != NULL) {
> - rtrequest_delete(&info, rt->rt_priority, ifp,
> - NULL, inp->inp_rtableid);
> - }
> + if (ifp != NULL)
> + rtdeletemsg(rt, ifp, inp->inp_rtableid);
>   if_put(ifp);
>   }
>   /*
> Index: netinet/ip_icmp.c
> ===
> RCS file: /cvs/src/sys/netinet/ip_icmp.c,v
> retrieving revision 1.175
> diff -u -p -r1.175 ip_icmp.c
> --- netinet/ip_icmp.c 21 May 2018 15:52:22 -  1.175
> +++ netinet/ip_icmp.c 10 Jul 2018 21:09:13 -
> @@ -983,6 +983,7 @@ icmp_mtudisc_clone(struct in_addr dst, u
>  
>   error = rtrequest(RTM_ADD, &info, rt->rt_priority, &nrt,
>   rtableid);
> + rtm_send(nrt, RTM_ADD, error, rtableid);
>   if (error) {
>   rtfree(rt);
>   return (NULL);
> Index: netinet6/icmp6.c
> ===
> RCS file: /cvs/src/sys/netinet6/icmp6.c,v
> retrieving revision 1.224
> diff -u -p -r1.224 icmp6.c
> --- netinet6/icmp6.c  2 Jun 2018 16:38:21 -   1.224
> +++ netinet6/icmp6.c  10 Jul 2018 21:18:13 -
> @@ -1799,6 +1799,7 @@ icmp6_mtudisc_clone(struct sockaddr *dst
>  
>   error = rtrequest(RTM_ADD, &info, rt->rt_priority, &nrt,
>   rtableid);
> + rtm_send(nrt, RTM_ADD, error, rtableid);
>   if (error) {
>   rtfree(rt);
>   return (NULL);
> 



Re: soii addresses for interfaces without layer 2 addresses

2018-07-11 Thread Martin Pieuchot
On 10/07/18(Tue) 18:01, Florian Obser wrote:
> When an interface doesn't have a layer 2 address in6_get_soii_ifid()
> failes and then later on a in in6_get_ifid() a layer 2 address is
> "borrowed" from from another interface.
> 
> Do the "borrowing" in in6_get_soii_ifid(), too so that semantically
> opaque interface identifiers work for these kind of interfaces, too.

Why do we need to borrow?  Can't we generate a random one?

> diff --git in6_ifattach.c in6_ifattach.c
> index f40b1905fe4..adc54b1a4da 100644
> --- in6_ifattach.c
> +++ in6_ifattach.c
> @@ -216,8 +216,9 @@ in6_get_hw_ifid(struct ifnet *ifp, struct in6_addr *in6)
>   * in6 - upper 64bits are preserved
>   */
>  int
> -in6_get_soii_ifid(struct ifnet *ifp, struct in6_addr *in6)
> +in6_get_soii_ifid(struct ifnet *ifp0, struct in6_addr *in6)
>  {
> + struct ifnet *ifp;
>   SHA2_CTX ctx;
>   u_int8_t digest[SHA512_DIGEST_LENGTH];
>   struct in6_addr prefix;
> @@ -225,10 +226,25 @@ in6_get_soii_ifid(struct ifnet *ifp, struct in6_addr 
> *in6)
>   int dad_counter = 0; /* XXX not used */
>   char *addr;
>  
> - if (ifp->if_xflags & IFXF_INET6_NOSOII)
> + if (ifp0->if_xflags & IFXF_INET6_NOSOII)
>   return -1;
>  
> - sdl = ifp->if_sadl;
> + sdl = ifp0->if_sadl;
> +
> + if (sdl == NULL || sdl->sdl_alen == 0) {
> + /*
> +  * try to get it from some other hardware interface like
> +  * in in6_get_ifid()
> +  */
> + TAILQ_FOREACH(ifp, &ifnet, if_list) {
> + if (ifp == ifp0)
> + continue;
> + sdl = ifp->if_sadl;
> + if (sdl != NULL && sdl->sdl_alen != 0)
> + break;
> + }
> + }
> +
>   if (sdl == NULL || sdl->sdl_alen == 0)
>   return -1;
>  
> 
> 
> -- 
> I'm not entirely sure you are real.
> 



rc(8): don't hide failures from route6d & rtadvd

2018-07-11 Thread Florian Obser
at least rtadvd has it's own check and failes to start if forwarding
is not enabled, not sure what route6d is doing.

rc(8) should not silently hide errors.

OK?

diff --git etc/rc etc/rc
index 21f009306cb..938f4858301 100644
--- etc/rc
+++ etc/rc
@@ -575,14 +575,7 @@ run_upgrade_script sysmerge
 
 echo -n 'starting network daemons:'
 start_daemon ldomd sshd switchd snmpd ldpd ripd ospfd ospf6d bgpd ifstated
-start_daemon relayd dhcpd dhcrelay mrouted dvmrpd radiusd eigrpd
-
-if ifconfig lo0 inet6 >/dev/null 2>&1; then
-   if (($(sysctl -n net.inet6.ip6.forwarding) == 1)); then
-   start_daemon route6d rtadvd
-   fi
-fi
-
+start_daemon relayd dhcpd dhcrelay mrouted dvmrpd radiusd eigrpd route6d rtadvd
 start_daemon hostapd lpd smtpd slowcgi httpd ftpd
 start_daemon ftpproxy ftpproxy6 tftpd tftpproxy identd inetd rarpd bootparamd
 start_daemon rbootd mopd vmd spamd spamlogd sndiod


-- 
I'm not entirely sure you are real.



Time to retire RTM_LOSING

2018-07-11 Thread Claudio Jeker
On busy servers I seen multiple RTM_LOSING message per second being
generated. This is not helpful (especially since nothing is doing
something with it). This diff removes the part where RTM_LOSING is
generated but at the same time adds some RTM_ADD / RTM_DELETE messages for
the dynamic routes added by the PMTU handlers. In my opinion adding even
dynamic routes to the routing table should be communicated on the routing
socket (also the removes because of the timeout will already show up).
Only lightly tested since I'm not having access to the box I have seen
this anymore.

-- 
:wq Claudio

Index: netinet/in_pcb.c
===
RCS file: /cvs/src/sys/netinet/in_pcb.c,v
retrieving revision 1.239
diff -u -p -r1.239 in_pcb.c
--- netinet/in_pcb.c14 Jun 2018 17:16:03 -  1.239
+++ netinet/in_pcb.c10 Jul 2018 21:19:09 -
@@ -709,21 +709,11 @@ in_pcbnotifyall(struct inpcbtable *table
 void
 in_losing(struct inpcb *inp)
 {
-   struct rtentry *rt;
-   struct rt_addrinfo info;
-   struct sockaddr_in6 sa_mask;
+   struct rtentry *rt = inp->inp_route.ro_rt;
 
-   if ((rt = inp->inp_route.ro_rt)) {
-   inp->inp_route.ro_rt = 0;
+   if (rt) {
+   inp->inp_route.ro_rt = NULL;
 
-   memset(&info, 0, sizeof(info));
-   info.rti_flags = rt->rt_flags;
-   info.rti_info[RTAX_DST] = &inp->inp_route.ro_dst;
-   info.rti_info[RTAX_GATEWAY] = rt->rt_gateway;
-   info.rti_info[RTAX_NETMASK] = rt_plen2mask(rt, &sa_mask);
-
-   rtm_miss(RTM_LOSING, &info, rt->rt_flags, rt->rt_priority,
-   rt->rt_ifidx, 0, inp->inp_rtableid);
if (rt->rt_flags & RTF_DYNAMIC) {
struct ifnet *ifp;
 
@@ -734,10 +724,8 @@ in_losing(struct inpcb *inp)
 * so we're dealing with a stale cache and have
 * nothing to do.
 */
-   if (ifp != NULL) {
-   rtrequest_delete(&info, rt->rt_priority, ifp,
-   NULL, inp->inp_rtableid);
-   }
+   if (ifp != NULL)
+   rtdeletemsg(rt, ifp, inp->inp_rtableid);
if_put(ifp);
}
/*
Index: netinet/ip_icmp.c
===
RCS file: /cvs/src/sys/netinet/ip_icmp.c,v
retrieving revision 1.175
diff -u -p -r1.175 ip_icmp.c
--- netinet/ip_icmp.c   21 May 2018 15:52:22 -  1.175
+++ netinet/ip_icmp.c   10 Jul 2018 21:09:13 -
@@ -983,6 +983,7 @@ icmp_mtudisc_clone(struct in_addr dst, u
 
error = rtrequest(RTM_ADD, &info, rt->rt_priority, &nrt,
rtableid);
+   rtm_send(nrt, RTM_ADD, error, rtableid);
if (error) {
rtfree(rt);
return (NULL);
Index: netinet6/icmp6.c
===
RCS file: /cvs/src/sys/netinet6/icmp6.c,v
retrieving revision 1.224
diff -u -p -r1.224 icmp6.c
--- netinet6/icmp6.c2 Jun 2018 16:38:21 -   1.224
+++ netinet6/icmp6.c10 Jul 2018 21:18:13 -
@@ -1799,6 +1799,7 @@ icmp6_mtudisc_clone(struct sockaddr *dst
 
error = rtrequest(RTM_ADD, &info, rt->rt_priority, &nrt,
rtableid);
+   rtm_send(nrt, RTM_ADD, error, rtableid);
if (error) {
rtfree(rt);
return (NULL);



Re: fix a few clang warnings for gnu cvs

2018-07-11 Thread Stefan Sperling
On Tue, Jul 10, 2018 at 05:00:15PM +0200, Theo Buehler wrote:
> Had these Ms in my trees for a while.
> 
> Does not fix all warnings, but a few simple ones:
> 
> Use "%s" to print modifiable strings, add a couple of braces, ansify a
> few functions and remove a few extra parens.

Looks good to me! OK

> Index: diff/diff3.c
> ===
> RCS file: /var/cvs/src/gnu/usr.bin/cvs/diff/diff3.c,v
> retrieving revision 1.1.1.6
> diff -u -p -r1.1.1.6 diff3.c
> --- diff/diff3.c  28 Sep 2001 22:45:41 -  1.1.1.6
> +++ diff/diff3.c  29 Jun 2018 08:47:56 -
> @@ -1502,7 +1502,7 @@ output_diff3 (diff, mapping, rev_mapping
> line = 0;
> do
>   {
> -   printf_output (line_prefix);
> +   printf_output ("%s", line_prefix);
> cp = D_RELNUM (ptr, realfile, line);
> length = D_RELLEN (ptr, realfile, line);
> write_output (cp, length);
> @@ -1554,11 +1554,12 @@ undotlines (leading_dot, start, num)
>   int leading_dot, start, num;
>  {
>write_output (".\n", 2);
> -  if (leading_dot)
> +  if (leading_dot) {
>  if (num == 1)
>printf_output ("%ds/^\\.//\n", start);
>  else
>printf_output ("%d,%ds/^\\.//\n", start, start + num - 1);
> +  }
>  }
>  
>  /*
> @@ -1749,11 +1750,12 @@ output_diff3_merge (infile, diff, mappin
>   do
> {
>   c = getc (infile);
> - if (c == EOF)
> + if (c == EOF) {
> if (ferror (infile))
>   diff3_perror_with_exit ("input file");
> else if (feof (infile))
>   diff3_fatal ("input file shrank");
> + }
>   cc = c;
>   write_output (&cc, 1);
> }
> @@ -1803,7 +1805,7 @@ output_diff3_merge (infile, diff, mappin
>linesread += i;
>while (0 <= --i)
>   while ((c = getc (infile)) != '\n')
> -   if (c == EOF)
> +   if (c == EOF) {
>   if (ferror (infile))
> diff3_perror_with_exit ("input file");
>   else if (feof (infile))
> @@ -1812,6 +1814,7 @@ output_diff3_merge (infile, diff, mappin
> diff3_fatal ("input file shrank");
>   return conflicts_found;
> }
> +   }
>  }
>/* Copy rest of common file.  */
>while ((c = getc (infile)) != EOF || !(ferror (infile) | feof (infile)))
> Index: diff/side.c
> ===
> RCS file: /var/cvs/src/gnu/usr.bin/cvs/diff/side.c,v
> retrieving revision 1.1.1.2
> diff -u -p -r1.1.1.2 side.c
> --- diff/side.c   22 Aug 1998 20:52:06 -  1.1.1.2
> +++ diff/side.c   29 Jun 2018 08:49:17 -
> @@ -122,7 +122,7 @@ print_half_line (line, indent, out_bound
> break;
>  
>   case '\b':
> -   if (in_position != 0 && --in_position < out_bound)
> +   if (in_position != 0 && --in_position < out_bound) {
>   if (out_position <= in_position)
> /* Add spaces to make up for suppressed tab past out_bound.  */
> for (;  out_position < in_position;  out_position++)
> @@ -133,6 +133,7 @@ print_half_line (line, indent, out_bound
>   cc = c;
>   write_output (&cc, 1);
> }
> +   }
> break;
>  
>   case '\f':
> Index: lib/getline.c
> ===
> RCS file: /var/cvs/src/gnu/usr.bin/cvs/lib/getline.c,v
> retrieving revision 1.2
> diff -u -p -r1.2 getline.c
> --- lib/getline.c 4 Mar 2012 04:05:15 -   1.2
> +++ lib/getline.c 29 Jun 2018 12:46:26 -
> @@ -46,13 +46,8 @@ char *malloc (), *realloc ();
> error.  */
>  
>  int
> -getstr (lineptr, n, stream, terminator, offset, limit)
> - char **lineptr;
> - size_t *n;
> - FILE *stream;
> - char terminator;
> - int offset;
> - int limit;
> +getstr (char **lineptr, size_t *n, FILE *stream, char terminator, int offset,
> +   int limit)
>  {
>int nchars_avail;  /* Allocated but unused chars in *LINEPTR.  */
>char *read_pos;/* Where we're reading into *LINEPTR. */
> @@ -154,20 +149,13 @@ getstr (lineptr, n, stream, terminator, 
>  }
>  
>  int
> -get_line (lineptr, n, stream)
> - char **lineptr;
> - size_t *n;
> - FILE *stream;
> +get_line (char **lineptr, size_t *n, FILE *stream)
>  {
>return getstr (lineptr, n, stream, '\n', 0, GETLINE_NO_LIMIT);
>  }
>  
>  int
> -getline_safe (lineptr, n, stream, limit)
> - char **lineptr;
> - size_t *n;
> - FILE *stream;
> - int limit;
> +getline_safe (char **lineptr, size_t *n, FILE *stream, int limit)
>  {
>return getstr (lineptr, n, stream, '\n', 0, limit);
>  }
> Index: lib/regex.c
> ===
> RCS file: /var/cvs/src/gnu/usr.bin/cvs/lib/regex.c,v
> retrieving revision 1.1.1.7
> diff -u -p -r1.1.1.7 regex

Re: bgpd: announce prefixes with priority n

2018-07-11 Thread Claudio Jeker
On Wed, Jul 11, 2018 at 12:43:41AM +0200, Sebastian Benoit wrote:
> hi,
> 
> allows you to announce prefixes from the kernel routing table selected by
> priority.
> 
> lightly tested, as in, the config part works.
> 
>   network inet priority 32
> 
> ok?

This is fairly esotheric as a feature. It would be nicer if route labels
would be used in such cases instead (e.g. tag all ospf routes in ospfd).
Also if done here then other routing daemons may need the same too.
 
> (benno_bgpd_announce_network_by_priority.diff)
> 
> diff --git usr.sbin/bgpd/bgpd.conf.5 usr.sbin/bgpd/bgpd.conf.5
> index d49a239ca22..f44805155f0 100644
> --- usr.sbin/bgpd/bgpd.conf.5
> +++ usr.sbin/bgpd/bgpd.conf.5
> @@ -273,6 +273,11 @@ Log received and sent updates.
>  .Pq Ic inet Ns | Ns Ic inet6
>  .Ic rtlabel Ar label Op Ic set ...\&
>  .Xc
> +.It Xo
> +.Ic network
> +.Pq Ic inet Ns | Ns Ic inet6
> +.Ic priority Ar number Op Ic set ...\&
> +.Xc
>  .\" NOT IMPLEMENTED. DO WE WANT THIS?
>  .\" .It Xo
>  .\" .Ic network prefix-set
> @@ -291,6 +296,11 @@ If set to
>  routes with the specified
>  .Ar label
>  will be announced.
> +If set to
> +.Ic priority ,
> +routes with the specified
> +.Ar priority
> +will be announced.
>  .Bd -literal -offset indent
>  network 192.168.7.0/24
>  .Ed
> diff --git usr.sbin/bgpd/bgpd.h usr.sbin/bgpd/bgpd.h
> index 5d53b019d97..bb8c4df42e6 100644
> --- usr.sbin/bgpd/bgpd.h
> +++ usr.sbin/bgpd/bgpd.h
> @@ -344,7 +344,8 @@ enum network_type {
>   NETWORK_STATIC,
>   NETWORK_CONNECTED,
>   NETWORK_RTLABEL,
> - NETWORK_MRTCLONE
> + NETWORK_MRTCLONE,
> + NETWORK_PRIORITY
>  };
>  
>  struct network_config {
> @@ -355,6 +356,7 @@ struct network_config {
>   u_int16_trtlabel;
>   enum network_typetype;
>   u_int8_t prefixlen;
> + u_int8_t priority;
>   u_int8_t old;   /* used for reloading */
>  };
>  
> diff --git usr.sbin/bgpd/kroute.c usr.sbin/bgpd/kroute.c
> index be4811d132a..73d6c43c359 100644
> --- usr.sbin/bgpd/kroute.c
> +++ usr.sbin/bgpd/kroute.c
> @@ -1127,6 +1127,10 @@ kr_net_match(struct ktable *kt, struct kroute *kr)
>   case NETWORK_MRTCLONE:
>   /* can not happen */
>   break;
> + case NETWORK_PRIORITY:
> + if (kr->priority == xn->net.priority)
> + return (xn);
> + break;
>   }
>   }
>   return (NULL);
> @@ -1163,6 +1167,10 @@ kr_net_match6(struct ktable *kt, struct kroute6 *kr6)
>   case NETWORK_MRTCLONE:
>   /* can not happen */
>   break;
> + case NETWORK_PRIORITY:
> + if (kr6->priority == xn->net.priority)
> + return (xn);
> + break;
>   }
>   }
>   return (NULL);
> diff --git usr.sbin/bgpd/parse.y usr.sbin/bgpd/parse.y
> index 2257473f7ce..86f8069e9a3 100644
> --- usr.sbin/bgpd/parse.y
> +++ usr.sbin/bgpd/parse.y
> @@ -211,7 +211,7 @@ typedef struct {
>  %token   COMMUNITY EXTCOMMUNITY LARGECOMMUNITY
>  %token   PREFIX PREFIXLEN PREFIXSET SOURCEAS TRANSITAS PEERAS DELETE 
> MAXASLEN
>  %token   MAXASSEQ SET LOCALPREF MED METRIC NEXTHOP REJECT BLACKHOLE 
> NOMODIFY SELF
> -%token   PREPEND_SELF PREPEND_PEER PFTABLE WEIGHT RTLABEL ORIGIN
> +%token   PREPEND_SELF PREPEND_PEER PFTABLE WEIGHT RTLABEL ORIGIN PRIORITY
>  %token   ERROR INCLUDE
>  %token   IPSEC ESP AH SPI IKE
>  %token   IPV4 IPV6
> @@ -794,6 +794,30 @@ network  : NETWORK prefix filter_set {
>  
>   TAILQ_INSERT_TAIL(netconf, n, entry);
>   }
> + | NETWORK family PRIORITY NUMBER filter_set {
> + struct network  *n;
> + if ($4 < RTP_LOCAL && $4 > RTP_MAX) {
> + yyerror("priority %lld > max %d or < min %d", 
> $4,
> + RTP_MAX, RTP_LOCAL);
> + YYERROR;
> + }
> +
> + if ((n = calloc(1, sizeof(struct network))) == NULL)
> + fatal("new_network");
> + if (afi2aid($2, SAFI_UNICAST, &n->net.prefix.aid) ==
> + -1) {
> + yyerror("unknown family");
> + filterset_free($5);
> + free($5);
> + YYERROR;
> + }
> + n->net.type = NETWORK_PRIORITY;
> + n->net.priority = $4;
> + filterset_move($5, &n->net.attrset);
> + free($5);
> +
> + TAILQ_INSERT_TAIL(netconf, n, entry);
> + }
>   | NETWORK family nettype filter_set {
>   struct network