csh: memory leak in setDolp()

2018-09-19 Thread Michael Mikonos
Hello,

In setDolp() pointers cp and dp initially point to the same
copied string, but later dp can become NULL if Strstr() finds
no match. The copied string is not freed in this case.
NetBSD added this fix in their dol.c revision 1.23 (2006).
OK?

- Michael

 
Index: dol.c
===
RCS file: /cvs/src/bin/csh/dol.c,v
retrieving revision 1.24
diff -u -p -u -r1.24 dol.c
--- dol.c   18 Sep 2018 06:56:09 -  1.24
+++ dol.c   20 Sep 2018 04:14:37 -
@@ -766,8 +766,10 @@ setDolp(Char *cp)
addla(dp);
free(dp);
 }
-else
+else {
addla(cp);
+   free(cp);
+}
 
 dolp = STRNULL;
 if (seterr)



Re: memory leak in amdisplay_attach()

2018-09-19 Thread Ian Sutton
On Tue, Sep 18, 2018 at 2:16 AM, Jonathan Gray  wrote:
> On Tue, Sep 18, 2018 at 08:34:55AM +0200, Claudio Jeker wrote:
>> On Tue, Sep 18, 2018 at 03:49:15PM +1000, Jonathan Gray wrote:
>> > Index: amdisplay.c
>> > ===
>> > RCS file: /cvs/src/sys/arch/armv7/omap/amdisplay.c,v
>> > retrieving revision 1.7
>> > diff -u -p -r1.7 amdisplay.c
>> > --- amdisplay.c 25 Oct 2017 14:34:22 -  1.7
>> > +++ amdisplay.c 18 Sep 2018 05:12:41 -
>> > @@ -272,6 +272,7 @@ amdisplay_attach(struct device *parent,
>> >
>> > if (rasops_init(>sc_ro, 200, 200)) {
>> > printf("%s: no rasops\n", DEVNAME(sc));
>> > +   free(edid_buf, M_DEVBUF, EDID_LENGTH);
>> > amdisplay_detach(self, 0);
>> > return;
>> > }
>> >
>>
>> I think it is better to free the edid_buf further up in that function
>> since it is unused after calling edid_parse(edid_buf, >sc_edid) on
>> line 215. So currently there is still a leak at the end of the function.
>
> sounds good to me, ok
>
>>
>> --
>> :wq Claudio
>>
>> Index: arch/armv7/omap/amdisplay.c
>> ===
>> RCS file: /cvs/src/sys/arch/armv7/omap/amdisplay.c,v
>> retrieving revision 1.7
>> diff -u -p -r1.7 amdisplay.c
>> --- arch/armv7/omap/amdisplay.c   25 Oct 2017 14:34:22 -  1.7
>> +++ arch/armv7/omap/amdisplay.c   18 Sep 2018 06:32:43 -
>> @@ -219,6 +219,8 @@ amdisplay_attach(struct device *parent,
>>   return;
>>   }
>>
>> + free(edid_buf, M_DEVBUF, EDID_LENGTH);
>> +
>>  #ifdef LCD_DEBUG
>>   edid_print(>sc_edid);
>>  #endif
>> @@ -246,7 +248,6 @@ amdisplay_attach(struct device *parent,
>>   /* configure DMA framebuffer */
>>   if (amdisplay_setup_dma(sc)) {
>>   printf("%s: couldn't allocate DMA framebuffer\n", DEVNAME(sc));
>> - free(edid_buf, M_DEVBUF, EDID_LENGTH);
>>   amdisplay_detach(self, 0);
>>   return;
>>   }
>>
>

I've tested Claudio's diff on my suite of BBB's, this patch is fine.

ok ians@



Re: bgpd: more RB tree less simpleq

2018-09-19 Thread Sebastian Benoit
ok benno@

Claudio Jeker(cje...@diehard.n-r-g.com) on 2018.09.19 10:15:22 +0200:
> Switch the prefixset simpleq into an RB trie. This allows to spot
> duplicates in the parser and is a requirement for roa-sets where
> conflicts need to be specially handled.
> 
> OK?
> -- 
> :wq Claudio
> 
> Index: bgpd.c
> ===
> RCS file: /cvs/src/usr.sbin/bgpd/bgpd.c,v
> retrieving revision 1.198
> diff -u -p -r1.198 bgpd.c
> --- bgpd.c9 Sep 2018 11:00:51 -   1.198
> +++ bgpd.c19 Sep 2018 06:34:11 -
> @@ -437,7 +437,7 @@ reconfigure(char *conffile, struct bgpd_
>   struct rde_rib  *rr;
>   struct rdomain  *rd;
>   struct prefixset*ps;
> - struct prefixset_item   *psi;
> + struct prefixset_item   *psi, *npsi;
>  
>   if (reconfpending) {
>   log_info("previous reload still running");
> @@ -510,8 +510,8 @@ reconfigure(char *conffile, struct bgpd_
>   if (imsg_compose(ibuf_rde, IMSG_RECONF_PREFIXSET, 0, 0, -1,
>   ps->name, sizeof(ps->name)) == -1)
>   return (-1);
> - while ((psi = SIMPLEQ_FIRST(>psitems)) != NULL) {
> - SIMPLEQ_REMOVE_HEAD(>psitems, entry);
> + RB_FOREACH_SAFE(psi, prefixset_tree, >psitems, npsi) {
> + RB_REMOVE(prefixset_tree, >psitems, psi);
>   if (imsg_compose(ibuf_rde, IMSG_RECONF_PREFIXSETITEM, 0,
>   0, -1, psi, sizeof(*psi)) == -1)
>   return (-1);
> Index: bgpd.h
> ===
> RCS file: /cvs/src/usr.sbin/bgpd/bgpd.h,v
> retrieving revision 1.340
> diff -u -p -r1.340 bgpd.h
> --- bgpd.h14 Sep 2018 10:22:11 -  1.340
> +++ bgpd.h19 Sep 2018 06:32:47 -
> @@ -953,15 +953,15 @@ struct filter_set {
>  };
>  
>  struct prefixset_item {
> - struct filter_prefix p;
> - SIMPLEQ_ENTRY(prefixset_item)entry;
> + struct filter_prefixp;
> + RB_ENTRY(prefixset_item)entry;
>  };
> -SIMPLEQ_HEAD(prefixset_items_h, prefixset_item);
> +RB_HEAD(prefixset_tree, prefixset_item);
>  
>  struct prefixset {
>   int  sflags;
>   char name[SET_NAME_LEN];
> - struct prefixset_items_h psitems;
> + struct prefixset_treepsitems;
>   SIMPLEQ_ENTRY(prefixset) entry;
>  };
>  
> @@ -1085,6 +1085,8 @@ voidfilterlist_free(struct filter_head 
>  int  host(const char *, struct bgpd_addr *, u_int8_t *);
>  void copy_filterset(struct filter_set_head *, struct filter_set_head *);
>  void expand_networks(struct bgpd_config *);
> +int  prefixset_cmp(struct prefixset_item *, struct prefixset_item *);
> +RB_PROTOTYPE(prefixset_tree, prefixset_item, entry, prefixset_cmp);
>  
>  /* kroute.c */
>  int   kr_init(void);
> Index: config.c
> ===
> RCS file: /cvs/src/usr.sbin/bgpd/config.c,v
> retrieving revision 1.73
> diff -u -p -r1.73 config.c
> --- config.c  9 Sep 2018 11:00:51 -   1.73
> +++ config.c  19 Sep 2018 06:35:49 -
> @@ -120,16 +120,15 @@ void
>  free_prefixsets(struct prefixset_head *psh)
>  {
>   struct prefixset*ps;
> - struct prefixset_item   *psi;
> + struct prefixset_item   *psi, *npsi;
>  
>   if (psh == NULL)
>   return;
>  
>   while (!SIMPLEQ_EMPTY(psh)) {
>   ps = SIMPLEQ_FIRST(psh);
> - while (!SIMPLEQ_EMPTY(>psitems)) {
> - psi = SIMPLEQ_FIRST(>psitems);
> - SIMPLEQ_REMOVE_HEAD(>psitems, entry);
> + RB_FOREACH_SAFE(psi, prefixset_tree, >psitems, npsi) {
> + RB_REMOVE(prefixset_tree, >psitems, psi);
>   free(psi);
>   }
>   SIMPLEQ_REMOVE_HEAD(psh, entry);
> @@ -529,7 +528,7 @@ expand_networks(struct bgpd_config *c)
>   == NULL)
>   fatal("%s: prefixset %s not found", __func__,
>   n->net.psname);
> - SIMPLEQ_FOREACH(psi, >psitems, entry) {
> + RB_FOREACH(psi, prefixset_tree, >psitems) {
>   if ((m = calloc(1, sizeof(struct network)))
>   == NULL)
>   fatal(NULL);
> @@ -546,3 +545,48 @@ expand_networks(struct bgpd_config *c)
>   }
>   }
>  }
> +
> +int
> +prefixset_cmp(struct prefixset_item *a, struct prefixset_item *b)
> +{
> + int i;
> +
> + if (a->p.addr.aid < b->p.addr.aid)
> + return (-1);
> + if (a->p.addr.aid > b->p.addr.aid)
> + return (1);
> +
> + switch (a->p.addr.aid) {
> + case AID_INET:
> + if 

Re: bgpd: more RB tree less simpleq

2018-09-19 Thread Denis Fondras
On Wed, Sep 19, 2018 at 10:41:15PM +0200, Claudio Jeker wrote:
> On Wed, Sep 19, 2018 at 08:50:41PM +0200, Denis Fondras wrote:
> > On Wed, Sep 19, 2018 at 10:15:22AM +0200, Claudio Jeker wrote:
> > > Switch the prefixset simpleq into an RB trie. This allows to spot
> > > duplicates in the parser and is a requirement for roa-sets where
> > > conflicts need to be specially handled.
> > > 
> > > OK?
> > 
> > I don't know if the case is relevant but
> > 
> > prefix-set plop {
> > 192.0.2.0/24 prefixlen 25
> > 192.0.2.0/25
> > 192.0.2.128/25
> > }
> > 
> > do not yield duplicate.
> 
> They are no real duplicates.
>   192.0.2.0/24 prefixlen 25
> is different from
>   192.0.2.0/25
> these are different nodes in the tree even though the cover the same
> address range in the end.
> 
> Duplicates will only trigger on exactly duplicate lines (same prefix and
> prefixlen bits).
> 
> Hope this makes sense.

Then OK denis@

> -- 
> :wq Claudio
>  
> > > -- 
> > > :wq Claudio
> > > 
> > > Index: bgpd.c
> > > ===
> > > RCS file: /cvs/src/usr.sbin/bgpd/bgpd.c,v
> > > retrieving revision 1.198
> > > diff -u -p -r1.198 bgpd.c
> > > --- bgpd.c9 Sep 2018 11:00:51 -   1.198
> > > +++ bgpd.c19 Sep 2018 06:34:11 -
> > > @@ -437,7 +437,7 @@ reconfigure(char *conffile, struct bgpd_
> > >   struct rde_rib  *rr;
> > >   struct rdomain  *rd;
> > >   struct prefixset*ps;
> > > - struct prefixset_item   *psi;
> > > + struct prefixset_item   *psi, *npsi;
> > >  
> > >   if (reconfpending) {
> > >   log_info("previous reload still running");
> > > @@ -510,8 +510,8 @@ reconfigure(char *conffile, struct bgpd_
> > >   if (imsg_compose(ibuf_rde, IMSG_RECONF_PREFIXSET, 0, 0, -1,
> > >   ps->name, sizeof(ps->name)) == -1)
> > >   return (-1);
> > > - while ((psi = SIMPLEQ_FIRST(>psitems)) != NULL) {
> > > - SIMPLEQ_REMOVE_HEAD(>psitems, entry);
> > > + RB_FOREACH_SAFE(psi, prefixset_tree, >psitems, npsi) {
> > > + RB_REMOVE(prefixset_tree, >psitems, psi);
> > >   if (imsg_compose(ibuf_rde, IMSG_RECONF_PREFIXSETITEM, 0,
> > >   0, -1, psi, sizeof(*psi)) == -1)
> > >   return (-1);
> > > Index: bgpd.h
> > > ===
> > > RCS file: /cvs/src/usr.sbin/bgpd/bgpd.h,v
> > > retrieving revision 1.340
> > > diff -u -p -r1.340 bgpd.h
> > > --- bgpd.h14 Sep 2018 10:22:11 -  1.340
> > > +++ bgpd.h19 Sep 2018 06:32:47 -
> > > @@ -953,15 +953,15 @@ struct filter_set {
> > >  };
> > >  
> > >  struct prefixset_item {
> > > - struct filter_prefix p;
> > > - SIMPLEQ_ENTRY(prefixset_item)entry;
> > > + struct filter_prefixp;
> > > + RB_ENTRY(prefixset_item)entry;
> > >  };
> > > -SIMPLEQ_HEAD(prefixset_items_h, prefixset_item);
> > > +RB_HEAD(prefixset_tree, prefixset_item);
> > >  
> > >  struct prefixset {
> > >   int  sflags;
> > >   char name[SET_NAME_LEN];
> > > - struct prefixset_items_h psitems;
> > > + struct prefixset_treepsitems;
> > >   SIMPLEQ_ENTRY(prefixset) entry;
> > >  };
> > >  
> > > @@ -1085,6 +1085,8 @@ voidfilterlist_free(struct filter_head 
> > >  int  host(const char *, struct bgpd_addr *, u_int8_t *);
> > >  void copy_filterset(struct filter_set_head *, struct filter_set_head 
> > > *);
> > >  void expand_networks(struct bgpd_config *);
> > > +int  prefixset_cmp(struct prefixset_item *, struct prefixset_item *);
> > > +RB_PROTOTYPE(prefixset_tree, prefixset_item, entry, prefixset_cmp);
> > >  
> > >  /* kroute.c */
> > >  int   kr_init(void);
> > > Index: config.c
> > > ===
> > > RCS file: /cvs/src/usr.sbin/bgpd/config.c,v
> > > retrieving revision 1.73
> > > diff -u -p -r1.73 config.c
> > > --- config.c  9 Sep 2018 11:00:51 -   1.73
> > > +++ config.c  19 Sep 2018 06:35:49 -
> > > @@ -120,16 +120,15 @@ void
> > >  free_prefixsets(struct prefixset_head *psh)
> > >  {
> > >   struct prefixset*ps;
> > > - struct prefixset_item   *psi;
> > > + struct prefixset_item   *psi, *npsi;
> > >  
> > >   if (psh == NULL)
> > >   return;
> > >  
> > >   while (!SIMPLEQ_EMPTY(psh)) {
> > >   ps = SIMPLEQ_FIRST(psh);
> > > - while (!SIMPLEQ_EMPTY(>psitems)) {
> > > - psi = SIMPLEQ_FIRST(>psitems);
> > > - SIMPLEQ_REMOVE_HEAD(>psitems, entry);
> > > + RB_FOREACH_SAFE(psi, prefixset_tree, >psitems, npsi) {
> > > + RB_REMOVE(prefixset_tree, >psitems, psi);
> > >   free(psi);
> > >   }
> > >   SIMPLEQ_REMOVE_HEAD(psh, entry);
> > 

Re: bgpd: more RB tree less simpleq

2018-09-19 Thread Claudio Jeker
On Wed, Sep 19, 2018 at 08:50:41PM +0200, Denis Fondras wrote:
> On Wed, Sep 19, 2018 at 10:15:22AM +0200, Claudio Jeker wrote:
> > Switch the prefixset simpleq into an RB trie. This allows to spot
> > duplicates in the parser and is a requirement for roa-sets where
> > conflicts need to be specially handled.
> > 
> > OK?
> 
> I don't know if the case is relevant but
> 
> prefix-set plop {
>   192.0.2.0/24 prefixlen 25
>   192.0.2.0/25
>   192.0.2.128/25
>   }
> 
> do not yield duplicate.

They are no real duplicates.
192.0.2.0/24 prefixlen 25
is different from
192.0.2.0/25
these are different nodes in the tree even though the cover the same
address range in the end.

Duplicates will only trigger on exactly duplicate lines (same prefix and
prefixlen bits).

Hope this makes sense.
-- 
:wq Claudio
 
> > -- 
> > :wq Claudio
> > 
> > Index: bgpd.c
> > ===
> > RCS file: /cvs/src/usr.sbin/bgpd/bgpd.c,v
> > retrieving revision 1.198
> > diff -u -p -r1.198 bgpd.c
> > --- bgpd.c  9 Sep 2018 11:00:51 -   1.198
> > +++ bgpd.c  19 Sep 2018 06:34:11 -
> > @@ -437,7 +437,7 @@ reconfigure(char *conffile, struct bgpd_
> > struct rde_rib  *rr;
> > struct rdomain  *rd;
> > struct prefixset*ps;
> > -   struct prefixset_item   *psi;
> > +   struct prefixset_item   *psi, *npsi;
> >  
> > if (reconfpending) {
> > log_info("previous reload still running");
> > @@ -510,8 +510,8 @@ reconfigure(char *conffile, struct bgpd_
> > if (imsg_compose(ibuf_rde, IMSG_RECONF_PREFIXSET, 0, 0, -1,
> > ps->name, sizeof(ps->name)) == -1)
> > return (-1);
> > -   while ((psi = SIMPLEQ_FIRST(>psitems)) != NULL) {
> > -   SIMPLEQ_REMOVE_HEAD(>psitems, entry);
> > +   RB_FOREACH_SAFE(psi, prefixset_tree, >psitems, npsi) {
> > +   RB_REMOVE(prefixset_tree, >psitems, psi);
> > if (imsg_compose(ibuf_rde, IMSG_RECONF_PREFIXSETITEM, 0,
> > 0, -1, psi, sizeof(*psi)) == -1)
> > return (-1);
> > Index: bgpd.h
> > ===
> > RCS file: /cvs/src/usr.sbin/bgpd/bgpd.h,v
> > retrieving revision 1.340
> > diff -u -p -r1.340 bgpd.h
> > --- bgpd.h  14 Sep 2018 10:22:11 -  1.340
> > +++ bgpd.h  19 Sep 2018 06:32:47 -
> > @@ -953,15 +953,15 @@ struct filter_set {
> >  };
> >  
> >  struct prefixset_item {
> > -   struct filter_prefix p;
> > -   SIMPLEQ_ENTRY(prefixset_item)entry;
> > +   struct filter_prefixp;
> > +   RB_ENTRY(prefixset_item)entry;
> >  };
> > -SIMPLEQ_HEAD(prefixset_items_h, prefixset_item);
> > +RB_HEAD(prefixset_tree, prefixset_item);
> >  
> >  struct prefixset {
> > int  sflags;
> > char name[SET_NAME_LEN];
> > -   struct prefixset_items_h psitems;
> > +   struct prefixset_treepsitems;
> > SIMPLEQ_ENTRY(prefixset) entry;
> >  };
> >  
> > @@ -1085,6 +1085,8 @@ void  filterlist_free(struct filter_head 
> >  inthost(const char *, struct bgpd_addr *, u_int8_t *);
> >  void   copy_filterset(struct filter_set_head *, struct filter_set_head 
> > *);
> >  void   expand_networks(struct bgpd_config *);
> > +intprefixset_cmp(struct prefixset_item *, struct prefixset_item *);
> > +RB_PROTOTYPE(prefixset_tree, prefixset_item, entry, prefixset_cmp);
> >  
> >  /* kroute.c */
> >  int kr_init(void);
> > Index: config.c
> > ===
> > RCS file: /cvs/src/usr.sbin/bgpd/config.c,v
> > retrieving revision 1.73
> > diff -u -p -r1.73 config.c
> > --- config.c9 Sep 2018 11:00:51 -   1.73
> > +++ config.c19 Sep 2018 06:35:49 -
> > @@ -120,16 +120,15 @@ void
> >  free_prefixsets(struct prefixset_head *psh)
> >  {
> > struct prefixset*ps;
> > -   struct prefixset_item   *psi;
> > +   struct prefixset_item   *psi, *npsi;
> >  
> > if (psh == NULL)
> > return;
> >  
> > while (!SIMPLEQ_EMPTY(psh)) {
> > ps = SIMPLEQ_FIRST(psh);
> > -   while (!SIMPLEQ_EMPTY(>psitems)) {
> > -   psi = SIMPLEQ_FIRST(>psitems);
> > -   SIMPLEQ_REMOVE_HEAD(>psitems, entry);
> > +   RB_FOREACH_SAFE(psi, prefixset_tree, >psitems, npsi) {
> > +   RB_REMOVE(prefixset_tree, >psitems, psi);
> > free(psi);
> > }
> > SIMPLEQ_REMOVE_HEAD(psh, entry);
> > @@ -529,7 +528,7 @@ expand_networks(struct bgpd_config *c)
> > == NULL)
> > fatal("%s: prefixset %s not found", __func__,
> > n->net.psname);
> > -   

Re: inpcb table and socket lock

2018-09-19 Thread Alexander Bluhm
On Mon, Sep 17, 2018 at 04:00:28PM +0200, Alexander Bluhm wrote:
> + /* XXXSMP Is it safe to call notify with inpcbtable mutex? */
>   if (notify)
>   (*notify)(inp, errno);

visa@ pointed out that this may cause a deadlock as the notify
functions may grab the kernel lock.  If we always take the kernel
lock in in_pcbnotifyall() before the mutex, it fixes the deadlock.
As notifications are not in the hot path, it does not matter for
performance.

ok?

bluhm

Index: kern/kern_sysctl.c
===
RCS file: /data/mirror/openbsd/cvs/src/sys/kern/kern_sysctl.c,v
retrieving revision 1.346
diff -u -p -r1.346 kern_sysctl.c
--- kern/kern_sysctl.c  12 Jul 2018 01:23:38 -  1.346
+++ kern/kern_sysctl.c  19 Sep 2018 19:30:06 -
@@ -1179,7 +1179,8 @@ fill_file(struct kinfo_file *kf, struct 
kf->inp_rtableid = inpcb->inp_rtableid;
if (so->so_type == SOCK_RAW)
kf->inp_proto = inpcb->inp_ip.ip_p;
-   if (so->so_proto->pr_protocol == IPPROTO_TCP) {
+   if (so->so_proto->pr_protocol == IPPROTO_TCP &&
+   inpcb->inp_ppcb != NULL) {
struct tcpcb *tcpcb = (void *)inpcb->inp_ppcb;
kf->t_rcv_wnd = tcpcb->rcv_wnd;
kf->t_snd_wnd = tcpcb->snd_wnd;
@@ -1206,7 +1207,8 @@ fill_file(struct kinfo_file *kf, struct 
kf->inp_rtableid = inpcb->inp_rtableid;
if (so->so_type == SOCK_RAW)
kf->inp_proto = inpcb->inp_ipv6.ip6_nxt;
-   if (so->so_proto->pr_protocol == IPPROTO_TCP) {
+   if (so->so_proto->pr_protocol == IPPROTO_TCP &&
+   inpcb->inp_ppcb != NULL) {
struct tcpcb *tcpcb = (void *)inpcb->inp_ppcb;
kf->t_rcv_wnd = tcpcb->rcv_wnd;
kf->t_snd_wnd = tcpcb->snd_wnd;
@@ -1320,10 +1322,16 @@ sysctl_file(int *name, u_int namelen, ch
}   \
needed += elem_size;\
 } while (0)
+
 #define FILLIT(fp, fdp, i, vp, pr) \
FILLIT2(fp, fdp, i, vp, pr, NULL)
-#define FILLSO(so) \
-   FILLIT2(NULL, NULL, 0, NULL, NULL, so)
+
+#define FILLINPCB(inp) do {\
+   mtx_enter(>inp_mtx);   \
+   if (inp->inp_socket != NULL)\
+   FILLIT2(NULL, NULL, 0, NULL, NULL, inp->inp_socket);\
+   mtx_leave(>inp_mtx);   \
+} while (0)
 
switch (op) {
case KERN_FILE_BYFILE:
@@ -1331,19 +1339,26 @@ sysctl_file(int *name, u_int namelen, ch
if (arg == DTYPE_SOCKET) {
struct inpcb *inp;
 
-   NET_LOCK();
+   /*
+* The inpcb and socket fields are accessed and read
+* without net lock.  This may result in inconsistent
+* data provided to userland.  The fix will be to
+* protect the socket fields with the inpcb mutex.
+* XXXSMP
+*/
+   mtx_enter(_mtx);
TAILQ_FOREACH(inp, _queue, inp_queue)
-   FILLSO(inp->inp_socket);
+   FILLINPCB(inp);
TAILQ_FOREACH(inp, _queue, inp_queue)
-   FILLSO(inp->inp_socket);
+   FILLINPCB(inp);
TAILQ_FOREACH(inp, _queue, inp_queue)
-   FILLSO(inp->inp_socket);
+   FILLINPCB(inp);
 #ifdef INET6
TAILQ_FOREACH(inp, _queue,
inp_queue)
-   FILLSO(inp->inp_socket);
+   FILLINPCB(inp);
 #endif
-   NET_UNLOCK();
+   mtx_leave(_mtx);
}
fp = NULL;
while ((fp = fd_iterfile(fp, p)) != NULL) {
Index: netinet/in_pcb.c
===
RCS file: /data/mirror/openbsd/cvs/src/sys/netinet/in_pcb.c,v
retrieving revision 1.245
diff -u -p -r1.245 in_pcb.c
--- netinet/in_pcb.c14 Sep 2018 12:55:17 -  1.245
+++ netinet/in_pcb.c19 Sep 2018 19:30:06 -
@@ -111,12 +111,16 @@ int ipport_lastauto = IPPORT_USERRESERVE
 int ipport_hifirstauto = IPPORT_HIFIRSTAUTO;
 int ipport_hilastauto = IPPORT_HILASTAUTO;
 
+/* Protect PCB table queues, lookup 

Re: bgpd: more RB tree less simpleq

2018-09-19 Thread Denis Fondras
On Wed, Sep 19, 2018 at 10:15:22AM +0200, Claudio Jeker wrote:
> Switch the prefixset simpleq into an RB trie. This allows to spot
> duplicates in the parser and is a requirement for roa-sets where
> conflicts need to be specially handled.
> 
> OK?

I don't know if the case is relevant but

prefix-set plop {
192.0.2.0/24 prefixlen 25
192.0.2.0/25
192.0.2.128/25
}

do not yield duplicate.

> -- 
> :wq Claudio
> 
> Index: bgpd.c
> ===
> RCS file: /cvs/src/usr.sbin/bgpd/bgpd.c,v
> retrieving revision 1.198
> diff -u -p -r1.198 bgpd.c
> --- bgpd.c9 Sep 2018 11:00:51 -   1.198
> +++ bgpd.c19 Sep 2018 06:34:11 -
> @@ -437,7 +437,7 @@ reconfigure(char *conffile, struct bgpd_
>   struct rde_rib  *rr;
>   struct rdomain  *rd;
>   struct prefixset*ps;
> - struct prefixset_item   *psi;
> + struct prefixset_item   *psi, *npsi;
>  
>   if (reconfpending) {
>   log_info("previous reload still running");
> @@ -510,8 +510,8 @@ reconfigure(char *conffile, struct bgpd_
>   if (imsg_compose(ibuf_rde, IMSG_RECONF_PREFIXSET, 0, 0, -1,
>   ps->name, sizeof(ps->name)) == -1)
>   return (-1);
> - while ((psi = SIMPLEQ_FIRST(>psitems)) != NULL) {
> - SIMPLEQ_REMOVE_HEAD(>psitems, entry);
> + RB_FOREACH_SAFE(psi, prefixset_tree, >psitems, npsi) {
> + RB_REMOVE(prefixset_tree, >psitems, psi);
>   if (imsg_compose(ibuf_rde, IMSG_RECONF_PREFIXSETITEM, 0,
>   0, -1, psi, sizeof(*psi)) == -1)
>   return (-1);
> Index: bgpd.h
> ===
> RCS file: /cvs/src/usr.sbin/bgpd/bgpd.h,v
> retrieving revision 1.340
> diff -u -p -r1.340 bgpd.h
> --- bgpd.h14 Sep 2018 10:22:11 -  1.340
> +++ bgpd.h19 Sep 2018 06:32:47 -
> @@ -953,15 +953,15 @@ struct filter_set {
>  };
>  
>  struct prefixset_item {
> - struct filter_prefix p;
> - SIMPLEQ_ENTRY(prefixset_item)entry;
> + struct filter_prefixp;
> + RB_ENTRY(prefixset_item)entry;
>  };
> -SIMPLEQ_HEAD(prefixset_items_h, prefixset_item);
> +RB_HEAD(prefixset_tree, prefixset_item);
>  
>  struct prefixset {
>   int  sflags;
>   char name[SET_NAME_LEN];
> - struct prefixset_items_h psitems;
> + struct prefixset_treepsitems;
>   SIMPLEQ_ENTRY(prefixset) entry;
>  };
>  
> @@ -1085,6 +1085,8 @@ voidfilterlist_free(struct filter_head 
>  int  host(const char *, struct bgpd_addr *, u_int8_t *);
>  void copy_filterset(struct filter_set_head *, struct filter_set_head *);
>  void expand_networks(struct bgpd_config *);
> +int  prefixset_cmp(struct prefixset_item *, struct prefixset_item *);
> +RB_PROTOTYPE(prefixset_tree, prefixset_item, entry, prefixset_cmp);
>  
>  /* kroute.c */
>  int   kr_init(void);
> Index: config.c
> ===
> RCS file: /cvs/src/usr.sbin/bgpd/config.c,v
> retrieving revision 1.73
> diff -u -p -r1.73 config.c
> --- config.c  9 Sep 2018 11:00:51 -   1.73
> +++ config.c  19 Sep 2018 06:35:49 -
> @@ -120,16 +120,15 @@ void
>  free_prefixsets(struct prefixset_head *psh)
>  {
>   struct prefixset*ps;
> - struct prefixset_item   *psi;
> + struct prefixset_item   *psi, *npsi;
>  
>   if (psh == NULL)
>   return;
>  
>   while (!SIMPLEQ_EMPTY(psh)) {
>   ps = SIMPLEQ_FIRST(psh);
> - while (!SIMPLEQ_EMPTY(>psitems)) {
> - psi = SIMPLEQ_FIRST(>psitems);
> - SIMPLEQ_REMOVE_HEAD(>psitems, entry);
> + RB_FOREACH_SAFE(psi, prefixset_tree, >psitems, npsi) {
> + RB_REMOVE(prefixset_tree, >psitems, psi);
>   free(psi);
>   }
>   SIMPLEQ_REMOVE_HEAD(psh, entry);
> @@ -529,7 +528,7 @@ expand_networks(struct bgpd_config *c)
>   == NULL)
>   fatal("%s: prefixset %s not found", __func__,
>   n->net.psname);
> - SIMPLEQ_FOREACH(psi, >psitems, entry) {
> + RB_FOREACH(psi, prefixset_tree, >psitems) {
>   if ((m = calloc(1, sizeof(struct network)))
>   == NULL)
>   fatal(NULL);
> @@ -546,3 +545,48 @@ expand_networks(struct bgpd_config *c)
>   }
>   }
>  }
> +
> +int
> +prefixset_cmp(struct prefixset_item *a, struct prefixset_item *b)
> +{
> + int i;
> +
> + if (a->p.addr.aid < b->p.addr.aid)
> + return (-1);
> + if 

Re: simplify dev_mkdb

2018-09-19 Thread Theo de Raadt
Not sure it matters, but I should point out a difference.

Your diff makes

 dev_mkdb --

illegal.

In a POSIX world, many programs have to use getopt.  Not sure if this is one.



simplify dev_mkdb

2018-09-19 Thread Clemens Goessnitzer
simplify dev_mkdb:
-) no need for getopt() since there are no possible options, just check
   if argc < 1
-) usage() only used once: move it to the single point of failure for
   user input
-) bzero => memset, bcopy => memcpy
-) no brackets for return according to style(9)

no functional change except that 

# dev_mkdb -a
dev_mkdb: unknown option -- a
usage: dev_mkdb

becomes:

# ./dev_mkdb -a
usage: dev_mkdb

Clemens

Index: usr.sbin/dev_mkdb/dev_mkdb.c
===
RCS file: /cvs/src/usr.sbin/dev_mkdb/dev_mkdb.c,v
retrieving revision 1.16
diff -u -p -r1.16 dev_mkdb.c
--- usr.sbin/dev_mkdb/dev_mkdb.c9 Aug 2018 14:30:28 -   1.16
+++ usr.sbin/dev_mkdb/dev_mkdb.c19 Sep 2018 18:33:33 -
@@ -42,8 +42,6 @@
 #include 
 #include 
 
-void   usage(void);
-
 int
 main(int argc, char *argv[])
 {
@@ -64,17 +62,10 @@ main(int argc, char *argv[])
if (pledge("stdio rpath wpath cpath flock", NULL) == -1)
err(1, "pledge");
 
-   while ((ch = getopt(argc, argv, "")) != -1)
-   switch(ch) {
-   case '?':
-   default:
-   usage();
-   }
-   argc -= optind;
-   argv += optind;
-
-   if (argc > 0)
-   usage();
+   if (argc > 1) {
+   (void)fprintf(stderr, "usage: dev_mkdb\n");
+   exit(1);
+   }
 
if (chdir(_PATH_DEV))
err(1, "%s", _PATH_DEV);
@@ -83,7 +74,7 @@ main(int argc, char *argv[])
 
(void)snprintf(dbtmp, sizeof(dbtmp), "%sdev.tmp", _PATH_VARRUN);
(void)snprintf(dbname, sizeof(dbname), "%sdev.db", _PATH_VARRUN);
-   bzero(, sizeof(info));
+   memset(, 0, sizeof(info));
info.bsize = 8192;
db = dbopen(dbtmp, O_CREAT|O_EXLOCK|O_RDWR|O_TRUNC,
S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH, DB_HASH, );
@@ -96,7 +87,7 @@ main(int argc, char *argv[])
 * that the structure may contain padding, so we have to clear it
 * out here.
 */
-   bzero(, sizeof(bkey));
+   memset(, 0, sizeof(bkey));
key.data = 
key.size = sizeof(bkey);
data.data = buf;
@@ -119,7 +110,7 @@ main(int argc, char *argv[])
 * Create the data; nul terminate the name so caller doesn't
 * have to.
 */
-   bcopy(dp->d_name, buf, dp->d_namlen);
+   memcpy(buf, dp->d_name, dp->d_namlen);
buf[dp->d_namlen] = '\0';
data.size = dp->d_namlen + 1;
if ((db->put)(db, , , 0))
@@ -129,13 +120,5 @@ main(int argc, char *argv[])
if (rename(dbtmp, dbname))
err(1, "rename %s to %s", dbtmp, dbname);
 
-   return (0);
-}
-
-void
-usage(void)
-{
-
-   (void)fprintf(stderr, "usage: dev_mkdb\n");
-   exit(1);
+   return 0;
 }



Re: csh: avoid using uninitialized stat buffer

2018-09-19 Thread Michael Mikonos
On Wed, Sep 19, 2018 at 09:19:22AM -0600, Todd C. Miller wrote:
> When getcwd() fails, the stat buffer 'swd' is used uninitialized
> by the else clause.  Since it is used in both clauses we should
> perform the stat before the if().
> 
> However, fixing this causes 'cp' to be unitialized in some case so
> initialize cp to NULL and move the "cp == NULL" check out of the
> first if() clause now that it can be true in either case.
> 
> Found by clang analyzer.
> 
>  - todd

I had to stare at this one for a while, but overall I like the patch.
OK miko@.

> 
> Index: bin/csh/dir.c
> ===
> RCS file: /cvs/src/bin/csh/dir.c,v
> retrieving revision 1.21
> diff -u -p -u -r1.21 dir.c
> --- bin/csh/dir.c 26 Dec 2015 13:48:38 -  1.21
> +++ bin/csh/dir.c 19 Sep 2018 15:14:43 -
> @@ -64,7 +64,7 @@ void
>  dinit(Char *hp)
>  {
>  char *tcp;
> -Char *cp;
> +Char *cp = NULL;
>  struct directory *dp;
>  charpath[PATH_MAX];
>  static const char emsg[] = "csh: Trying to start from \"%s\"\n";
> @@ -75,45 +75,45 @@ dinit(Char *hp)
>   (void) fprintf(csherr, "csh: %s\n", strerror(errno));
>   if (hp && *hp) {
>   tcp = short2str(hp);
> - if (chdir(tcp) == -1)
> - cp = NULL;
> - else
> + if (chdir(tcp) == 0)
>   cp = hp;
>   (void) fprintf(csherr, emsg, vis_str(hp));
>   }
> - else
> - cp = NULL;
> - if (cp == NULL) {
> - (void) fprintf(csherr, emsg, "/");
> - if (chdir("/") == -1)
> - /* I am not even try to print an error message! */
> - xexit(1);
> - cp = SAVE("/");
> - }
>  }
>  else {
>   struct stat swd, shp;
>  
> - /*
> -  * See if $HOME is the working directory we got and use that
> -  */
> - if (hp && *hp &&
> - stat(tcp, ) != -1 && stat(short2str(hp), ) != -1 &&
> - swd.st_dev == shp.st_dev && swd.st_ino == shp.st_ino)
> - cp = hp;
> - else {
> - char   *cwd;
> -
> + if (stat(tcp, ) == -1) {
> + (void) fprintf(csherr, "csh: %s: %s\n", tcp, strerror(errno));
> + } else {
>   /*
> -  * use PWD if we have it (for subshells)
> +  * See if $HOME is the working directory we got and use that
>*/
> - if ((cwd = getenv("PWD")) != NULL) {
> - if (stat(cwd, ) != -1 && swd.st_dev == shp.st_dev &&
> - swd.st_ino == shp.st_ino)
> - tcp = cwd;
> + if (hp && *hp && stat(short2str(hp), ) != -1 &&
> + swd.st_dev == shp.st_dev && swd.st_ino == shp.st_ino)
> + cp = hp;
> + else {
> + char   *cwd;
> +
> + /*
> +  * use PWD if we have it (for subshells)
> +  */
> + if ((cwd = getenv("PWD")) != NULL) {
> + if (stat(cwd, ) != -1 && swd.st_dev == shp.st_dev &&
> + swd.st_ino == shp.st_ino)
> + tcp = cwd;
> + }
> + cp = dcanon(SAVE(tcp), STRNULL);
>   }
> - cp = dcanon(SAVE(tcp), STRNULL);
>   }
> +}
> +
> +if (cp == NULL) {
> + (void) fprintf(csherr, emsg, "/");
> + if (chdir("/") == -1)
> + /* I am not even try to print an error message! */
> + xexit(1);
> + cp = SAVE("/");
>  }
>  
>  dp = xcalloc(1, sizeof(struct directory));
> 



csh: avoid using uninitialized stat buffer

2018-09-19 Thread Todd C. Miller
When getcwd() fails, the stat buffer 'swd' is used uninitialized
by the else clause.  Since it is used in both clauses we should
perform the stat before the if().

However, fixing this causes 'cp' to be unitialized in some case so
initialize cp to NULL and move the "cp == NULL" check out of the
first if() clause now that it can be true in either case.

Found by clang analyzer.

 - todd

Index: bin/csh/dir.c
===
RCS file: /cvs/src/bin/csh/dir.c,v
retrieving revision 1.21
diff -u -p -u -r1.21 dir.c
--- bin/csh/dir.c   26 Dec 2015 13:48:38 -  1.21
+++ bin/csh/dir.c   19 Sep 2018 15:14:43 -
@@ -64,7 +64,7 @@ void
 dinit(Char *hp)
 {
 char *tcp;
-Char *cp;
+Char *cp = NULL;
 struct directory *dp;
 charpath[PATH_MAX];
 static const char emsg[] = "csh: Trying to start from \"%s\"\n";
@@ -75,45 +75,45 @@ dinit(Char *hp)
(void) fprintf(csherr, "csh: %s\n", strerror(errno));
if (hp && *hp) {
tcp = short2str(hp);
-   if (chdir(tcp) == -1)
-   cp = NULL;
-   else
+   if (chdir(tcp) == 0)
cp = hp;
(void) fprintf(csherr, emsg, vis_str(hp));
}
-   else
-   cp = NULL;
-   if (cp == NULL) {
-   (void) fprintf(csherr, emsg, "/");
-   if (chdir("/") == -1)
-   /* I am not even try to print an error message! */
-   xexit(1);
-   cp = SAVE("/");
-   }
 }
 else {
struct stat swd, shp;
 
-   /*
-* See if $HOME is the working directory we got and use that
-*/
-   if (hp && *hp &&
-   stat(tcp, ) != -1 && stat(short2str(hp), ) != -1 &&
-   swd.st_dev == shp.st_dev && swd.st_ino == shp.st_ino)
-   cp = hp;
-   else {
-   char   *cwd;
-
+   if (stat(tcp, ) == -1) {
+   (void) fprintf(csherr, "csh: %s: %s\n", tcp, strerror(errno));
+   } else {
/*
-* use PWD if we have it (for subshells)
+* See if $HOME is the working directory we got and use that
 */
-   if ((cwd = getenv("PWD")) != NULL) {
-   if (stat(cwd, ) != -1 && swd.st_dev == shp.st_dev &&
-   swd.st_ino == shp.st_ino)
-   tcp = cwd;
+   if (hp && *hp && stat(short2str(hp), ) != -1 &&
+   swd.st_dev == shp.st_dev && swd.st_ino == shp.st_ino)
+   cp = hp;
+   else {
+   char   *cwd;
+
+   /*
+* use PWD if we have it (for subshells)
+*/
+   if ((cwd = getenv("PWD")) != NULL) {
+   if (stat(cwd, ) != -1 && swd.st_dev == shp.st_dev &&
+   swd.st_ino == shp.st_ino)
+   tcp = cwd;
+   }
+   cp = dcanon(SAVE(tcp), STRNULL);
}
-   cp = dcanon(SAVE(tcp), STRNULL);
}
+}
+
+if (cp == NULL) {
+   (void) fprintf(csherr, emsg, "/");
+   if (chdir("/") == -1)
+   /* I am not even try to print an error message! */
+   xexit(1);
+   cp = SAVE("/");
 }
 
 dp = xcalloc(1, sizeof(struct directory));



bgpd: stop crashing SE after RDE crash

2018-09-19 Thread Claudio Jeker
If the RDE process dies it takes the session engine along. The problem
is that the ibuf structures to the RDE become invalid but the SE still
tries to send the RDE messages which ends up in tears and SIGSEGV.
Wrap the imsg_compose() to ibuf_rde in a new helper function which does
a NULL check before. Additionally add an extra check in session_stop()
which is called in the exit handler of the SE and is triggering this
in most cases.

OK?
-- 
:wq Claudio

Index: session.c
===
RCS file: /cvs/src/usr.sbin/bgpd/session.c,v
retrieving revision 1.366
diff -u -p -r1.366 session.c
--- session.c   4 Sep 2018 12:00:29 -   1.366
+++ session.c   19 Sep 2018 12:28:38 -
@@ -94,6 +94,7 @@ int   capa_neg_calc(struct peer *);
 void   session_dispatch_imsg(struct imsgbuf *, int, u_int *);
 void   session_up(struct peer *);
 void   session_down(struct peer *);
+intimsg_rde(int, u_int32_t, void *, u_int16_t);
 void   session_demote(struct peer *, int);
 intsession_link_state_is_up(int, int, int);
 
@@ -1379,8 +1380,7 @@ session_sendmsg(struct bgp_msg *msg, str
 
ibuf_close(>wbuf, msg->buf);
if (!p->throttled && p->wbuf.queued > SESS_MSG_HIGH_MARK) {
-   if (imsg_compose(ibuf_rde, IMSG_XOFF, p->conf.id, 0, -1,
-   NULL, 0) == -1)
+   if (imsg_rde(IMSG_XOFF, p->conf.id, NULL, 0) == -1)
log_peer_warn(>conf, "imsg_compose XOFF");
p->throttled = 1;
}
@@ -1671,16 +1671,16 @@ session_graceful_restart(struct peer *p)
 
for (i = 0; i < AID_MAX; i++) {
if (p->capa.neg.grestart.flags[i] & CAPA_GR_PRESENT) {
-   if (imsg_compose(ibuf_rde, IMSG_SESSION_STALE,
-   p->conf.id, 0, -1, , sizeof(i)) == -1)
+   if (imsg_rde(IMSG_SESSION_STALE, p->conf.id,
+   , sizeof(i)) == -1)
return (-1);
log_peer_warnx(>conf,
"graceful restart of %s, keeping routes",
aid2str(i));
p->capa.neg.grestart.flags[i] |= CAPA_GR_RESTARTING;
} else if (p->capa.neg.mp[i]) {
-   if (imsg_compose(ibuf_rde, IMSG_SESSION_FLUSH,
-   p->conf.id, 0, -1, , sizeof(i)) == -1)
+   if (imsg_rde(IMSG_SESSION_FLUSH, p->conf.id,
+   , sizeof(i)) == -1)
return (-1);
log_peer_warnx(>conf,
"graceful restart of %s, flushing routes",
@@ -1704,8 +1704,8 @@ session_graceful_stop(struct peer *p)
if (p->capa.neg.grestart.flags[i] & CAPA_GR_RESTARTING) {
log_peer_warnx(>conf, "graceful restart of %s, "
"time-out, flushing", aid2str(i));
-   if (imsg_compose(ibuf_rde, IMSG_SESSION_FLUSH,
-   p->conf.id, 0, -1, , sizeof(i)) == -1)
+   if (imsg_rde(IMSG_SESSION_FLUSH, p->conf.id,
+   , sizeof(i)) == -1)
return (-1);
}
p->capa.neg.grestart.flags[i] &= ~CAPA_GR_RESTARTING;
@@ -1771,8 +1771,7 @@ session_dispatch_msg(struct pollfd *pfd,
return (1);
}
if (p->throttled && p->wbuf.queued < SESS_MSG_LOW_MARK) {
-   if (imsg_compose(ibuf_rde, IMSG_XON, p->conf.id, 0, -1,
-   NULL, 0) == -1)
+   if (imsg_rde(IMSG_XON, p->conf.id, NULL, 0) == -1)
log_peer_warn(>conf, "imsg_compose XON");
p->throttled = 0;
}
@@ -2183,8 +2182,7 @@ parse_update(struct peer *peer)
p += MSGSIZE_HEADER;/* header is already checked */
datalen -= MSGSIZE_HEADER;
 
-   if (imsg_compose(ibuf_rde, IMSG_UPDATE, peer->conf.id, 0, -1, p,
-   datalen) == -1)
+   if (imsg_rde(IMSG_UPDATE, peer->conf.id, p, datalen) == -1)
return (-1);
 
return (0);
@@ -2221,8 +2219,7 @@ parse_refresh(struct peer *peer)
return (0);
}
 
-   if (imsg_compose(ibuf_rde, IMSG_REFRESH, peer->conf.id, 0, -1, ,
-   sizeof(aid)) == -1)
+   if (imsg_rde(IMSG_REFRESH, peer->conf.id, , sizeof(aid)) == -1)
return (-1);
 
return (0);
@@ -2551,8 +2548,8 @@ capa_neg_calc(struct peer *p)
if (negflags & CAPA_GR_RESTARTING) {
if (!(p->capa.peer.grestart.flags[i] &
CAPA_GR_FORWARD)) {
-   if (imsg_compose(ibuf_rde, IMSG_SESSION_FLUSH,
-   p->conf.id, 0, -1, , sizeof(i)) == -1)
+   if 

Re: Speed up UEFI framebuffer console

2018-09-19 Thread Mark Kettenis
> Date: Sat, 25 Aug 2018 17:38:12 +0200 (CEST)
> From: Mark Kettenis 
> 
> Here is a diff to speed up the initial framebuffer console on amd64.
> It remaps the framebuffer write-combining early on, which speeds up
> writing to the framebuffer considerably.
> 
> Remapping is done using _bus_space_map().  Otherwise inteldrm(4) and
> radeondrm(4) will fail to attach (or even panic) because the graphics
> aperture can't be mapped.  This mapping stays around even if efifb(4)
> doesn't attach.  There is no good place to unmap it without risking
> some random kernel printf causing a fault.
> 
> The rasops(4) bit is a bugfix that probably should go in regardless.
> It makes sure we don't clear the character mapping if the RI_CLEAR
> flag isn't set.
> 
> Can somebody with a UEFI machine that has radeondrm(4) test this for
> me?

I've had some test reports, and it has been in snaps for quite a while.

ok?


> Index: arch/amd64/amd64/efifb.c
> ===
> RCS file: /cvs/src/sys/arch/amd64/amd64/efifb.c,v
> retrieving revision 1.17
> diff -u -p -r1.17 efifb.c
> --- arch/amd64/amd64/efifb.c  12 Jul 2018 12:47:57 -  1.17
> +++ arch/amd64/amd64/efifb.c  25 Aug 2018 15:27:43 -
> @@ -215,11 +215,6 @@ efifb_attach(struct device *parent, stru
>   ccol = ri->ri_ccol;
>   crow = ri->ri_crow;
>  
> - if (bus_space_map(iot, fb->paddr, fb->psize,
> - BUS_SPACE_MAP_PREFETCHABLE | BUS_SPACE_MAP_LINEAR,
> - ) == 0)
> - ri->ri_origbits = bus_space_vaddr(iot, ioh);
> -
>   efifb_rasops_preinit(fb);
>   ri->ri_flg &= ~RI_CLEAR;
>   ri->ri_flg |= RI_VCONS | RI_WRONLY;
> @@ -428,6 +423,7 @@ efifb_efiinfo_init(struct efifb *fb)
>   fb->psize = bios_efiinfo->fb_height *
>   bios_efiinfo->fb_pixpsl * (fb->depth / 8);
>  }
> +
>  void
>  efifb_cnattach_common(void)
>  {
> @@ -450,6 +446,28 @@ efifb_cnattach_common(void)
>  
>   ri->ri_ops.alloc_attr(ri, 0, 0, 0, );
>   wsdisplay_cnattach(_std_descr, ri, 0, 0, defattr);
> +}
> +
> +void
> +efifb_cnremap(void)
> +{
> + struct efifb*fb = _console;
> + struct rasops_info  *ri = >rinfo;
> + bus_space_tag_t  iot = X86_BUS_SPACE_MEM;
> + bus_space_handle_t   ioh;
> +
> + if (fb->paddr == 0)
> + return;
> +
> + if (_bus_space_map(iot, fb->paddr, fb->psize,
> + BUS_SPACE_MAP_PREFETCHABLE | BUS_SPACE_MAP_LINEAR, ) == 0)
> + ri->ri_origbits = bus_space_vaddr(iot, ioh);
> +
> + efifb_rasops_preinit(fb);
> + ri->ri_flg &= ~RI_CLEAR;
> + ri->ri_flg |= RI_CENTER | RI_WRONLY;
> +
> + rasops_init(ri, efifb_std_descr.nrows, efifb_std_descr.ncols);
>  }
>  
>  int
> Index: arch/amd64/amd64/mainbus.c
> ===
> RCS file: /cvs/src/sys/arch/amd64/amd64/mainbus.c,v
> retrieving revision 1.44
> diff -u -p -r1.44 mainbus.c
> --- arch/amd64/amd64/mainbus.c13 Jul 2018 08:30:34 -  1.44
> +++ arch/amd64/amd64/mainbus.c25 Aug 2018 15:27:43 -
> @@ -171,6 +171,10 @@ mainbus_attach(struct device *parent, st
>   pvbus_identify();
>  #endif
>  
> +#if NEFIFB > 0
> + efifb_cnremap();
> +#endif
> +
>  #if NBIOS > 0
>   {
>   mba.mba_bios.ba_name = "bios";
> Index: arch/amd64/include/efifbvar.h
> ===
> RCS file: /cvs/src/sys/arch/amd64/include/efifbvar.h,v
> retrieving revision 1.7
> diff -u -p -r1.7 efifbvar.h
> --- arch/amd64/include/efifbvar.h 25 Apr 2018 00:46:28 -  1.7
> +++ arch/amd64/include/efifbvar.h 25 Aug 2018 15:27:43 -
> @@ -26,6 +26,7 @@ struct efifb_attach_args {
>  struct pci_attach_args;
>  
>  int efifb_cnattach(void);
> +void efifb_cnremap(void);
>  int efifb_is_console(struct pci_attach_args *);
>  void efifb_cndetach(void);
>  void efifb_cnreattach(void);
> Index: dev/rasops/rasops.c
> ===
> RCS file: /cvs/src/sys/dev/rasops/rasops.c,v
> retrieving revision 1.54
> diff -u -p -r1.54 rasops.c
> --- dev/rasops/rasops.c   3 May 2018 10:05:47 -   1.54
> +++ dev/rasops/rasops.c   25 Aug 2018 15:27:43 -
> @@ -288,10 +288,12 @@ rasops_init(struct rasops_info *ri, int 
>   ri->ri_ops.copyrows = rasops_wronly_copyrows;
>   ri->ri_ops.eraserows = rasops_wronly_eraserows;
>  
> - ri->ri_alloc_attr(ri, 0, 0, 0, );
> - for (i = 0; i < ri->ri_rows * ri->ri_cols; i++) {
> - ri->ri_bs[i].uc = ' ';
> - ri->ri_bs[i].attr = attr;
> + if (ri->ri_flg & RI_CLEAR) {
> + ri->ri_alloc_attr(ri, 0, 0, 0, );
> + for (i = 0; i < ri->ri_rows * ri->ri_cols; i++) {
> + 

Re: add explanations of vmctl send command in vmctl.8

2018-09-19 Thread Mike Larkin
On Wed, Sep 19, 2018 at 12:22:21PM +0200, Solene Rapenne wrote:
> Solene Rapenne  wrote:
> > This diff explains a little more about the send commands.
> > send pauses the VM and send its memory + the start parameters.
> > 
> 
> new diff with some changes, also thx bentley@ for telling me sentences should
> start on a newline in mdoc.
> 
> 
> Index: vmctl.8
> ===
> RCS file: /cvs/src/usr.sbin/vmctl/vmctl.8,v
> retrieving revision 1.47
> diff -u -p -r1.47 vmctl.8
> --- vmctl.8 11 Sep 2018 04:03:16 -  1.47
> +++ vmctl.8 19 Sep 2018 10:20:06 -
> @@ -90,6 +90,13 @@ Reset and terminate all VMs.
>  Send a VM with the specified
>  .Ar id
>  to standard output and terminate it.
> +The VM is paused while send is processing.
> +Data sent to standard output contains the VM parameters and its memory,
> +not the disk image.
> +.Pp
> +In order to move a VM from one host to another, disk files must be
> +synced between the send and the receive processes and must be located
> +under the same path.
>  .It Cm show Op Ar id
>  An alias for the
>  .Cm status
> 
> 

ok mlarkin on these, and thanks.



Maybe need to enrich `-T' option in netcat manual

2018-09-19 Thread Nan Xiao
Hi tech@,

For `-T' option explanation in netcat manual:

-T keyword
Change the IPv4 TOS value or the TLS options.

But in fact, the netcat code not only processes IPv4 but also IPv6:

if (Tflag != -1) {
if (af == AF_INET && setsockopt(s, IPPROTO_IP,
IP_TOS, , sizeof(Tflag)) == -1)
err(1, "set IP ToS");

else if (af == AF_INET6 && setsockopt(s, IPPROTO_IPV6,
IPV6_TCLASS, , sizeof(Tflag)) == -1)
err(1, "set IPv6 traffic class");
}

So I think maybe the netcat manual should be enriched at least for `-T'
option, thanks!

-- 
Best Regards
Nan Xiao



Re: add explanations of vmctl send command in vmctl.8

2018-09-19 Thread Solene Rapenne
Solene Rapenne  wrote:
> This diff explains a little more about the send commands.
> send pauses the VM and send its memory + the start parameters.
> 

new diff with some changes, also thx bentley@ for telling me sentences should
start on a newline in mdoc.


Index: vmctl.8
===
RCS file: /cvs/src/usr.sbin/vmctl/vmctl.8,v
retrieving revision 1.47
diff -u -p -r1.47 vmctl.8
--- vmctl.8 11 Sep 2018 04:03:16 -  1.47
+++ vmctl.8 19 Sep 2018 10:20:06 -
@@ -90,6 +90,13 @@ Reset and terminate all VMs.
 Send a VM with the specified
 .Ar id
 to standard output and terminate it.
+The VM is paused while send is processing.
+Data sent to standard output contains the VM parameters and its memory,
+not the disk image.
+.Pp
+In order to move a VM from one host to another, disk files must be
+synced between the send and the receive processes and must be located
+under the same path.
 .It Cm show Op Ar id
 An alias for the
 .Cm status




add explanations of vmctl send command in vmctl.8

2018-09-19 Thread Solene Rapenne
This diff explains a little more about the send commands.
send pauses the VM and send its memory + the start parameters.

It's not obvious when you don't know vmctl.

Index: vmctl.8
===
RCS file: /cvs/src/usr.sbin/vmctl/vmctl.8,v
retrieving revision 1.47
diff -u -p -r1.47 vmctl.8
--- vmctl.8 11 Sep 2018 04:03:16 -  1.47
+++ vmctl.8 19 Sep 2018 08:14:11 -
@@ -89,7 +89,9 @@ Reset and terminate all VMs.
 .It Cm send Ar id
 Send a VM with the specified
 .Ar id
-to standard output and terminate it.
+to standard output and terminate it. The VM is paused while sending.
+Data sent to standard output contains the VM parameters and its memory,
+it does not contain the disk image.
 .It Cm show Op Ar id
 An alias for the
 .Cm status


This diff adds an explanation about moving a VM from one host to another.
Not sure if it should be in the man page.

Index: vmctl.8
===
RCS file: /cvs/src/usr.sbin/vmctl/vmctl.8,v
retrieving revision 1.47
diff -u -p -r1.47 vmctl.8
--- vmctl.8 11 Sep 2018 04:03:16 -  1.47
+++ vmctl.8 19 Sep 2018 08:17:16 -
@@ -89,7 +89,12 @@ Reset and terminate all VMs.
 .It Cm send Ar id
 Send a VM with the specified
 .Ar id
-to standard output and terminate it.
+to standard output and terminate it. The VM is paused while sending.
+Data sent to standard output contains the VM parameters and its memory,
+it does not contain the disk image.
+.Pp
+In order to move a VM from one host to another, disk files must be
+synced between the send and the receive processes and must have the same path.
 .It Cm show Op Ar id
 An alias for the
 .Cm status



bgpd: more RB tree less simpleq

2018-09-19 Thread Claudio Jeker
Switch the prefixset simpleq into an RB trie. This allows to spot
duplicates in the parser and is a requirement for roa-sets where
conflicts need to be specially handled.

OK?
-- 
:wq Claudio

Index: bgpd.c
===
RCS file: /cvs/src/usr.sbin/bgpd/bgpd.c,v
retrieving revision 1.198
diff -u -p -r1.198 bgpd.c
--- bgpd.c  9 Sep 2018 11:00:51 -   1.198
+++ bgpd.c  19 Sep 2018 06:34:11 -
@@ -437,7 +437,7 @@ reconfigure(char *conffile, struct bgpd_
struct rde_rib  *rr;
struct rdomain  *rd;
struct prefixset*ps;
-   struct prefixset_item   *psi;
+   struct prefixset_item   *psi, *npsi;
 
if (reconfpending) {
log_info("previous reload still running");
@@ -510,8 +510,8 @@ reconfigure(char *conffile, struct bgpd_
if (imsg_compose(ibuf_rde, IMSG_RECONF_PREFIXSET, 0, 0, -1,
ps->name, sizeof(ps->name)) == -1)
return (-1);
-   while ((psi = SIMPLEQ_FIRST(>psitems)) != NULL) {
-   SIMPLEQ_REMOVE_HEAD(>psitems, entry);
+   RB_FOREACH_SAFE(psi, prefixset_tree, >psitems, npsi) {
+   RB_REMOVE(prefixset_tree, >psitems, psi);
if (imsg_compose(ibuf_rde, IMSG_RECONF_PREFIXSETITEM, 0,
0, -1, psi, sizeof(*psi)) == -1)
return (-1);
Index: bgpd.h
===
RCS file: /cvs/src/usr.sbin/bgpd/bgpd.h,v
retrieving revision 1.340
diff -u -p -r1.340 bgpd.h
--- bgpd.h  14 Sep 2018 10:22:11 -  1.340
+++ bgpd.h  19 Sep 2018 06:32:47 -
@@ -953,15 +953,15 @@ struct filter_set {
 };
 
 struct prefixset_item {
-   struct filter_prefix p;
-   SIMPLEQ_ENTRY(prefixset_item)entry;
+   struct filter_prefixp;
+   RB_ENTRY(prefixset_item)entry;
 };
-SIMPLEQ_HEAD(prefixset_items_h, prefixset_item);
+RB_HEAD(prefixset_tree, prefixset_item);
 
 struct prefixset {
int  sflags;
char name[SET_NAME_LEN];
-   struct prefixset_items_h psitems;
+   struct prefixset_treepsitems;
SIMPLEQ_ENTRY(prefixset) entry;
 };
 
@@ -1085,6 +1085,8 @@ void  filterlist_free(struct filter_head 
 inthost(const char *, struct bgpd_addr *, u_int8_t *);
 void   copy_filterset(struct filter_set_head *, struct filter_set_head *);
 void   expand_networks(struct bgpd_config *);
+intprefixset_cmp(struct prefixset_item *, struct prefixset_item *);
+RB_PROTOTYPE(prefixset_tree, prefixset_item, entry, prefixset_cmp);
 
 /* kroute.c */
 int kr_init(void);
Index: config.c
===
RCS file: /cvs/src/usr.sbin/bgpd/config.c,v
retrieving revision 1.73
diff -u -p -r1.73 config.c
--- config.c9 Sep 2018 11:00:51 -   1.73
+++ config.c19 Sep 2018 06:35:49 -
@@ -120,16 +120,15 @@ void
 free_prefixsets(struct prefixset_head *psh)
 {
struct prefixset*ps;
-   struct prefixset_item   *psi;
+   struct prefixset_item   *psi, *npsi;
 
if (psh == NULL)
return;
 
while (!SIMPLEQ_EMPTY(psh)) {
ps = SIMPLEQ_FIRST(psh);
-   while (!SIMPLEQ_EMPTY(>psitems)) {
-   psi = SIMPLEQ_FIRST(>psitems);
-   SIMPLEQ_REMOVE_HEAD(>psitems, entry);
+   RB_FOREACH_SAFE(psi, prefixset_tree, >psitems, npsi) {
+   RB_REMOVE(prefixset_tree, >psitems, psi);
free(psi);
}
SIMPLEQ_REMOVE_HEAD(psh, entry);
@@ -529,7 +528,7 @@ expand_networks(struct bgpd_config *c)
== NULL)
fatal("%s: prefixset %s not found", __func__,
n->net.psname);
-   SIMPLEQ_FOREACH(psi, >psitems, entry) {
+   RB_FOREACH(psi, prefixset_tree, >psitems) {
if ((m = calloc(1, sizeof(struct network)))
== NULL)
fatal(NULL);
@@ -546,3 +545,48 @@ expand_networks(struct bgpd_config *c)
}
}
 }
+
+int
+prefixset_cmp(struct prefixset_item *a, struct prefixset_item *b)
+{
+   int i;
+
+   if (a->p.addr.aid < b->p.addr.aid)
+   return (-1);
+   if (a->p.addr.aid > b->p.addr.aid)
+   return (1);
+
+   switch (a->p.addr.aid) {
+   case AID_INET:
+   if (ntohl(a->p.addr.v4.s_addr) < ntohl(b->p.addr.v4.s_addr))
+   return (-1);
+   if (ntohl(a->p.addr.v4.s_addr) > ntohl(b->p.addr.v4.s_addr))
+   return