Re: libevent: Protect integer multiplications (min_heap)

2019-04-18 Thread Ted Unangst
Ted Unangst wrote:
> (and then reformat to be knf, but after changes that require review.)

mostly mechanical..

we'll get to real changes eventually :)


Index: min_heap.h
===
RCS file: /cvs/src/lib/libevent/min_heap.h,v
retrieving revision 1.4
diff -u -p -r1.4 min_heap.h
--- min_heap.h  18 Apr 2019 23:44:21 -  1.4
+++ min_heap.h  18 Apr 2019 23:48:36 -
@@ -31,125 +31,152 @@
 
 #include "event.h"
 
-typedef struct min_heap
-{
-struct event** p;
-unsigned n, a;
+typedef struct min_heap {
+   struct event **p;
+   unsigned n, a;
 } min_heap_t;
 
-static inline void   min_heap_ctor(min_heap_t* s);
-static inline void   min_heap_dtor(min_heap_t* s);
-static inline void   min_heap_elem_init(struct event* e);
-static inline intmin_heap_elem_greater(struct event *a, struct 
event *b);
-static inline intmin_heap_empty(min_heap_t* s);
-static inline unsigned   min_heap_size(min_heap_t* s);
-static inline struct event*  min_heap_top(min_heap_t* s);
-static inline intmin_heap_reserve(min_heap_t* s, unsigned n);
-static inline intmin_heap_push(min_heap_t* s, struct event* e);
-static inline struct event*  min_heap_pop(min_heap_t* s);
-static inline intmin_heap_erase(min_heap_t* s, struct event* e);
-static inline void   min_heap_shift_up_(min_heap_t* s, unsigned 
hole_index, struct event* e);
-static inline void   min_heap_shift_down_(min_heap_t* s, unsigned 
hole_index, struct event* e);
-
-int min_heap_elem_greater(struct event *a, struct event *b)
-{
-return timercmp(>ev_timeout, >ev_timeout, >);
-}
-
-void min_heap_ctor(min_heap_t* s) { s->p = 0; s->n = 0; s->a = 0; }
-void min_heap_dtor(min_heap_t* s) { if(s->p) free(s->p); }
-void min_heap_elem_init(struct event* e) { e->min_heap_idx = -1; }
-int min_heap_empty(min_heap_t* s) { return 0u == s->n; }
-unsigned min_heap_size(min_heap_t* s) { return s->n; }
-struct event* min_heap_top(min_heap_t* s) { return s->n ? *s->p : 0; }
-
-int min_heap_push(min_heap_t* s, struct event* e)
-{
-if(min_heap_reserve(s, s->n + 1))
-return -1;
-min_heap_shift_up_(s, s->n++, e);
-return 0;
-}
-
-struct event* min_heap_pop(min_heap_t* s)
-{
-if(s->n)
-{
-struct event* e = *s->p;
-min_heap_shift_down_(s, 0u, s->p[--s->n]);
-e->min_heap_idx = -1;
-return e;
-}
-return 0;
-}
-
-int min_heap_erase(min_heap_t* s, struct event* e)
-{
-if(((unsigned int)-1) != e->min_heap_idx)
-{
-struct event *last = s->p[--s->n];
-unsigned parent = (e->min_heap_idx - 1) / 2;
-   /* we replace e with the last element in the heap.  We might need to
-  shift it upward if it is less than its parent, or downward if it is
-  greater than one or both its children. Since the children are known
-  to be less than the parent, it can't need to shift both up and
-  down. */
-if (e->min_heap_idx > 0 && min_heap_elem_greater(s->p[parent], last))
- min_heap_shift_up_(s, e->min_heap_idx, last);
-else
- min_heap_shift_down_(s, e->min_heap_idx, last);
-e->min_heap_idx = -1;
-return 0;
-}
-return -1;
-}
-
-int min_heap_reserve(min_heap_t* s, unsigned n)
-{
-if(s->a < n)
-{
-struct event** p;
-unsigned a = s->a ? s->a * 2 : 8;
-if(a < n)
-a = n;
-if(!(p = realloc(s->p, a * sizeof *p)))
-return -1;
-s->p = p;
-s->a = a;
-}
-return 0;
-}
-
-void min_heap_shift_up_(min_heap_t* s, unsigned hole_index, struct event* e)
-{
-unsigned parent = (hole_index - 1) / 2;
-while(hole_index && min_heap_elem_greater(s->p[parent], e))
-{
-s->p[hole_index] = s->p[parent];
-s->p[hole_index]->min_heap_idx = hole_index;
-hole_index = parent;
-parent = (hole_index - 1) / 2;
-}
-e->min_heap_idx = hole_index;
-s->p[hole_index] = e;
-}
-
-void min_heap_shift_down_(min_heap_t* s, unsigned hole_index, struct event* e)
-{
-unsigned min_child = 2 * (hole_index + 1);
-while(min_child <= s->n)
-   {
-   if (min_child == s->n ||
-   min_heap_elem_greater(s->p[min_child], s->p[min_child - 1]))
-   min_child -= 1;
-if(!(min_heap_elem_greater(e, s->p[min_child])))
-break;
-s->p[hole_index] = s->p[min_child];
-s->p[hole_index]->min_heap_idx = hole_index;
-hole_index = min_child;
-min_child = 2 * (hole_index + 1);
+static inline void min_heap_ctor(min_heap_t * s);
+static inline void min_heap_dtor(min_heap_t * s);
+static inline void min_heap_elem_init(struct event * e);
+static inline int min_heap_elem_greater(struct event * a, struct event * b);
+static inline int min_heap_empty(min_heap_t * s);
+static inline unsigned min_heap_size(min_heap_t * 

Re: libevent: Protect integer multiplications (min_heap)

2019-04-18 Thread Tobias Stoeckmann
On Wed, Apr 17, 2019 at 11:34:36AM -0400, Ted Unangst wrote:
> (and then reformat to be knf, but after changes that require review.)

Totally agree here. That will help with further changes to this file!

> 
> Index: min_heap.h
> ===
> RCS file: /home/cvs/src/lib/libevent/min_heap.h,v
> retrieving revision 1.3
> diff -u -p -r1.3 min_heap.h
> --- min_heap.h29 Oct 2014 22:47:29 -  1.3
> +++ min_heap.h17 Apr 2019 15:30:02 -
> @@ -112,7 +112,7 @@ int min_heap_reserve(min_heap_t* s, unsi
>  unsigned a = s->a ? s->a * 2 : 8;
>  if(a < n)
>  a = n;
> -if(!(p = (struct event**)realloc(s->p, a * sizeof *p)))
> +if(!(p = realloc(s->p, a * sizeof *p)))
>  return -1;
>  s->p = p;
>  s->a = a;
> @@ -125,11 +125,13 @@ void min_heap_shift_up_(min_heap_t* s, u
>  unsigned parent = (hole_index - 1) / 2;
>  while(hole_index && min_heap_elem_greater(s->p[parent], e))
>  {
> -(s->p[hole_index] = s->p[parent])->min_heap_idx = hole_index;
> +s->p[hole_index] = s->p[parent];
> +s->p[hole_index]->min_heap_idx = hole_index;
>  hole_index = parent;
>  parent = (hole_index - 1) / 2;
>  }
> -(s->p[hole_index] = e)->min_heap_idx = hole_index;
> +e->min_heap_idx = hole_index;
> +s->p[hole_index] = e;
>  }
>  
>  void min_heap_shift_down_(min_heap_t* s, unsigned hole_index, struct event* 
> e)
> @@ -137,10 +139,13 @@ void min_heap_shift_down_(min_heap_t* s,
>  unsigned min_child = 2 * (hole_index + 1);
>  while(min_child <= s->n)
>   {
> -min_child -= min_child == s->n || 
> min_heap_elem_greater(s->p[min_child], s->p[min_child - 1]);
> + if (min_child == s->n ||
> + min_heap_elem_greater(s->p[min_child], s->p[min_child - 1]))
> + min_child -= 1;
>  if(!(min_heap_elem_greater(e, s->p[min_child])))
>  break;
> -(s->p[hole_index] = s->p[min_child])->min_heap_idx = hole_index;
> +s->p[hole_index] = s->p[min_child];
> +s->p[hole_index]->min_heap_idx = hole_index;
>  hole_index = min_child;
>  min_child = 2 * (hole_index + 1);
>   }



Re: [PATCH] [www] cvsync.html - use class="cmdbox"

2019-04-18 Thread Solene Rapenne
On Thu, Apr 18, 2019 at 07:31:45AM +0200, Theo Buehler wrote:
> On Wed, Apr 17, 2019 at 11:41:18PM +0100, Raf Czlonka wrote:
> > On Wed, Apr 17, 2019 at 10:53:54PM BST, Theo Buehler wrote:
> > > On Wed, Apr 17, 2019 at 11:34:56PM +0200, Solene Rapenne wrote:
> > > > On Wed, Apr 17, 2019 at 09:55:26PM +0100, Raf Czlonka wrote:
> > > > > Hi all,
> > > > > 
> > > > > Similar to other pages[0][1], use class="cmdbox", add prompt character
> > > > > where appropriate, and remove superfluous indentation while there.
> > > > > 
> > > > > [0] https://www.openbsd.org/anoncvs.html
> > > > > [1] https://www.openbsd.org/ddb.html
> > > > > 
> > > > > Regards,
> > > > > 
> > > > > Raf
> > > > 
> > > > this looks much better with this
> > > > 
> > > > ok solene@
> > > > 
> > > 
> > > Please send a diff for www/build/mirrors/cvsync.html.* instead
> > 
> > After cvsync.html -> build/mirrors/cvsync.html.head change, the patch
> > applies just fine but, as requested, re-done for the
> > build/mirrors/cvsync.html.head below anyway.
> 
> Looks good.
> 
> ok tb
> 
> Solene, can you take care of committing this?
> 
> > 

done!



Re: dwxe: resetting interface on watchdog timeout

2019-04-18 Thread Theo de Raadt
Sebastien Marie  wrote:

> On Wed, Apr 17, 2019 at 04:32:04PM -0700, Jungle Boogie wrote:
> > On Wed 17 Apr 2019  9:44 AM, Sebastien Marie wrote:
> > > Hi,
> > > 
> > > With a pine64, I am experimenting regulary dwxe watchdog
> > > timeout. Usually it is a sign that something doesn't work in the driver
> > > itself.
> > 
> > Good to know this isn't just affecting my three devices.
> > Let's hope this patch gets some feedback and makes its way into the build.
> 
> you could build a kernel and test it for confirming it works as expected.
> 
> it could really help to have feedback from users.

Resetting the chipset on a timer is a workaround.

It means the root cause hasn't been found and fixed.

It is not a fix.



Re: tunnel interface rxprio config

2019-04-18 Thread Claudio Jeker
On Sun, Apr 14, 2019 at 05:33:07PM +1000, David Gwynne wrote:
> ive been working on RFC 2983 support, with extended functionality.
> 
> rfc 2983 is "Differentiated Services and Tunnels", and discusses where
> prio values should go and come from on tunnel ingress and egress. we
> currentl support setting the packet on tunnel ingress using the txprio
> functionliaty. this diff adds egress or rxprio handling.
> 
> the rfc talks about selecting the outer or inner dscp value on ip
> tunnels. this diff adds this support, and allows config to ignore both
> the inner and outer prio fields, or hardcode it to a specific value like
> we do on tx. it also extends on the rfc by allowing the config to
> apply to other encapsulations, eg, vlan, bpe, and the mpls tunnels can
> support this too.
> 
> the diff below shows the vlan and gif diffs. i have changes for other
> interfaces in a tree somewhere, but i'm happy to commit those on my own
> if everyone's ok with the diff below.
> 
> ok?

This is missing a manpage diff for ifconfig.8 apart from that I'm OK with
it.
 
> Index: sys/sys/sockio.h
> ===
> RCS file: /cvs/src/sys/sys/sockio.h,v
> retrieving revision 1.81
> diff -u -p -r1.81 sockio.h
> --- sys/sys/sockio.h  10 Apr 2019 09:49:50 -  1.81
> +++ sys/sys/sockio.h  14 Apr 2019 07:14:01 -
> @@ -207,6 +207,9 @@
>  #define  SIOCSLIFPHYECN  _IOW('i', 199, struct ifreq)/* set ecn 
> copying */
>  #define  SIOCGLIFPHYECN  _IOWR('i', 200, struct ifreq)   /* get ecn 
> copying */
>  
> +#define  SIOCSRXHPRIO_IOW('i', 219, struct ifreq)/* set rx hdr 
> prio */
> +#define  SIOCGRXHPRIO_IOWR('i', 219, struct ifreq)   /* get rx hdr 
> prio */
> +
>  #define SIOCSPWE3CTRLWORD_IOW('i', 220, struct ifreq)
>  #define SIOCGPWE3CTRLWORD_IOWR('i',  220, struct ifreq)
>  #define SIOCSPWE3FAT _IOW('i', 221, struct ifreq)
> Index: sys/net/if.c
> ===
> RCS file: /cvs/src/sys/net/if.c,v
> retrieving revision 1.575
> diff -u -p -r1.575 if.c
> --- sys/net/if.c  14 Apr 2019 06:57:00 -  1.575
> +++ sys/net/if.c  14 Apr 2019 07:14:01 -
> @@ -2168,6 +2168,7 @@ ifioctl(struct socket *so, u_long cmd, c
>   case SIOCSVNETID:
>   case SIOCSVNETFLOWID:
>   case SIOCSTXHPRIO:
> + case SIOCSRXHPRIO:
>   case SIOCSIFPAIR:
>   case SIOCSIFPARENT:
>   case SIOCDIFPARENT:
> Index: sys/net/if.h
> ===
> RCS file: /cvs/src/sys/net/if.h,v
> retrieving revision 1.200
> diff -u -p -r1.200 if.h
> --- sys/net/if.h  10 Apr 2019 09:49:22 -  1.200
> +++ sys/net/if.h  14 Apr 2019 07:14:02 -
> @@ -427,6 +427,7 @@ structifreq {
>  #define IF_HDRPRIO_MAX   IFQ_MAXPRIO
>  #define IF_HDRPRIO_PACKET-1  /* use mbuf prio */
>  #define IF_HDRPRIO_PAYLOAD   -2  /* copy payload prio */
> +#define IF_HDRPRIO_OUTER -3  /* use outer prio */
>  
>  #define IF_PWE3_ETHERNET 1   /* ethernet or ethernet tagged */
>  #define IF_PWE3_IP   2   /* IP layer 2 */
> Index: sys/net/if_vlan.c
> ===
> RCS file: /cvs/src/sys/net/if_vlan.c,v
> retrieving revision 1.183
> diff -u -p -r1.183 if_vlan.c
> --- sys/net/if_vlan.c 15 Feb 2019 13:00:51 -  1.183
> +++ sys/net/if_vlan.c 14 Apr 2019 07:14:02 -
> @@ -174,6 +174,7 @@ vlan_clone_create(struct if_clone *ifc, 
>  
>   refcnt_init(>ifv_refcnt);
>   ifv->ifv_prio = IF_HDRPRIO_PACKET;
> + ifv->ifv_rxprio = IF_HDRPRIO_OUTER;
>  
>   ifp->if_flags = IFF_BROADCAST | IFF_MULTICAST;
>   ifp->if_xflags = IFXF_CLONED|IFXF_MPSAFE;
> @@ -373,11 +374,6 @@ vlan_input(struct ifnet *ifp0, struct mb
>  
>   /* From now on ether_vtag is fine */
>   tag = EVL_VLANOFTAG(m->m_pkthdr.ether_vtag);
> - m->m_pkthdr.pf.prio = EVL_PRIOFTAG(m->m_pkthdr.ether_vtag);
> -
> - /* IEEE 802.1p has prio 0 and 1 swapped */
> - if (m->m_pkthdr.pf.prio <= 1)
> - m->m_pkthdr.pf.prio = !m->m_pkthdr.pf.prio;
>  
>   list = [TAG_HASH(tag)];
>   SRPL_FOREACH(ifv, , list, ifv_list) {
> @@ -408,6 +404,20 @@ vlan_input(struct ifnet *ifp0, struct mb
>   m_adj(m, EVL_ENCAPLEN);
>   }
>  
> + switch (ifv->ifv_rxprio) {
> + case IF_HDRPRIO_PACKET:
> + break;
> + case IF_HDRPRIO_OUTER:
> + m->m_pkthdr.pf.prio = EVL_PRIOFTAG(m->m_pkthdr.ether_vtag);
> + break;
> + default:
> + m->m_pkthdr.pf.prio = ifv->ifv_rxprio;
> + /* IEEE 802.1p has prio 0 and 1 swapped */
> + if (m->m_pkthdr.pf.prio <= 1)
> + m->m_pkthdr.pf.prio = !m->m_pkthdr.pf.prio;
> + break;
> + }
> +
>   ml_enqueue(, m);
>   if_input(>ifv_if, );
>   SRPL_LEAVE();
> @@ -736,6 +746,22 @@