pretty borders for slitherins

2019-09-23 Thread Ted Unangst
snake and worm draw boxes, but they can be prettier by using the default
style, which will use line drawing instead of ugly -*| characters.

should do the right thing on a vt100, but only tested in xterm.

Index: snake/snake.c
===
RCS file: /home/cvs/src/games/snake/snake.c,v
retrieving revision 1.34
diff -u -p -r1.34 snake.c
--- snake/snake.c   28 Jun 2019 13:32:52 -  1.34
+++ snake/snake.c   13 Sep 2019 17:05:19 -
@@ -450,23 +450,8 @@ setup(void)
pchar([i], SNAKETAIL);
}
pchar([0], SNAKEHEAD);
-   drawbox();
+   border(0, 0, 0, 0, 0, 0, 0, 0);
refresh();
-}
-
-void
-drawbox(void)
-{
-   int i;
-
-   for (i = 1; i <= ccnt; i++) {
-   mvaddch(0, i, '-');
-   mvaddch(lcnt + 1, i, '-');
-   }
-   for (i = 0; i <= lcnt + 1; i++) {
-   mvaddch(i, 0, '|');
-   mvaddch(i, ccnt + 1, '|');
-   }
 }
 
 void
Index: worm/worm.c
===
RCS file: /home/cvs/src/games/worm/worm.c,v
retrieving revision 1.39
diff -u -p -r1.39 worm.c
--- worm/worm.c 24 Aug 2018 11:14:49 -  1.39
+++ worm/worm.c 13 Sep 2019 16:51:39 -
@@ -122,7 +122,7 @@ main(int argc, char **argv)
}
stw = newwin(1, COLS-1, 0, 0);
tv = newwin(LINES-1, COLS-1, 1, 0);
-   box(tv, '*', '*');
+   box(tv, 0, 0);
scrollok(tv, FALSE);
scrollok(stw, FALSE);
wmove(stw, 0, 0);



bgpctl sh nei [group XX] terse: add peer address

2019-09-23 Thread Stuart Henderson
"bgpctl XX nei" functions can now take "group XX" - when used as
"show nei group XX terse" you can't tell which entry relates to each
neighbour.

OK to add the address to the end of the line where it's reasonably
out of the way of existing parsers?

Index: bgpctl.c
===
RCS file: /cvs/src/usr.sbin/bgpctl/bgpctl.c,v
retrieving revision 1.243
diff -u -p -r1.243 bgpctl.c
--- bgpctl.c5 Aug 2019 12:51:32 -   1.243
+++ bgpctl.c23 Sep 2019 21:42:52 -
@@ -601,12 +601,26 @@ int
 show_neighbor_terse(struct imsg *imsg)
 {
struct peer *p;
+   char*s;
 
switch (imsg->hdr.type) {
case IMSG_CTL_SHOW_NEIGHBOR:
p = imsg->data;
+   if ((p->conf.remote_addr.aid == AID_INET &&
+   p->conf.remote_masklen != 32) ||
+   (p->conf.remote_addr.aid == AID_INET6 &&
+   p->conf.remote_masklen != 128)) {
+   if (asprintf(, "%s/%u",
+   log_addr(>conf.remote_addr),
+   p->conf.remote_masklen) == -1)
+   err(1, NULL);
+   } else
+   if ((s = strdup(log_addr(>conf.remote_addr))) ==
+   NULL)
+   err(1, "strdup");
+
printf("%llu %llu %llu %llu %llu %llu %llu "
-   "%llu %llu %llu %u %u %llu %llu %llu %llu\n",
+   "%llu %llu %llu %u %u %llu %llu %llu %llu %s\n",
p->stats.msg_sent_open, p->stats.msg_rcvd_open,
p->stats.msg_sent_notification,
p->stats.msg_rcvd_notification,
@@ -616,7 +630,7 @@ show_neighbor_terse(struct imsg *imsg)
p->stats.prefix_cnt, p->conf.max_prefix,
p->stats.prefix_sent_update, p->stats.prefix_rcvd_update,
p->stats.prefix_sent_withdraw,
-   p->stats.prefix_rcvd_withdraw);
+   p->stats.prefix_rcvd_withdraw, s);
break;
case IMSG_CTL_END:
return (1);
Index: bgpctl.8
===
RCS file: /cvs/src/usr.sbin/bgpctl/bgpctl.8,v
retrieving revision 1.89
diff -u -p -r1.89 bgpctl.8
--- bgpctl.828 Jun 2019 12:12:06 -  1.89
+++ bgpctl.823 Sep 2019 21:47:58 -
@@ -289,7 +289,8 @@ Show statistics in an easily parseable t
 The printed numbers are the sent and received open, sent and received
 notifications, sent and received updates, sent and received keepalives, and
 sent and received route refresh messages plus the current and maximum
-prefix count, the number of sent and received updates, and withdraws.
+prefix count, the number of sent and received updates, sent and
+received withdraws, and finally the neighbor's address.
 .It Cm timers
 Show the BGP timers.
 .El




Re: net80211: fix bug with access point switching channel

2019-09-23 Thread Stefan Sperling
On Mon, Sep 23, 2019 at 06:19:00PM +0200, Tobias Heider wrote:
> bluhm@ and I have noticed that our wifi connection breaks when the access 
> point
> switches channel. The fix is to update the node list node's channel with the
> received channel in STA mode. I've been using the fix for some days now 
> without
> breakage.
> 
> ok?

Yes, OK. Thank you!

> Index: ieee80211_input.c
> ===
> RCS file: /cvs/src/sys/net80211/ieee80211_input.c,v
> retrieving revision 1.209
> diff -u -p -r1.209 ieee80211_input.c
> --- ieee80211_input.c 12 Sep 2019 12:55:07 -  1.209
> +++ ieee80211_input.c 22 Sep 2019 08:54:22 -
> @@ -1380,8 +1380,9 @@ ieee80211_save_ie(const u_int8_t *frm, u
>   */
>  void
>  ieee80211_recv_probe_resp(struct ieee80211com *ic, struct mbuf *m,
> -struct ieee80211_node *ni, struct ieee80211_rxinfo *rxi, int isprobe)
> +struct ieee80211_node *rni, struct ieee80211_rxinfo *rxi, int isprobe)
>  {
> + struct ieee80211_node *ni;
>   const struct ieee80211_frame *wh;
>   const u_int8_t *frm, *efrm;
>   const u_int8_t *tstamp, *ssid, *rates, *xrates, *edcaie, *wmmie;
> @@ -1553,6 +1554,10 @@ ieee80211_recv_probe_resp(struct ieee802
>   /* we know that ssid[1] <= IEEE80211_NWID_LEN */
>   memcpy(ni->ni_essid, [2], ssid[1]);
>   }
> +
> + /* Update channel in case AP has switched */
> + if (ic->ic_opmode == IEEE80211_M_STA)
> + ni->ni_chan = rni->ni_chan;
>  
>   return;
>   }
> 



net80211: fix bug with access point switching channel

2019-09-23 Thread Tobias Heider
bluhm@ and I have noticed that our wifi connection breaks when the access point
switches channel. The fix is to update the node list node's channel with the
received channel in STA mode. I've been using the fix for some days now without
breakage.

ok?

Index: ieee80211_input.c
===
RCS file: /cvs/src/sys/net80211/ieee80211_input.c,v
retrieving revision 1.209
diff -u -p -r1.209 ieee80211_input.c
--- ieee80211_input.c   12 Sep 2019 12:55:07 -  1.209
+++ ieee80211_input.c   22 Sep 2019 08:54:22 -
@@ -1380,8 +1380,9 @@ ieee80211_save_ie(const u_int8_t *frm, u
  */
 void
 ieee80211_recv_probe_resp(struct ieee80211com *ic, struct mbuf *m,
-struct ieee80211_node *ni, struct ieee80211_rxinfo *rxi, int isprobe)
+struct ieee80211_node *rni, struct ieee80211_rxinfo *rxi, int isprobe)
 {
+   struct ieee80211_node *ni;
const struct ieee80211_frame *wh;
const u_int8_t *frm, *efrm;
const u_int8_t *tstamp, *ssid, *rates, *xrates, *edcaie, *wmmie;
@@ -1553,6 +1554,10 @@ ieee80211_recv_probe_resp(struct ieee802
/* we know that ssid[1] <= IEEE80211_NWID_LEN */
memcpy(ni->ni_essid, [2], ssid[1]);
}
+
+   /* Update channel in case AP has switched */
+   if (ic->ic_opmode == IEEE80211_M_STA)
+   ni->ni_chan = rni->ni_chan;
 
return;
}



Re: vmd(8): fix memory leak in virtio network TX path

2019-09-23 Thread Theo Buehler
On Sun, Sep 22, 2019 at 02:42:28AM -0700, Mike Larkin wrote:
> We allocate a 'pkt' for each network packet in the queue, but only were
> freeing the last one. This has always been a bug, but it looks like recent
> changes elsewhere in the network stack may have made the problem more apparent
> since more packets seem to be deposited in the queue for each TX operation
> now.
> 
> This was reported back in July by Paul de Weerd, who told me this could be
> reproduced by doing iperf tests between a VM and the host. He and I have
> tested that this diff seems to resolve the problem.
> 
> There is a similar leak with the built-in vmd(8) DHCP service's packets.
> Both are fixed below. Each pointer is reset to NULL so that the final
> free at the end of the function doesn't double free the last buffer(s).

That doesn't look right as dhcppkt will be used after the while loop:

1542 if (dhcpsz > 0) {
1543 if (vionet_enq_rx(dev, dhcppkt, dhcpsz, ))
1544 ret = 1;
1545 }

I've tried this diff with a local interface and indeed it broke dhcp.

Note that dhcppkt is only allocated once as afterwards dhcpsz > 0 will
prevent further calls to dhcp_request(), so I'm not sure we should touch
dhcppkt at all.

An alternative to the diff below would be to free and null out pkt and
dhcpkt at the beginning of the while loop and setting pktsz and dhcpsz
to 0. Both approaches work for me, but I don't know which is
better/correct.

Index: virtio.c
===
RCS file: /var/cvs/src/usr.sbin/vmd/virtio.c,v
retrieving revision 1.77
diff -u -p -r1.77 virtio.c
--- virtio.c22 Jan 2019 10:12:36 -  1.77
+++ virtio.c23 Sep 2019 06:28:43 -
@@ -1533,6 +1533,9 @@ vionet_notify_tx(struct vionet_dev *dev)
num_enq++;
 
idx = dev->vq[TXQ].last_avail & VIONET_QUEUE_MASK;
+
+   free(pkt);
+   pkt = NULL;
}
 
if (write_mem(q_gpa, vr, vr_sz)) {