mpsafe revarps

2015-09-13 Thread David Gwynne
this moves revarp processing to softnet because it is not mpsafe.

it works fine for general use, but i would like someone to test it
with diskless booting. ie, i want to know if nfs root works with this.

ok?

Index: net/if_ethersubr.c
===
RCS file: /cvs/src/sys/net/if_ethersubr.c,v
retrieving revision 1.224
diff -u -p -r1.224 if_ethersubr.c
--- net/if_ethersubr.c  12 Sep 2015 13:34:12 -  1.224
+++ net/if_ethersubr.c  13 Sep 2015 09:28:14 -
@@ -296,6 +296,7 @@ ether_input(struct ifnet *ifp, struct mb
struct ether_header *eh_tmp;
 #endif
 
+   ac = (struct arpcom *)ifp;
eh = mtod(m, struct ether_header *);
m_adj(m, ETHER_HDR_LEN);
 
@@ -305,7 +306,7 @@ ether_input(struct ifnet *ifp, struct mb
 * if it came from us.
 */
if ((ifp->if_flags & IFF_SIMPLEX) == 0) {
-   if (memcmp(LLADDR(ifp->if_sadl), eh->ether_shost,
+   if (memcmp(ac->ac_enaddr, eh->ether_shost,
ETHER_ADDR_LEN) == 0) {
m_freem(m);
return (1);
@@ -320,10 +321,6 @@ ether_input(struct ifnet *ifp, struct mb
ifp->if_imcasts++;
}
 
-   etype = ntohs(eh->ether_type);
-
-   ac = (struct arpcom *)ifp;
-
/*
 * If packet has been filtered by the bpf listener, drop it now
 * also HW vlan tagged packets that were not collected by vlan(4)
@@ -346,6 +343,8 @@ ether_input(struct ifnet *ifp, struct mb
}
}
 
+   etype = ntohs(eh->ether_type);
+
 decapsulate:
switch (etype) {
case ETHERTYPE_IP:
@@ -361,7 +360,7 @@ decapsulate:
case ETHERTYPE_REVARP:
if (ifp->if_flags & IFF_NOARP)
goto dropanyway;
-   revarpinput(m); /* XXX queue? */
+   inq = 
return (1);
 
 #ifdef INET6
Index: netinet/if_ether.c
===
RCS file: /cvs/src/sys/netinet/if_ether.c,v
retrieving revision 1.166
diff -u -p -r1.166 if_ether.c
--- netinet/if_ether.c  12 Sep 2015 20:26:07 -  1.166
+++ netinet/if_ether.c  13 Sep 2015 09:28:14 -
@@ -95,11 +95,14 @@ void arptfree(struct llinfo_arp *);
 void arptimer(void *);
 struct rtentry *arplookup(u_int32_t, int, int, u_int);
 void in_arpinput(struct mbuf *);
+void revarpinput(struct mbuf *);
+void in_revarpinput(struct mbuf *);
 
 LIST_HEAD(, llinfo_arp) llinfo_arp;
 struct pool arp_pool;  /* pool for llinfo_arp structures */
 /* XXX hate magic numbers */
 struct niqueue arpintrq = NIQUEUE_INITIALIZER(50, NETISR_ARP);
+struct niqueue rarpintrq = NIQUEUE_INITIALIZER(50, NETISR_ARP);
 intarp_inuse, arp_allocated;
 intarp_maxtries = 5;
 intarpinit_done;
@@ -498,6 +501,9 @@ arpintr(void)
}
m_freem(m);
}
+
+   while ((m = niq_dequeue()) != NULL)
+   revarpinput(m);
 }
 
 /*
Index: netinet/if_ether.h
===
RCS file: /cvs/src/sys/netinet/if_ether.h,v
retrieving revision 1.58
diff -u -p -r1.58 if_ether.h
--- netinet/if_ether.h  10 Sep 2015 07:43:18 -  1.58
+++ netinet/if_ether.h  13 Sep 2015 09:28:14 -
@@ -189,6 +189,7 @@ extern u_int8_t etherbroadcastaddr[ETHER
 extern u_int8_t ether_ipmulticast_min[ETHER_ADDR_LEN];
 extern u_int8_t ether_ipmulticast_max[ETHER_ADDR_LEN];
 extern struct niqueue arpintrq;
+extern struct niqueue rarpintrq;
 
 void   arpwhohas(struct arpcom *, struct in_addr *);
 void   arpintr(void);
@@ -273,8 +274,6 @@ extern struct ifnet *revarp_ifp;
 
 void arprequest(struct ifnet *, u_int32_t *, u_int32_t *, u_int8_t *);
 int arpproxy(struct in_addr, unsigned int);
-void revarpinput(struct mbuf *);
-void in_revarpinput(struct mbuf *);
 void revarprequest(struct ifnet *);
 int revarpwhoarewe(struct ifnet *, struct in_addr *, struct in_addr *);
 int revarpwhoami(struct in_addr *, struct ifnet *);



ksh: allow leading space stripping with <<- redirection

2015-09-13 Thread Alessandro DE LAURENZIS
Hello,

The following patch would strip leading blank characters (instead of
tabs only) from the lines in the document when <<- redirection is
used (and should be useful when indentation is done with spaces):

--- tree.h.orig Mon Mar 28 23:28:22 2005
+++ tree.h  Sun Sep 13 08:23:01 2015
@@ -92,7 +92,7 @@
 #defineIOCAT   0x5 /* >> */
 #defineIODUP   0x6 /* <&/>& */
 #defineIOEVAL  BIT(4)  /* expand in << */
-#defineIOSKIP  BIT(5)  /* <<-, skip ^\t* */
+#defineIOSKIP  BIT(5)  /* <<-, skip ^[ \t]* */
 #defineIOCLOB  BIT(6)  /* >|, override -o noclobber */
 #define IORDUP BIT(7)  /* x< (as opposed to x>) */
 #define IONAMEXP BIT(8)/* name has been expanded */

--- lex.c.orig  Sun Sep 13 07:50:06 2015
+++ lex.c   Sun Sep 13 08:08:29 2015
@@ -843,7 +843,7 @@
int c;
char *volatile eof;
char *eofp;
-   int skiptabs;
+   int skipblanks;
XString xs;
char *xp;
int xpos;
@@ -857,13 +857,13 @@
 
for (;;) {
eofp = eof;
-   skiptabs = iop->flag & IOSKIP;
+   skipblanks = iop->flag & IOSKIP;
xpos = Xsavepos(xs, xp);
while ((c = getsc()) != 0) {
-   if (skiptabs) {
-   if (c == '\t')
+   if (skipblanks) {
+   if (isblank(c))
continue;
-   skiptabs = 0;
+   skipblanks = 0;
}
if (c != *eofp)
break;

--- ksh.1.orig  Fri Jul 17 08:39:57 2015
+++ ksh.1   Sun Sep 13 08:11:05 2015
@@ -2085,7 +2085,8 @@
 .It \*(Lt\*(Lt- Ar marker
 Same as
 .Ic \*(Lt\*(Lt ,
-except leading tabs are stripped from lines in the here document.
+except leading blank characters (tabs and spaces) are stripped from lines in
+the here document.
 .It \*(Lt& Ar fd
 Standard input is duplicated from file descriptor
 .Ar fd .

--- sh.1.orig   Wed Jun 17 07:47:43 2015
+++ sh.1Sun Sep 13 08:13:20 2015
@@ -1554,7 +1554,7 @@
 .It Oo Ar n Oc Ns <<-
 Same as
 .Ic << ,
-except leading tabs are stripped from lines in
+except leading blank characters (spaces or tabs) are stripped from lines in
 .Ar block .
 .It Oo Ar n Oc Ns <& Ns Ar file
 Make file descriptor

I don't know if isblank(3) is acceptable here (since I do not understand
from the man page if it could return true for characters different from
spaces and tabs when locales other than C are used); if not, a simple
or operator between '\t' and ' ' could be used instead.

All the best

-- 
Alessandro DE LAURENZIS
[mailto:just22@gmail.com]
LinkedIn: http://it.linkedin.com/in/delaurenzis



mpsafe ip_carp

2015-09-13 Thread David Gwynne
i did this yesterday, but havent had a chance to beat on it properly
yet.

if anyone would like to give it a go it would be much appreciated.
im particularly interested in stability while carp configuration
is made or changed. if it happens to keep handling packets, thats
great, but not blowing up when you run ifconfig is the important
bit atm.

Index: ip_carp.c
===
RCS file: /cvs/src/sys/netinet/ip_carp.c,v
retrieving revision 1.271
diff -u -p -r1.271 ip_carp.c
--- ip_carp.c   12 Sep 2015 20:51:35 -  1.271
+++ ip_carp.c   12 Sep 2015 21:07:42 -
@@ -48,6 +48,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include 
 #include 
@@ -93,7 +94,9 @@ struct carp_mc_entry {
 enum { HMAC_ORIG=0, HMAC_NOV6LL=1, HMAC_MAX=2 };
 
 struct carp_vhost_entry {
-   LIST_ENTRY(carp_vhost_entry)vhost_entries;
+   struct srpl_entry vhost_entries;
+   struct refcnt vhost_refcnt;
+
struct carp_softc *parent_sc;
int vhe_leader;
int vhid;
@@ -114,6 +117,12 @@ struct carp_vhost_entry {
struct sockaddr_dl vhe_sdl; /* for IPv6 ndp balancing */
 };
 
+void   carp_vh_ref(void *, void *);
+void   carp_vh_unref(void *, void *);
+
+struct srpl_rc carp_vh_rc =
+SRPL_RC_INITIALIZER(carp_vh_ref, carp_vh_unref, NULL);
+
 struct carp_softc {
struct arpcom sc_ac;
 #definesc_if   sc_ac.ac_if
@@ -124,7 +133,9 @@ struct carp_softc {
 #ifdef INET6
struct ip6_moptions sc_im6o;
 #endif /* INET6 */
-   TAILQ_ENTRY(carp_softc) sc_list;
+
+   struct srpl_entry sc_list;
+   struct refcnt sc_refcnt;
 
int sc_suppress;
int sc_bow_out;
@@ -137,7 +148,7 @@ struct carp_softc {
 
char sc_curlladdr[ETHER_ADDR_LEN];
 
-   LIST_HEAD(__carp_vhosthead, carp_vhost_entry)   carp_vhosts;
+   struct srpl carp_vhosts;
int sc_vhe_count;
u_int8_t sc_vhids[CARP_MAXNODES];
u_int8_t sc_advskews[CARP_MAXNODES];
@@ -162,13 +173,19 @@ struct carp_softc {
struct carp_vhost_entry *cur_vhe; /* current active vhe */
 };
 
+void   carp_sc_ref(void *, void *);
+void   carp_sc_unref(void *, void *);
+
+struct srpl_rc carp_sc_rc =
+SRPL_RC_INITIALIZER(carp_sc_ref, carp_sc_unref, NULL);
+
 int carp_opts[CARPCTL_MAXID] = { 0, 1, 0, LOG_CRIT };  /* XXX for now */
 struct carpstats carpstats;
 
 intcarp_send_all_recur = 0;
 
 struct carp_if {
-   TAILQ_HEAD(, carp_softc) vhif_vrs;
+   struct srpl vhif_vrs;
 };
 
 #defineCARP_LOG(l, sc, s)  
\
@@ -250,7 +267,9 @@ carp_hmac_prepare(struct carp_softc *sc)
struct carp_vhost_entry *vhe;
u_int8_t i;
 
-   LIST_FOREACH(vhe, >carp_vhosts, vhost_entries) {
+   KERNEL_ASSERT_LOCKED(); /* touching carp_vhosts */
+
+   SRPL_FOREACH_LOCKED(vhe, >carp_vhosts, vhost_entries) {
for (i = 0; i < HMAC_MAX; i++) {
carp_hmac_prepare_ctx(vhe, i);
}
@@ -579,11 +598,12 @@ carp_proto_input_c(struct ifnet *ifp, st
else
cif = (struct carp_if *)ifp->if_carp;
 
-   TAILQ_FOREACH(sc, >vhif_vrs, sc_list) {
+   KERNEL_ASSERT_LOCKED(); /* touching vhif_vrs + carp_vhosts */
+   SRPL_FOREACH_LOCKED(sc, >vhif_vrs, sc_list) {
if (af == AF_INET &&
ismulti != IN_MULTICAST(sc->sc_peer.s_addr))
continue;
-   LIST_FOREACH(vhe, >carp_vhosts, vhost_entries) {
+   SRPL_FOREACH_LOCKED(vhe, >carp_vhosts, vhost_entries) {
if (vhe->vhid == ch->carp_vhid)
goto found;
}
@@ -749,7 +769,9 @@ carp_clone_create(struct if_clone *ifc, 
if (!sc)
return (ENOMEM);
 
-   LIST_INIT(>carp_vhosts);
+   refcnt_init(>sc_refcnt);
+   
+   SRPL_INIT(>carp_vhosts);
sc->sc_vhe_count = 0;
if (carp_new_vhost(sc, 0, 0)) {
free(sc, M_DEVBUF, sizeof(*sc));
@@ -801,6 +823,8 @@ carp_new_vhost(struct carp_softc *sc, in
if (vhe == NULL)
return (ENOMEM);
 
+   refcnt_init(>vhost_refcnt);
+   carp_sc_ref(NULL, sc); /* give a sc ref to the vhe */
vhe->parent_sc = sc;
vhe->vhid = vhid;
vhe->advskew = advskew;
@@ -809,18 +833,23 @@ carp_new_vhost(struct carp_softc *sc, in
timeout_set(>md_tmo, carp_master_down, vhe);
timeout_set(>md6_tmo, carp_master_down, vhe);
 
+   KERNEL_ASSERT_LOCKED(); /* touching carp_vhosts */
+
/* mark the first vhe as leader */
-   if (LIST_EMPTY(>carp_vhosts)) {
+   if (SRPL_EMPTY_LOCKED(>carp_vhosts)) {
vhe->vhe_leader = 1;
-   LIST_INSERT_HEAD(>carp_vhosts, vhe, vhost_entries);
+   SRPL_INSERT_HEAD_LOCKED(_vh_rc, >carp_vhosts,
+   vhe, vhost_entries);
sc->sc_vhe_count = 1;

Re: kill struct inpcbtable's inpt_lastport

2015-09-13 Thread Vincent Gross
On 09/13/15 10:37, Claudio Jeker wrote:
> On Sun, Sep 13, 2015 at 12:18:10AM +0200, Vincent Gross wrote:
>> On 09/12/15 22:10, Claudio Jeker wrote:
>>> On Sat, Sep 12, 2015 at 02:40:59PM +0200, Vincent Gross wrote:
 inpt_lastport is never read without being written before, and only
 in_pcbbind()
 and in6_pcbsetport() are using it. This diff removes inpt_lastport from
 struct inpcbtable and turns it into a local variable where it is used.

 Ok ?
>>> Reads OK but can not be applied because something wrapped some lines.
>>
> 
> Lines are now fixed but now all the tabs got replaced by spaces. So the
> thing still fails to apply.
> 

How about now ?


Index: sys/netinet/in_pcb.c
===
RCS file: /cvs/src/sys/netinet/in_pcb.c,v
retrieving revision 1.179
diff -u -p -r1.179 in_pcb.c
--- sys/netinet/in_pcb.c11 Sep 2015 15:29:47 -  1.179
+++ sys/netinet/in_pcb.c12 Sep 2015 12:22:03 -
@@ -199,7 +199,6 @@ in_pcbinit(struct inpcbtable *table, int
>inpt_lhash);
if (table->inpt_lhashtbl == NULL)
panic("in_pcbinit: hashinit failed for lport");
-   table->inpt_lastport = 0;
table->inpt_count = 0;
arc4random_buf(>inpt_key, sizeof(table->inpt_key));
 }
@@ -281,9 +280,8 @@ in_pcbbind(struct inpcb *inp, struct mbu
 {
struct socket *so = inp->inp_socket;
struct inpcbtable *table = inp->inp_table;
-   u_int16_t *lastport = >inp_table->inpt_lastport;
struct sockaddr_in *sin;
-   u_int16_t lport = 0;
+   u_int16_t lastport, lport = 0;
int wild = 0, reuseport = (so->so_options & SO_REUSEPORT);
int error;
 
@@ -391,16 +389,16 @@ in_pcbbind(struct inpcb *inp, struct mbu
 */
count = first - last;
if (count)
-   *lastport = first - arc4random_uniform(count);
+   lastport = first - arc4random_uniform(count);
 
do {
if (count-- < 0)/* completely used? */
return (EADDRNOTAVAIL);
-   --*lastport;
-   if (*lastport > first || *lastport < last)
-   *lastport = first;
-   lport = htons(*lastport);
-   } while (in_baddynamic(*lastport, 
so->so_proto->pr_protocol) ||
+   --lastport;
+   if (lastport > first || lastport < last)
+   lastport = first;
+   lport = htons(lastport);
+   } while (in_baddynamic(lastport, 
so->so_proto->pr_protocol) ||
in_pcblookup(table, _addr, 0,
>inp_laddr, lport, wild, inp->inp_rtableid));
} else {
@@ -409,16 +407,16 @@ in_pcbbind(struct inpcb *inp, struct mbu
 */
count = last - first;
if (count)
-   *lastport = first + arc4random_uniform(count);
+   lastport = first + arc4random_uniform(count);
 
do {
if (count-- < 0)/* completely used? */
return (EADDRNOTAVAIL);
-   ++*lastport;
-   if (*lastport < first || *lastport > last)
-   *lastport = first;
-   lport = htons(*lastport);
-   } while (in_baddynamic(*lastport, 
so->so_proto->pr_protocol) ||
+   ++lastport;
+   if (lastport < first || lastport > last)
+   lastport = first;
+   lport = htons(lastport);
+   } while (in_baddynamic(lastport, 
so->so_proto->pr_protocol) ||
in_pcblookup(table, _addr, 0,
>inp_laddr, lport, wild, inp->inp_rtableid));
}
Index: sys/netinet/in_pcb.h
===
RCS file: /cvs/src/sys/netinet/in_pcb.h,v
retrieving revision 1.89
diff -u -p -r1.89 in_pcb.h
--- sys/netinet/in_pcb.h16 Apr 2015 19:24:13 -  1.89
+++ sys/netinet/in_pcb.h12 Sep 2015 12:22:03 -
@@ -152,7 +152,6 @@ struct inpcbtable {
struct inpcbhead *inpt_hashtbl, *inpt_lhashtbl;
SIPHASH_KEY inpt_key;
u_longinpt_hash, inpt_lhash;
-   u_int16_t inpt_lastport;
int   inpt_count;
 };
 
Index: sys/netinet6/in6_pcb.c
===
RCS file: 

Re: kill struct inpcbtable's inpt_lastport

2015-09-13 Thread Claudio Jeker
On Sun, Sep 13, 2015 at 12:18:10AM +0200, Vincent Gross wrote:
> On 09/12/15 22:10, Claudio Jeker wrote:
> > On Sat, Sep 12, 2015 at 02:40:59PM +0200, Vincent Gross wrote:
> >> inpt_lastport is never read without being written before, and only
> >> in_pcbbind()
> >> and in6_pcbsetport() are using it. This diff removes inpt_lastport from
> >> struct inpcbtable and turns it into a local variable where it is used.
> >>
> >> Ok ?
> > Reads OK but can not be applied because something wrapped some lines.
> 
> Ok, thunderbird and I reached an agreement where we will keep our legs
> and lines unbroken.
> 

Lines are now fixed but now all the tabs got replaced by spaces. So the
thing still fails to apply.

> 
> --
> Vincent
> 
> 
> Index: sys/netinet/in_pcb.c
> ===
> RCS file: /cvs/src/sys/netinet/in_pcb.c,v
> retrieving revision 1.179
> diff -u -p -r1.179 in_pcb.c
> --- sys/netinet/in_pcb.c11 Sep 2015 15:29:47 -  1.179
> +++ sys/netinet/in_pcb.c12 Sep 2015 12:22:03 -
> @@ -199,7 +199,6 @@ in_pcbinit(struct inpcbtable *table, int
> >inpt_lhash);
> if (table->inpt_lhashtbl == NULL)
> panic("in_pcbinit: hashinit failed for lport");
> -   table->inpt_lastport = 0;
> table->inpt_count = 0;
> arc4random_buf(>inpt_key, sizeof(table->inpt_key));
>  }
> @@ -281,9 +280,8 @@ in_pcbbind(struct inpcb *inp, struct mbu
>  {
> struct socket *so = inp->inp_socket;
> struct inpcbtable *table = inp->inp_table;
> -   u_int16_t *lastport = >inp_table->inpt_lastport;
> struct sockaddr_in *sin;
> -   u_int16_t lport = 0;
> +   u_int16_t lastport, lport = 0;
> int wild = 0, reuseport = (so->so_options & SO_REUSEPORT);
> int error;
>  
> @@ -391,16 +389,16 @@ in_pcbbind(struct inpcb *inp, struct mbu
>  */
> count = first - last;
> if (count)
> -   *lastport = first - arc4random_uniform(count);
> +   lastport = first - arc4random_uniform(count);
>  
> do {
> if (count-- < 0)/* completely used? */
> return (EADDRNOTAVAIL);
> -   --*lastport;
> -   if (*lastport > first || *lastport < last)
> -   *lastport = first;
> -   lport = htons(*lastport);
> -   } while (in_baddynamic(*lastport, 
> so->so_proto->pr_protocol) ||
> +   --lastport;
> +   if (lastport > first || lastport < last)
> +   lastport = first;
> +   lport = htons(lastport);
> +   } while (in_baddynamic(lastport, 
> so->so_proto->pr_protocol) ||
> in_pcblookup(table, _addr, 0,
> >inp_laddr, lport, wild, inp->inp_rtableid));
> } else {
> @@ -409,16 +407,16 @@ in_pcbbind(struct inpcb *inp, struct mbu
>  */
> count = last - first;
> if (count)
> -   *lastport = first + arc4random_uniform(count);
> +   lastport = first + arc4random_uniform(count);
>  
> do {
> if (count-- < 0)/* completely used? */
> return (EADDRNOTAVAIL);
> -   ++*lastport;
> -   if (*lastport < first || *lastport > last)
> -   *lastport = first;
> -   lport = htons(*lastport);
> -   } while (in_baddynamic(*lastport, 
> so->so_proto->pr_protocol) ||
> +   ++lastport;
> +   if (lastport < first || lastport > last)
> +   lastport = first;
> +   lport = htons(lastport);
> +   } while (in_baddynamic(lastport, 
> so->so_proto->pr_protocol) ||
> in_pcblookup(table, _addr, 0,
> >inp_laddr, lport, wild, inp->inp_rtableid));
> }
> Index: sys/netinet/in_pcb.h
> ===
> RCS file: /cvs/src/sys/netinet/in_pcb.h,v
> retrieving revision 1.89
> diff -u -p -r1.89 in_pcb.h
> --- sys/netinet/in_pcb.h16 Apr 2015 19:24:13 -  1.89
> +++ sys/netinet/in_pcb.h12 Sep 2015 12:22:03 -
> @@ -152,7 +152,6 @@ struct inpcbtable {
> struct inpcbhead *inpt_hashtbl, *inpt_lhashtbl;
> SIPHASH_KEY 

Purge route entries when an address is removed

2015-09-13 Thread Martin Pieuchot
Currently we leave RTF_STATIC route entries in the table when the
address they are attached to is removed from a system.

That's why ifas need to be refcounted and that's why we have *a lot*
of checks in the stack to not use cached routes attached to such ifa.

I'd like to simplify all of this by simply purging all the routes
attached to an ifa being removed.  This behavior is coherent with
the fact that routes *need* an ifa to be inserted in the table.

This makes the kernel simpler as it no longer try to find a new ifa
when a route with a stale address is being used.

Tests and oks welcome.

Index: net/if.c
===
RCS file: /cvs/src/sys/net/if.c,v
retrieving revision 1.376
diff -u -p -r1.376 if.c
--- net/if.c12 Sep 2015 20:26:06 -  1.376
+++ net/if.c13 Sep 2015 08:53:56 -
@@ -143,6 +143,7 @@ struct if_clone *if_clone_lookup(const c
 
 intif_group_egress_build(void);
 
+void   if_purgeaddrs(struct ifnet *);
 void   if_link_state_change_task(void *);
 
 void   if_input_process(void *);
@@ -893,7 +894,6 @@ if_deactivate(struct ifnet *ifp)
 void
 if_detach(struct ifnet *ifp)
 {
-   struct ifaddr *ifa;
struct ifg_list *ifg;
struct domain *dp;
int i, s;
@@ -916,7 +916,6 @@ if_detach(struct ifnet *ifp)
 #if NBPFILTER > 0
bpfdetach(ifp);
 #endif
-   rt_if_remove(ifp);
rti_delete(ifp);
 #if NETHER > 0 && defined(NFSCLIENT)
if (ifp == revarp_ifp)
@@ -944,16 +943,7 @@ if_detach(struct ifnet *ifp)
if_free_sadl(ifp);
 
/* We should not have any address left at this point. */
-   if (!TAILQ_EMPTY(>if_addrlist)) {
-#ifdef DIAGNOSTIC
-   printf("%s: address list non empty\n", ifp->if_xname);
-#endif
-   while ((ifa = TAILQ_FIRST(>if_addrlist)) != NULL) {
-   ifa_del(ifp, ifa);
-   ifa->ifa_ifp = NULL;
-   ifafree(ifa);
-   }
-   }
+   if_purgeaddrs(ifp);
 
free(ifp->if_addrhooks, M_TEMP, 0);
free(ifp->if_linkstatehooks, M_TEMP, 0);
@@ -1570,6 +1560,28 @@ if_put(struct ifnet *ifp)
atomic_dec_int(>if_refcnt);
 }
 
+
+/*
+ * Remove the remaining addresses from an interface, this should
+ * theorically not be necessary.
+ */
+void
+if_purgeaddrs(struct ifnet *ifp)
+{
+   struct ifaddr *ifa;
+
+   if (!TAILQ_EMPTY(>if_addrlist)) {
+#ifdef DIAGNOSTIC
+   printf("%s: address list non empty\n", ifp->if_xname);
+#endif
+   while ((ifa = TAILQ_FIRST(>if_addrlist)) != NULL) {
+   ifa_del(ifp, ifa);
+   ifa->ifa_ifp = NULL;
+   ifafree(ifa);
+   }
+   }
+}
+
 /*
  * Interface ioctls.
  */
@@ -1912,7 +1924,6 @@ ifioctl(struct socket *so, u_long cmd, c
 */
if (up)
if_down(ifp);
-   rt_if_remove(ifp);
rti_delete(ifp);
 #ifdef MROUTING
vif_delete(ifp);
@@ -1921,6 +1932,10 @@ ifioctl(struct socket *so, u_long cmd, c
in6_ifdetach(ifp);
 #endif
in_ifdetach(ifp);
+
+   /* We should not have any address left at this point. */
+   if_purgeaddrs(ifp);
+
splx(s);
}
 
@@ -2509,6 +2524,7 @@ void
 ifa_del(struct ifnet *ifp, struct ifaddr *ifa)
 {
TAILQ_REMOVE(>if_addrlist, ifa, ifa_list);
+   rt_ifa_purge(ifa);
 }
 
 void
Index: net/route.c
===
RCS file: /cvs/src/sys/net/route.c,v
retrieving revision 1.239
diff -u -p -r1.239 route.c
--- net/route.c 12 Sep 2015 20:50:17 -  1.239
+++ net/route.c 13 Sep 2015 09:00:43 -
@@ -152,7 +152,7 @@ voidrt_timer_init(void);
 intrtable_alloc(void ***, u_int);
 intrtflushclone1(struct rtentry *, void *, u_int);
 void   rtflushclone(unsigned int, struct rtentry *);
-intrt_if_remove_rtdelete(struct rtentry *, void *, u_int);
+intrt_ifa_remove_rtdelete(struct rtentry *, void *, unsigned int);
 
 struct ifaddr *ifa_ifwithroute(int, struct sockaddr *, struct sockaddr *,
u_int);
@@ -850,22 +850,10 @@ rtrequest1(int req, struct rt_addrinfo *
return (EINVAL);
if ((rt->rt_flags & RTF_CLONING) == 0)
return (EINVAL);
-   if (rt->rt_ifa->ifa_ifp) {
-   info->rti_ifa = rt->rt_ifa;
-   } else {
-   /*
-* The address of the cloning route is not longer
-* configured on an interface, but its descriptor
-* is still there because of reference counting.
-*
-* Try to find a similar active 

Re: Floating point #define in ksh

2015-09-13 Thread Nicholas Marriott
On Sat, Sep 12, 2015 at 08:45:43PM -0400, Michael McConville wrote:
> Nicholas Marriott wrote:
> > Works for me. ok anyone?
> > 
> > I think ksh_limval.h can go entirely after this, per the note in
> > PROJECTS.
> 
> I also just found this gem. It only has one use, so it can probably be
> replaced. Am I interpreting it correctly?

No this is not right. long can still be 32 or 64 bits on different
platforms (such as i386 (ILP32) and amd64 (I32LP64)).

You need to keep the flags checks because long long or a 64-bit long
take up more space on the stack than an int or a 32-bit long - if you
ask va_arg for a long long when there is only an int or a 32-bit long,
it will use the wrong size.

The second check is kind of confusing, because not only was the comment
clearly not updated when changing from short/int to int/long but the
macro itself was not updated when llnum was changed from unsigned long
to unsigned long long.

When llnum was unsigned long, the intent was that -ve numbers were sign
extended for %d but not %[oux]. So where int is 32 bits and long 64
bits, -1 to %d gave (unsigned long)(int)-1 but -1 to %x gave (unsigned
long)(unsigned int)-1. Where int and long are both 32 bits, it didn't
matter.

But llnum is now always 64 bits (unsigned long long) even when long is
32 bits, so the check is now wrong and will not sign extend when it
should (for example on i386).

So the (sizeof (int) < sizeof (long) condition can be removed - now that
llnum is long long, it should actually be sizeof (int) < sizeof (long
long), which is always true on OpenBSD. But we need to keep the true
branch not the false, so that the sign extension happens correctly for
[di] vs [oux].

There is another problem: %d is checked, but not %i - I think they
should be the same.

Also if it is concerned about sign extension for %d vs %x, then it
should be for %ld vs %lx too, because %ld and %d are the same on ILP32
platforms.

So the macro should possibly be expanded to something like:

if (flags & FL_LLONG)
llnum = va_arg(args, unsigned long long);
else if (flags & FL_LONG) {
if (c == 'd' || c == 'i')
llnum = va_arg(args, long);
else
llnum = va_arg(args, unsigned long);
} else {
if (c == 'd' || c == 'i')
llnum = va_arg(args, int);
else
llnum = va_arg(args, unsigned int);
}

I hope this makes sense...

> 
> 
> Index: shf.c
> ===
> RCS file: /cvs/src/bin/ksh/shf.c,v
> retrieving revision 1.16
> diff -u -p -r1.16 shf.c
> --- shf.c 19 Apr 2013 17:36:09 -  1.16
> +++ shf.c 13 Sep 2015 00:42:51 -
> @@ -715,21 +715,6 @@ shf_smprintf(const char *fmt, ...)
>* constant, just use a large buffer.
>*/
>  
> -/*
> - *   What kinda of machine we on?  Hopefully the C compiler will optimize
> - *  this out...
> - *
> - *   For shorts, we want sign extend for %d but not for %[oxu] - on 16 bit
> - *  machines it don't matter.  Assumes C compiler has converted shorts to
> - *  ints before pushing them.
> - */
> -#define POP_INT(f, s, a) \
> - (((f) & FL_LLONG) ? va_arg((a), unsigned long long) :   \
> - ((f) & FL_LONG) ? va_arg((a), unsigned long) :  \
> - (sizeof(int) < sizeof(long) ? ((s) ?\
> - (long) va_arg((a), int) : va_arg((a), unsigned)) :  \
> - va_arg((a), unsigned)))
> -
>  #define ABIGNUM  32000   /* big numer that will fit in a short */
>  #define LOG2_10  3.321928094887362347870319429   /* log base 2 
> of 10 */
>  
> @@ -890,7 +875,7 @@ shf_vfprintf(struct shf *shf, const char
>   case 'x':
>   flags |= FL_NUMBER;
>   s = [sizeof(numbuf)];
> - llnum = POP_INT(flags, c == 'd', args);
> + llnum = va_arg(args, unsigned long long);
>   switch (c) {
>   case 'd':
>   case 'i':



Re: ksh: allow leading space stripping with <<- redirection

2015-09-13 Thread Philip Guenther
On Sun, Sep 13, 2015 at 8:46 AM, Alessandro DE LAURENZIS
 wrote:
> The following patch would strip leading blank characters (instead of
> tabs only) from the lines in the document when <<- redirection is
> used (and should be useful when indentation is done with spaces):

Nope.  The just-strip-tabs behavior is straight from the standard.  To
quote SUSv4 XCU section 2.7.4 paragraph 5:
If the redirection symbol is "<<-", all leading  characters
shall be stripped from input lines
and the line containing the trailing delimiter. If more than one
"<<" or "<<-" operator is
specified on a line, the here-document associated with the first
operator shall be supplied first
by the application and shall be read first by the shell.


Philip Guenther



Re: ksh: allow leading space stripping with <<- redirection

2015-09-13 Thread Alessandro DE LAURENZIS
Hello Philip,

On Sun 13/09/2015 09:32, Philip Guenther wrote:
[...]
> Nope.  The just-strip-tabs behavior is straight from the standard.  To
> quote SUSv4 XCU section 2.7.4 paragraph 5:
[...]
Got it, thanks for your feedback.

Cheers

-- 
Alessandro DE LAURENZIS
[mailto:just22@gmail.com]
LinkedIn: http://it.linkedin.com/in/delaurenzis



netstart: only call ifautoconf is rtsolif is populated

2015-09-13 Thread Stuart Henderson
Avoid printing "IPv6 autoconf:" if you have no v6 rtsol interfaces.
OK?

Index: netstart
===
RCS file: /cvs/src/etc/netstart,v
retrieving revision 1.154
diff -u -p -r1.154 netstart
--- netstart11 Sep 2015 12:21:52 -  1.154
+++ netstart13 Sep 2015 12:18:14 -
@@ -180,7 +180,7 @@ if [ $# -gt 0 ]; then
ifstart $1
shift
done
-   ifautoconf
+   [[ -n $rtsolif ]] && ifautoconf
return
 fi
 
@@ -263,7 +263,7 @@ ifmstart "" "trunk svlan vlan carp gif g
 ifmstart "trunk svlan vlan carp"
 
 # Now that $rtsolif has been populated, IPv6 autoconf those interfaces
-ifautoconf
+[[ -n $rtsolif ]] && ifautoconf
 
 # Look for default routes in /etc/mygate.
 [[ -z $dhcpif ]] && stripcom /etc/mygate | while read gw; do



[PATCH] mount_tmpfs -P option for populating after mounting (simplified)

2015-09-13 Thread bytevolcano
Hello,

Although a patch like this was submitted before, this one is more "focused". It 
may be useful for those moving from MFS who use this option to pre-populate an 
MFS mount with a collection of files.
This will refuse to work if the path specified for -P is not a directory.
If the copy is unsuccessful, unmount and inform the user.

A few questions on this though:

1. Is there a better way than executing pax, to copy all the files in a 
directory?

2. The do_exec() function was sort of copied from sbin/newfs/newfs.c. It 
doesn't feel like the best way of handling this, but some research suggests it 
is better than calling system() due to security issues, one that springs to 
mind is a malformed input directory to the -P option. Is there a simple way to 
sanitise the input for use with system()?

3. I noticed a pattern of functions that have about 2-3 lines of code in them. 
Is it best to keep things that way, or is it best to merge them into a single 
function (eg. copy_dir() merged into the mount_tmpfs() function)?

4. Are variable declarations to be at the beginning of a function block, or the 
beginning of the immediate block? I feel limiting scope is a good idea, but 
would like some feedback on this as I cannot see anything in style(9).

5. Is mount_tmpfs.h really necessary, given nothing in the tree seems to use 
anything related to the mount_tmpfs() function which is internal to the 
mount_tmpfs binary?


 -

Index: sbin/mount_tmpfs/mount_tmpfs.8
===
RCS file: /cvs/src/sbin/mount_tmpfs/mount_tmpfs.8,v
retrieving revision 1.4
diff -u -p -r1.4 mount_tmpfs.8
--- sbin/mount_tmpfs/mount_tmpfs.8  16 Nov 2014 02:22:10 -  1.4
+++ sbin/mount_tmpfs/mount_tmpfs.8  13 Sep 2015 13:03:34 -
@@ -41,6 +41,7 @@
 .Op Fl m Ar mode
 .Op Fl n Ar nodes
 .Op Fl o Ar options
+.Op Fl P Ar directory
 .Op Fl s Ar size
 .Op Fl u Ar user
 .Ar tmpfs
@@ -80,6 +81,8 @@ flag followed by a comma-separated strin
 See the
 .Xr mount 8
 man page for possible options and their meanings.
+.It Fl P Ar directory
+Populate the created tmpfs file system with the contents of the directory.
 .It Fl s Ar size
 Specifies the total file system size in bytes.
 If zero is given (the default), the available amount of memory (including
@@ -136,6 +139,10 @@ and
 .Ox 5.5 .
 .Sh CAVEATS
 The update of mount options (through mount -u) is currently not supported.
+The
+.Fl P
+option will produce an error if the mount is read-only, or if the files
+cannot be copied from the specified template directory.
 .Sh BUGS
 File system meta-data is not pageable.
 If there is not enough main memory to hold this information, the system may
Index: sbin/mount_tmpfs/mount_tmpfs.c
===
RCS file: /cvs/src/sbin/mount_tmpfs/mount_tmpfs.c,v
retrieving revision 1.5
diff -u -p -r1.5 mount_tmpfs.c
--- sbin/mount_tmpfs/mount_tmpfs.c  16 Jan 2015 06:39:59 -  1.5
+++ sbin/mount_tmpfs/mount_tmpfs.c  13 Sep 2015 13:03:34 -
@@ -34,6 +34,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include 
 #include 
@@ -41,6 +42,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -68,12 +70,15 @@ static int  a_num(const char *, const cha
 static mode_t  a_mask(const char *);
 static voidpathadj(const char *, char *);
 
+static int do_exec(const char *, const char *, char *const[]);
+static int copy_dir(char *, char *);
+
 /* - */
 
 void
 mount_tmpfs_parseargs(int argc, char *argv[],
struct tmpfs_args *args, int *mntflags,
-   char *canon_dev, char *canon_dir)
+   char *canon_dev, char *canon_dir, char *pop_dir)
 {
int gidset, modeset, uidset; /* Ought to be 'bool'. */
int ch;
@@ -95,7 +100,7 @@ mount_tmpfs_parseargs(int argc, char *ar
modeset = 0; mode = 0;
 
optind = optreset = 1;
-   while ((ch = getopt(argc, argv, "g:m:n:o:s:u:")) != -1 ) {
+   while ((ch = getopt(argc, argv, "P:g:m:n:o:s:u:")) != -1 ) {
switch (ch) {
case 'g':
gid = a_gid(optarg);
@@ -131,6 +136,10 @@ mount_tmpfs_parseargs(int argc, char *ar
uidset = 1;
break;
 
+   case 'P':
+   strlcpy(pop_dir, optarg, PATH_MAX);
+   break;
+
case '?':
default:
usage();
@@ -161,7 +170,8 @@ usage(void)
extern char *__progname;
(void)fprintf(stderr,
"usage: %s [-g group] [-m mode] [-n nodes] [-o options] [-s size]\n"
-   "   [-u user] tmpfs mount_point\n", __progname);
+   "   [-P directory] [-u user] tmpfs mount_point\n",
+   __progname);
exit(1);
 }
 
@@ -172,14 +182,33 @@ mount_tmpfs(int argc, char *argv[])
 {

Re: netstart: only call ifautoconf is rtsolif is populated

2015-09-13 Thread Robert Peichaer
On Sun, Sep 13, 2015 at 01:35:02PM +0100, Stuart Henderson wrote:
> On 2015/09/13 13:19, Stuart Henderson wrote:
> > Avoid printing "IPv6 autoconf:" if you have no v6 rtsol interfaces.
> > OK?
> 
> As suggested by rpe, just do the check once in ifautoconf.
> (I was trying to avoid the indent, but it's not too horrible)
> 
> Index: netstart
> ===
> RCS file: /cvs/src/etc/netstart,v
> retrieving revision 1.154
> diff -u -p -r1.154 netstart
> --- netstart  11 Sep 2015 12:21:52 -  1.154
> +++ netstart  13 Sep 2015 12:33:38 -
> @@ -154,16 +154,18 @@ ifmstart() {
>  # IPv6 autoconf the interfaces in the list at $rtsolif
>  # Usage: ifautoconf
>  ifautoconf() {
> - printf 'IPv6 autoconf:'
> - # $ip6kernel will not have been set if we were invoked with a
> - # list of interface names
> - if ifconfig lo0 inet6 >/dev/null 2>&1; then
> - for curif in $rtsolif; do
> - printf ' %s' $curif
> - ifconfig $curif inet6 autoconf
> - done
> + if [[ -n $rtsolif ]]; then
> + printf 'IPv6 autoconf:'
> + # $ip6kernel will not have been set if we were invoked with a
> + # list of interface names
> + if ifconfig lo0 inet6 >/dev/null 2>&1; then
> + for curif in $rtsolif; do
> + printf ' %s' $curif
> + ifconfig $curif inet6 autoconf
> + done
> + fi
> + echo
>   fi
> - echo
>  }
>  
>  # Get network related vars from rc.conf using the parsing routine from 
> rc.subr.
> 

fwiw. OK rpe@

-- 
-=[rpe]=-



Re: Purge route entries when an address is removed

2015-09-13 Thread Martin Pieuchot
On 13/09/15(Sun) 15:51, Alexander Bluhm wrote:
> On Sun, Sep 13, 2015 at 11:15:50AM +0200, Martin Pieuchot wrote:
> > This makes the kernel simpler as it no longer try to find a new ifa
> > when a route with a stale address is being used.
> 
> This makes the code simpler, which is good.
> 
> I am still not convinced that we want to loose the feature that the
> routes jump to another interface address.  When we have multiple
> suiteable addresses and one gets deleted, the system can use another
> one.

This is the price to pay for making the code simpler.  I strongly
believe this "feature" is a side effect of history that should not
have been added in the first place.

However I'd like to fix potential issues with this diff before committing
it, so tests are welcome :)

> The patch itself looks correct.  Just one question:
> 
> > @@ -850,22 +850,10 @@ rtrequest1(int req, struct rt_addrinfo *
> > return (EINVAL);
> > if ((rt->rt_flags & RTF_CLONING) == 0)
> > return (EINVAL);
> > -   if (rt->rt_ifa->ifa_ifp) {
> > -   info->rti_ifa = rt->rt_ifa;
> > -   } else {
> > -   /*
> > -* The address of the cloning route is not longer
> > -* configured on an interface, but its descriptor
> > -* is still there because of reference counting.
> > -*
> > -* Try to find a similar active address and use
> > -* it for the cloned route.  The cloning route
> > -* will get the new address and interface later.
> > -*/
> > -   info->rti_ifa = NULL;
> > -   info->rti_info[RTAX_IFA] = rt->rt_ifa->ifa_addr;
> > -   }
> > +   if (rt->rt_ifa->ifa_ifp == NULL)
> > +   return (EAGAIN);
> 
> Why return EAGAIN here?  Should it be EINVAL like in the other
> cases?  Can this happen at all?

This should never happen but I'd like to take a safe approach and be
able to differentiate the error code if this still happens.  I'd
happily turn this into a KASSERT() but not right now.



lpd: move hosts.lpd parsing into lpd proper

2015-09-13 Thread Todd C. Miller
This should allow us to stop exporting __ivaliduser and __ivaliduser_sa
from libc and to eventually remove ruserok from libc entirely.

Needs testing by someone who actually runs lpd...

 - todd

Index: usr.sbin/lpr/lpd/Makefile
===
RCS file: /cvs/src/usr.sbin/lpr/lpd/Makefile,v
retrieving revision 1.5
diff -u -p -u -r1.5 Makefile
--- usr.sbin/lpr/lpd/Makefile   10 Dec 2013 16:38:04 -  1.5
+++ usr.sbin/lpr/lpd/Makefile   13 Sep 2015 15:21:13 -
@@ -5,7 +5,7 @@ PROG=   lpd
 CFLAGS+=-I${.CURDIR}/../common_source
 MAN=   lpd.8
 SRCS=  lpd.c printjob.c recvjob.c displayq.c rmjob.c startdaemon.c \
-   lpdchar.c common.c key.c modes.c common_vars.c
+   lpdchar.c common.c key.c modes.c common_vars.c allowedhost.c
 BINGRP=daemon
 BINMODE=2550
 .PATH: ${.CURDIR}/../common_source
Index: usr.sbin/lpr/lpd/allowedhost.c
===
RCS file: usr.sbin/lpr/lpd/allowedhost.c
diff -N usr.sbin/lpr/lpd/allowedhost.c
--- /dev/null   1 Jan 1970 00:00:00 -
+++ usr.sbin/lpr/lpd/allowedhost.c  13 Sep 2015 15:21:32 -
@@ -0,0 +1,249 @@
+/*
+ * Copyright (c) 1995, 1996, 1998 Theo de Raadt.  All rights reserved.
+ * Copyright (c) 1983, 1993, 1994
+ * The Regents of the University of California.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *notice, this list of conditions and the following disclaimer in the
+ *documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ *may be used to endorse or promote products derived from this software
+ *without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include 
+#include 
+
+#include 
+#include 
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+intallowedhost(FILE *, struct sockaddr *, socklen_t);
+static int checkhost(struct sockaddr *, socklen_t, const char *);
+static char *gethostloop(struct sockaddr *, socklen_t);
+
+/*
+ * Check whether the specified addr is listed in hostf.
+ * Returns 0 if ok, -1 if not ok.
+ */
+int
+allowedhost(FILE *hostf, struct sockaddr *raddr, socklen_t salen)
+{
+   char *buf, *cp, *ep;
+   const char *ahost;
+   int hostok;
+   char *rhost = (char *)-1;
+   char domain[HOST_NAME_MAX+1];
+   size_t buflen;
+
+   getdomainname(domain, sizeof(domain));
+
+   while ((buf = fgetln(hostf, ))) {
+   cp = buf;
+   ep = buf + buflen;
+   if (*cp == '#')
+   continue;
+   while (cp < ep && *cp != '\n' && *cp != ' ' && *cp != '\t') {
+   if (!isprint((unsigned char)*cp))
+   goto bail;
+   *cp = isupper((unsigned char)*cp) ?
+   tolower((unsigned char)*cp) : *cp;
+   cp++;
+   }
+   while (cp < ep && (*cp == '\n' || *cp == ' ' || *cp == '\t'))
+   *cp++ = '\0';
+   if (cp > ep)
+   continue;
+   if (cp == buf || cp[-1] != '\0')
+   continue;
+
+   ahost = buf;
+   if (strlen(ahost) > HOST_NAME_MAX)
+   continue;
+
+   /*
+* innetgr() must lookup a hostname (we do not attempt
+* to change the semantics so that netgroups may have
+* #.#.#.# addresses in the list.)
+*/
+   if (ahost[0] == '+')
+   switch (ahost[1]) {
+   case '\0':
+   hostok = 1;
+   break;
+   case '@':
+ 

IPv6 transport for pflow(4)

2015-09-13 Thread Florian Obser
I don't really like to store struct sockaddr_storage since it's so
big. I played around with a union like pf does, but looked
complicated.
Thoughts?

Also with this you can specify a source port.
Since I was touching all those lines anyway I renamed sender to
flowsrc and receiver to flowdst like the ifconfig keywords. I found
the names of these struct members always confusing.
Test, comments, OKs?

diff --git sbin/ifconfig/ifconfig.8 sbin/ifconfig/ifconfig.8
index 85244d3..b3851aa 100644
--- sbin/ifconfig/ifconfig.8
+++ sbin/ifconfig/ifconfig.8
@@ -1277,7 +1277,7 @@ network.
 .Nm ifconfig
 .Ar pflow-interface
 .Op Oo Fl Oc Ns Cm flowdst Ar addr : Ns Ar port
-.Op Oo Fl Oc Ns Cm flowsrc Ar addr
+.Op Oo Fl Oc Ns Cm flowsrc Ar addr Oo : Ns Ar port Oc
 .Op Cm pflowproto Ar n
 .Ek
 .nr nS 0
@@ -1298,7 +1298,7 @@ is the port number of the flow collector.
 Pflow data will be sent to this address/port.
 .It Fl flowdst
 Unset the receiver address and stop sending pflow data.
-.It Cm flowsrc Ar addr
+.It Cm flowsrc Ar addr Oo : Ns Ar port Oc
 Set the source IP address for pflow packets.
 .Ar addr
 is the IP address used as sender of the UDP packets and may be used to
diff --git sbin/ifconfig/ifconfig.c sbin/ifconfig/ifconfig.c
index 63f6956..bee5dc2 100644
--- sbin/ifconfig/ifconfig.c
+++ sbin/ifconfig/ifconfig.c
@@ -265,6 +265,7 @@ voidsetifpowersave(const char *, int);
 void   setifmetric(const char *, int);
 void   notrailers(const char *, int);
 void   pflow_status(void);
+void   pflow_addr(const char*, struct sockaddr_storage *);
 void   setpflow_sender(const char *, int);
 void   unsetpflow_sender(const char *, int);
 void   setpflow_receiver(const char *, int);
@@ -4280,7 +4281,11 @@ pfsync_status(void)
 void
 pflow_status(void)
 {
-   struct pflowreq preq;
+   struct pflowreq  preq;
+   struct sockaddr_in  *sin;
+   struct sockaddr_in6 *sin6;
+   int  error;
+   char buf[INET6_ADDRSTRLEN];
 
bzero(, sizeof(struct pflowreq));
ifr.ifr_data = (caddr_t)
@@ -4288,47 +4293,135 @@ pflow_status(void)
if (ioctl(s, SIOCGETPFLOW, (caddr_t)) == -1)
 return;
 
+   if (preq.flowsrc.ss_family == AF_INET || preq.flowsrc.ss_family ==
+   AF_INET6) {
+   error = getnameinfo((struct sockaddr*),
+   preq.flowsrc.ss_len, buf, sizeof(buf), NULL, 0,
+   NI_NUMERICHOST);
+   if (error)
+   err(1, "sender: %s", gai_strerror(error));
+   }
+
printf("\tpflow: ");
-   if (preq.sender_ip.s_addr != INADDR_ANY)
-   printf("sender: %s ", inet_ntoa(preq.sender_ip));
-   printf("receiver: %s:", preq.receiver_ip.s_addr != INADDR_ANY ?
-   inet_ntoa(preq.receiver_ip) : "INVALID");
-   if (preq.receiver_port == 0)
-   printf("%s ", "INVALID");
-   else
-   printf("%u ", ntohs(preq.receiver_port));
+   switch (preq.flowsrc.ss_family) {
+   case AF_INET:
+   sin = (struct sockaddr_in*) 
+   if (sin->sin_addr.s_addr != INADDR_ANY) {
+   printf("sender: %s", buf);
+   if (sin->sin_port != 0)
+   printf(":%u", ntohs(sin->sin_port));
+   printf(" ");
+   }
+   break;
+   case AF_INET6:
+   sin6 = (struct sockaddr_in6*) 
+   if (!IN6_IS_ADDR_UNSPECIFIED(>sin6_addr)) {
+   printf("sender: [%s]", buf);
+   if (sin6->sin6_port != 0)
+   printf(":%u", ntohs(sin6->sin6_port));
+   printf(" ");
+   }
+   default:
+   break;
+   }
+   if (preq.flowdst.ss_family == AF_INET || preq.flowdst.ss_family ==
+   AF_INET6) {
+   error = getnameinfo((struct sockaddr*),
+   preq.flowdst.ss_len, buf, sizeof(buf), NULL, 0,
+   NI_NUMERICHOST);
+   if (error)
+   err(1, "receiver: %s", gai_strerror(error));
+   }
+   switch (preq.flowdst.ss_family) {
+   case AF_INET:
+   sin = (struct sockaddr_in*)
+   printf("receiver: %s:", sin->sin_addr.s_addr != INADDR_ANY ?
+   buf : "INVALID");   
+   if (sin->sin_port == 0)
+   printf("%s ", "INVALID");
+   else
+   printf("%u ", ntohs(sin->sin_port));
+   break;
+   case AF_INET6:
+   sin6 = (struct sockaddr_in6*) 
+   printf("receiver: [%s]:",
+   !IN6_IS_ADDR_UNSPECIFIED(>sin6_addr) ? buf :
+   "INVALID"); 
+   if (sin6->sin6_port == 0)
+   printf("%s ", "INVALID");
+   else
+   printf("%u ", ntohs(sin6->sin6_port));
+

Re: netstart: only call ifautoconf is rtsolif is populated

2015-09-13 Thread Stuart Henderson
On 2015/09/13 13:19, Stuart Henderson wrote:
> Avoid printing "IPv6 autoconf:" if you have no v6 rtsol interfaces.
> OK?

As suggested by rpe, just do the check once in ifautoconf.
(I was trying to avoid the indent, but it's not too horrible)

Index: netstart
===
RCS file: /cvs/src/etc/netstart,v
retrieving revision 1.154
diff -u -p -r1.154 netstart
--- netstart11 Sep 2015 12:21:52 -  1.154
+++ netstart13 Sep 2015 12:33:38 -
@@ -154,16 +154,18 @@ ifmstart() {
 # IPv6 autoconf the interfaces in the list at $rtsolif
 # Usage: ifautoconf
 ifautoconf() {
-   printf 'IPv6 autoconf:'
-   # $ip6kernel will not have been set if we were invoked with a
-   # list of interface names
-   if ifconfig lo0 inet6 >/dev/null 2>&1; then
-   for curif in $rtsolif; do
-   printf ' %s' $curif
-   ifconfig $curif inet6 autoconf
-   done
+   if [[ -n $rtsolif ]]; then
+   printf 'IPv6 autoconf:'
+   # $ip6kernel will not have been set if we were invoked with a
+   # list of interface names
+   if ifconfig lo0 inet6 >/dev/null 2>&1; then
+   for curif in $rtsolif; do
+   printf ' %s' $curif
+   ifconfig $curif inet6 autoconf
+   done
+   fi
+   echo
fi
-   echo
 }
 
 # Get network related vars from rc.conf using the parsing routine from rc.subr.



Re: [PATCH] Initial implementation of posix_fallocate(2)

2015-09-13 Thread Dimitris Papastamos
Hi,

A slightly updated patch.  Removed some checks that were
redundant.

Index: kern/init_sysent.c
===
RCS file: /cvs/src/sys/kern/init_sysent.c,v
retrieving revision 1.171
diff -u -p -r1.171 init_sysent.c
--- kern/init_sysent.c  9 Sep 2015 17:57:57 -   1.171
+++ kern/init_sysent.c  13 Sep 2015 15:47:11 -
@@ -1,4 +1,4 @@
-/* $OpenBSD: init_sysent.c,v 1.171 2015/09/09 17:57:57 deraadt Exp $   
*/
+/* $OpenBSD$   */
 
 /*
  * System call switch table.
@@ -751,5 +751,7 @@ struct sysent sysent[] = {
sys___set_tcb },/* 329 = __set_tcb */
{ 0, 0, SY_NOLOCK | 0,
sys___get_tcb },/* 330 = __get_tcb */
+   { 3, s(struct sys_posix_fallocate_args), 0,
+   sys_posix_fallocate },  /* 331 = posix_fallocate */
 };
 
Index: kern/syscalls.c
===
RCS file: /cvs/src/sys/kern/syscalls.c,v
retrieving revision 1.170
diff -u -p -r1.170 syscalls.c
--- kern/syscalls.c 9 Sep 2015 17:57:57 -   1.170
+++ kern/syscalls.c 13 Sep 2015 15:47:11 -
@@ -1,4 +1,4 @@
-/* $OpenBSD: syscalls.c,v 1.170 2015/09/09 17:57:57 deraadt Exp $  */
+/* $OpenBSD$   */
 
 /*
  * System call names.
@@ -393,4 +393,5 @@ char *syscallnames[] = {
"#328 (obsolete __tfork51)",/* 328 = obsolete __tfork51 */
"__set_tcb",/* 329 = __set_tcb */
"__get_tcb",/* 330 = __get_tcb */
+   "posix_fallocate",  /* 331 = posix_fallocate */
 };
Index: kern/syscalls.master
===
RCS file: /cvs/src/sys/kern/syscalls.master,v
retrieving revision 1.158
diff -u -p -r1.158 syscalls.master
--- kern/syscalls.master9 Sep 2015 17:56:59 -   1.158
+++ kern/syscalls.master13 Sep 2015 15:47:12 -
@@ -561,3 +561,4 @@
 328OBSOL   __tfork51
 329STD NOLOCK  { void sys___set_tcb(void *tcb); }
 330STD NOLOCK  { void *sys___get_tcb(void); }
+331STD { int sys_posix_fallocate(int fd, off_t offset, off_t 
len); }
Index: kern/vfs_syscalls.c
===
RCS file: /cvs/src/sys/kern/vfs_syscalls.c,v
retrieving revision 1.227
diff -u -p -r1.227 vfs_syscalls.c
--- kern/vfs_syscalls.c 31 Aug 2015 16:13:11 -  1.227
+++ kern/vfs_syscalls.c 13 Sep 2015 15:47:12 -
@@ -3023,3 +3023,40 @@ sys_pwritev(struct proc *p, void *v, reg
1, , retval));
 }
 
+int
+sys_posix_fallocate(struct proc *p, void *v, register_t *retval)
+{
+   struct sys_posix_fallocate_args /* {
+   syscallarg(int) fd;
+   syscallarg(off_t) offset;
+   syscallarg(off_t) len;
+   } */ *uap = v;
+   struct vnode *vp;
+   struct file *fp;
+   int error;
+
+   if (SCARG(uap, offset) < 0 || SCARG(uap, len) < 0)
+   return (EINVAL);
+   if (SCARG(uap, offset) > LLONG_MAX - SCARG(uap, len))
+   return (EFBIG);
+
+   if ((error = getvnode(p, SCARG(uap, fd), )) != 0)
+   return (error);
+   if ((fp->f_flag & FWRITE) == 0) {
+   error = EBADF;
+   goto bad;
+   }
+   vp = fp->f_data;
+   vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, p);
+   if (vp->v_type == VFIFO)
+   error = ESPIPE;
+   else if (vp->v_type != VREG)
+   error = ENODEV;
+   else if ((error = vn_writechk(vp)) == 0)
+   error = vn_fallocate(vp, SCARG(uap, offset),
+SCARG(uap, len), p);
+   VOP_UNLOCK(vp, 0, p);
+bad:
+   FRELE(fp, p);
+   return (error);
+}
Index: kern/vfs_vnops.c
===
RCS file: /cvs/src/sys/kern/vfs_vnops.c,v
retrieving revision 1.82
diff -u -p -r1.82 vfs_vnops.c
--- kern/vfs_vnops.c1 May 2015 01:30:58 -   1.82
+++ kern/vfs_vnops.c13 Sep 2015 15:47:12 -
@@ -573,3 +573,70 @@ vn_isunder(struct vnode *lvp, struct vno
 
return (0);
 }
+
+int
+vn_fallocate(struct vnode *vp, off_t offset, off_t len, struct proc *p)
+{
+   struct vattr va;
+   uint8_t *buf;
+   off_t cur, fsize;
+   long blksize;
+   size_t resid;
+   int error;
+
+   if ((error = VOP_GETATTR(vp, , p->p_ucred, p)) != 0)
+   return (error);
+   fsize = va.va_size;
+   blksize = va.va_blocksize;
+
+   if (offset + len > fsize) {
+   /*
+* Check if the filesystem supports the resulting
+* filesystem size.
+*/
+   VATTR_NULL();
+   va.va_size = offset + len;
+   if ((error = VOP_SETATTR(vp, , p->p_ucred, p)) != 0)
+   return (error);
+
+   /* 

Re: Purge route entries when an address is removed

2015-09-13 Thread Alexander Bluhm
On Sun, Sep 13, 2015 at 11:15:50AM +0200, Martin Pieuchot wrote:
> This makes the kernel simpler as it no longer try to find a new ifa
> when a route with a stale address is being used.

This makes the code simpler, which is good.

I am still not convinced that we want to loose the feature that the
routes jump to another interface address.  When we have multiple
suiteable addresses and one gets deleted, the system can use another
one.

> Tests and oks welcome.

The patch itself looks correct.  Just one question:

> @@ -850,22 +850,10 @@ rtrequest1(int req, struct rt_addrinfo *
>   return (EINVAL);
>   if ((rt->rt_flags & RTF_CLONING) == 0)
>   return (EINVAL);
> - if (rt->rt_ifa->ifa_ifp) {
> - info->rti_ifa = rt->rt_ifa;
> - } else {
> - /*
> -  * The address of the cloning route is not longer
> -  * configured on an interface, but its descriptor
> -  * is still there because of reference counting.
> -  *
> -  * Try to find a similar active address and use
> -  * it for the cloned route.  The cloning route
> -  * will get the new address and interface later.
> -  */
> - info->rti_ifa = NULL;
> - info->rti_info[RTAX_IFA] = rt->rt_ifa->ifa_addr;
> - }
> + if (rt->rt_ifa->ifa_ifp == NULL)
> + return (EAGAIN);

Why return EAGAIN here?  Should it be EINVAL like in the other
cases?  Can this happen at all?

bluhm



Condense fluffy comments in pax

2015-09-13 Thread Michael McConville
Index: options.c
===
RCS file: /cvs/src/bin/pax/options.c,v
retrieving revision 1.91
diff -u -p -r1.91 options.c
--- options.c   18 May 2015 20:26:16 -  1.91
+++ options.c   11 Sep 2015 00:12:19 -
@@ -668,9 +668,7 @@ tar_options(int argc, char **argv)
"b:cef:hjmopqruts:vwxzBC:HI:LNOPXZ014578")) != -1) {
switch (c) {
case 'b':
-   /*
-* specify blocksize in 512-byte blocks
-*/
+   /* specify blocksize in 512-byte blocks */
if ((wrblksz = (int)str_offt(optarg)) <= 0) {
paxwarn(1, "Invalid block size %s", optarg);
tar_usage();
@@ -678,25 +676,17 @@ tar_options(int argc, char **argv)
wrblksz *= 512; /* XXX - check for int oflow */
break;
case 'c':
-   /*
-* create an archive
-*/
+   /* create an archive */
act = ARCHIVE;
break;
case 'e':
-   /*
-* stop after first error
-*/
+   /* stop after first error */
maxflt = 0;
break;
case 'f':
-   /*
-* filename where the archive is stored
-*/
+   /* filename where the archive is stored */
if ((optarg[0] == '-') && (optarg[1]== '\0')) {
-   /*
-* treat a - as stdin
-*/
+   /* treat a - as stdin */
fstdin = 1;
arcname = NULL;
break;
@@ -705,21 +695,15 @@ tar_options(int argc, char **argv)
arcname = optarg;
break;
case 'h':
-   /*
-* follow symlinks
-*/
+   /* follow symlinks */
Lflag = 1;
break;
case 'j':
-   /*
-* use bzip2.  Non standard option.
-*/
+   /* use bzip2.  Non standard option. */
gzip_program = BZIP2_CMD;
break;
case 'm':
-   /*
-* do not preserve modification time
-*/
+   /* do not preserve modification time */
pmtime = 0;
break;
case 'O':
@@ -730,79 +714,56 @@ tar_options(int argc, char **argv)
tar_nodir = 1;
break;
case 'p':
-   /*
-* preserve uid/gid and file mode, regardless of umask
-*/
+   /* preserve uid/gid and file mode, regardless of umask 
*/
pmode = 1;
pids = 1;
break;
case 'q':
-   /*
-* select first match for a pattern only
-*/
+   /* select first match for a pattern only */
nflag = 1;
break;
case 'r':
case 'u':
-   /*
-* append to the archive
-*/
+   /* append to the archive */
act = APPND;
break;
case 's':
-   /*
-* file name substitution name pattern
-*/
+   /* file name substitution name pattern */
if (rep_add(optarg) < 0) {
tar_usage();
break;
}
break;
case 't':
-   /*
-* list contents of the tape
-*/
+   /* list contents of the tape */
act = LIST;
break;
case 'v':
-   /*
-* verbose operation mode
-*/
+   /* verbose operation mode */
vflag++;
break;
case 'w':
-   

Fix error reporting in ksh's csh-history

2015-09-13 Thread Michael McConville
ksh offers csh-style history aliases when you set csh-history. This
feature currently works. However, when an alias doesn't exist ksh
reports only the last digit (thanks to Theo for tipping me off on this):

> mike:/tmp/tech:1$ set -o csh-history
> mike:/tmp/tech:2$ ls
> a  b  c
> mike:/tmp/tech:3$ !2
> a  b  c
> mike:/tmp/tech:4$ !3456789
> ksh: !9: not found

The below diff fixes this. Basically, this feature is implemented in the
lexer, and ksh doesn't rewind through the whole alias after realizing
that it doesn't exist.

I don't entirely understand the lexer, so I did this super defensively.
If anyone knows of a smarter way, please share.

I moved the var declarations farther out because they're now needed in
the outer scope.


Index: lex.c
===
RCS file: /cvs/src/bin/ksh/lex.c,v
retrieving revision 1.51
diff -u -p -r1.51 lex.c
--- lex.c   10 Sep 2015 22:48:58 -  1.51
+++ lex.c   13 Sep 2015 20:44:30 -
@@ -163,6 +163,9 @@ yylex(int cf)
if (Flag(FCSHHISTORY) && (source->flags & SF_TTY) &&
c == '!') {
char **replace = NULL;
+   int get, i;
+   char match[200], *str = match;
+   size_t mlen;
 
c2 = getsc();
if (c2 == '\0' || c2 == ' ' || c2 == '\t')
@@ -171,8 +174,7 @@ yylex(int cf)
replace = hist_get_newest(0);
else if (isdigit(c2) || c2 == '-' ||
isalpha(c2)) {
-   int get = !isalpha(c2);
-   char match[200], *str = match;
+   get = !isalpha(c2);
 
*str++ = c2;
do {
@@ -216,8 +218,20 @@ yylex(int cf)
s->u.freeme = NULL;
source = s;
continue;
-   } else
-   ungetsc(c2);
+   } else {
+   /*
+* We do this the robust, safe, stupid 
way. We
+* should just be able to use:
+*
+* source->str = MAX(source->start,
+* source->str - (strlen(match)-1));
+*/
+   mlen = strlen(match);
+   if (source->start <= (source->str - 
mlen)) {
+   for (i = mlen-1; i >= 0; i--)
+   ungetsc(match[i]);
+   }
+   }
}
if (c == '[' && (cf & (VARASN|ARRAYVAR))) {
*wp = EOS; /* temporary */



Re: IPv6 transport for pflow(4)

2015-09-13 Thread Florian Obser
On Sun, Sep 13, 2015 at 03:25:16PM +, Florian Obser wrote:
> I don't really like to store struct sockaddr_storage since it's so
> big. I played around with a union like pf does, but looked
> complicated.
> Thoughts?
> 
> Also with this you can specify a source port.
> Since I was touching all those lines anyway I renamed sender to
> flowsrc and receiver to flowdst like the ifconfig keywords. I found
> the names of these struct members always confusing.
> Test, comments, OKs?
> 

second version, now uses a pointer to struct sockaddr + malloc of the
correct size.

diff --git sbin/ifconfig/ifconfig.8 sbin/ifconfig/ifconfig.8
index 85244d3..b3851aa 100644
--- sbin/ifconfig/ifconfig.8
+++ sbin/ifconfig/ifconfig.8
@@ -1277,7 +1277,7 @@ network.
 .Nm ifconfig
 .Ar pflow-interface
 .Op Oo Fl Oc Ns Cm flowdst Ar addr : Ns Ar port
-.Op Oo Fl Oc Ns Cm flowsrc Ar addr
+.Op Oo Fl Oc Ns Cm flowsrc Ar addr Oo : Ns Ar port Oc
 .Op Cm pflowproto Ar n
 .Ek
 .nr nS 0
@@ -1298,7 +1298,7 @@ is the port number of the flow collector.
 Pflow data will be sent to this address/port.
 .It Fl flowdst
 Unset the receiver address and stop sending pflow data.
-.It Cm flowsrc Ar addr
+.It Cm flowsrc Ar addr Oo : Ns Ar port Oc
 Set the source IP address for pflow packets.
 .Ar addr
 is the IP address used as sender of the UDP packets and may be used to
diff --git sbin/ifconfig/ifconfig.c sbin/ifconfig/ifconfig.c
index 63f6956..bee5dc2 100644
--- sbin/ifconfig/ifconfig.c
+++ sbin/ifconfig/ifconfig.c
@@ -265,6 +265,7 @@ voidsetifpowersave(const char *, int);
 void   setifmetric(const char *, int);
 void   notrailers(const char *, int);
 void   pflow_status(void);
+void   pflow_addr(const char*, struct sockaddr_storage *);
 void   setpflow_sender(const char *, int);
 void   unsetpflow_sender(const char *, int);
 void   setpflow_receiver(const char *, int);
@@ -4280,7 +4281,11 @@ pfsync_status(void)
 void
 pflow_status(void)
 {
-   struct pflowreq preq;
+   struct pflowreq  preq;
+   struct sockaddr_in  *sin;
+   struct sockaddr_in6 *sin6;
+   int  error;
+   char buf[INET6_ADDRSTRLEN];
 
bzero(, sizeof(struct pflowreq));
ifr.ifr_data = (caddr_t)
@@ -4288,47 +4293,135 @@ pflow_status(void)
if (ioctl(s, SIOCGETPFLOW, (caddr_t)) == -1)
 return;
 
+   if (preq.flowsrc.ss_family == AF_INET || preq.flowsrc.ss_family ==
+   AF_INET6) {
+   error = getnameinfo((struct sockaddr*),
+   preq.flowsrc.ss_len, buf, sizeof(buf), NULL, 0,
+   NI_NUMERICHOST);
+   if (error)
+   err(1, "sender: %s", gai_strerror(error));
+   }
+
printf("\tpflow: ");
-   if (preq.sender_ip.s_addr != INADDR_ANY)
-   printf("sender: %s ", inet_ntoa(preq.sender_ip));
-   printf("receiver: %s:", preq.receiver_ip.s_addr != INADDR_ANY ?
-   inet_ntoa(preq.receiver_ip) : "INVALID");
-   if (preq.receiver_port == 0)
-   printf("%s ", "INVALID");
-   else
-   printf("%u ", ntohs(preq.receiver_port));
+   switch (preq.flowsrc.ss_family) {
+   case AF_INET:
+   sin = (struct sockaddr_in*) 
+   if (sin->sin_addr.s_addr != INADDR_ANY) {
+   printf("sender: %s", buf);
+   if (sin->sin_port != 0)
+   printf(":%u", ntohs(sin->sin_port));
+   printf(" ");
+   }
+   break;
+   case AF_INET6:
+   sin6 = (struct sockaddr_in6*) 
+   if (!IN6_IS_ADDR_UNSPECIFIED(>sin6_addr)) {
+   printf("sender: [%s]", buf);
+   if (sin6->sin6_port != 0)
+   printf(":%u", ntohs(sin6->sin6_port));
+   printf(" ");
+   }
+   default:
+   break;
+   }
+   if (preq.flowdst.ss_family == AF_INET || preq.flowdst.ss_family ==
+   AF_INET6) {
+   error = getnameinfo((struct sockaddr*),
+   preq.flowdst.ss_len, buf, sizeof(buf), NULL, 0,
+   NI_NUMERICHOST);
+   if (error)
+   err(1, "receiver: %s", gai_strerror(error));
+   }
+   switch (preq.flowdst.ss_family) {
+   case AF_INET:
+   sin = (struct sockaddr_in*)
+   printf("receiver: %s:", sin->sin_addr.s_addr != INADDR_ANY ?
+   buf : "INVALID");   
+   if (sin->sin_port == 0)
+   printf("%s ", "INVALID");
+   else
+   printf("%u ", ntohs(sin->sin_port));
+   break;
+   case AF_INET6:
+   sin6 = (struct sockaddr_in6*) 
+   printf("receiver: [%s]:",
+   !IN6_IS_ADDR_UNSPECIFIED(>sin6_addr) ? buf :
+   "INVALID"); 
+ 

[WIP PATCH] SR RAID1 checksumming support V3

2015-09-13 Thread Karel Gardas
Hello,

attached is my work in progress on checksumming support for softraid
RAID1. Currently it does:
- computation of checksums (crc32)
- verification of checksums
- hang-over to another chunk (restart wu) in case of checksum error
- properly handle errors happening on all chunks
- "self-healing" of bad sector
- supports rebuild
- signal bad checksum to console and to sensors

E.g.:
$ sysctl hw.sensors.softraid0
hw.sensors.softraid0.raw0=0 (sd0f), OK
hw.sensors.softraid0.raw1=0 (sd0g), OK
hw.sensors.softraid0.drive0=
online (sd1), OK


Next TODO items:
- fix openings, currently it suggests max 2 wus are used per I/O, but
this changed with healing where the max number is 3 wus for case of
failed read (read, healing read, healing write)
- I really do not like current state (either in this patch or in
OpenBSD current) of handling of dependent wus. I will probably add
something like:
  sr_schedule_depwus(struct sr_workunit *wu, struct sr_workunit *depwu);
which will be hopefully more clear and ends few different ways how to
do dependent wus in the SR RAID code.
- fix RAID5/6 wus dependency handling (see above item)

With the above tasks done I hope the patch will be complete. Another
big TODO, but not for this patch (series) is to add proper scrub
support since RAID1C will benefit from it a lot.
But this is task really for the future as this patch is already quite
big and I'd like to have it merged first (if possible in one form or
another).

Note: checksums are computed per sector basis, saved in the area
allocated at the end of the drive. Due to this design,
LBA collision detection in softraid.c was enhanced/fixed to support
also this case of application
and currently it may not be compatible with RAID5/6 usage.

Any comments welcome!

Thanks!
Karel

PS: sorry for not inlining the patch, gmail/firefox has frozen 3 times
on it so I've given up this time and just attached that.
? .cvsignore
Index: sbin/bioctl/bioctl.8
===
RCS file: /cvs/src/sbin/bioctl/bioctl.8,v
retrieving revision 1.96
diff -u -p -u -r1.96 bioctl.8
--- sbin/bioctl/bioctl.829 May 2015 00:33:37 -  1.96
+++ sbin/bioctl/bioctl.813 Sep 2015 20:40:28 -
@@ -199,6 +199,11 @@ for example, force the creation of volum
 with unclean data in the metadata areas.
 .It Ar noauto
 Do not automatically assemble this volume at boot time.
+.It Ar chksum
+Enforce usage of checksums on the device blocks. The checksum area is
+located at the end of the device data area and since it occupies some
+space it makes actual usable device size smaller. We need exactly 8
+bytes of checksum per device data block.
 .El
 .It Fl c Ar raidlevel
 Create a
Index: sbin/bioctl/bioctl.c
===
RCS file: /cvs/src/sbin/bioctl/bioctl.c,v
retrieving revision 1.129
diff -u -p -u -r1.129 bioctl.c
--- sbin/bioctl/bioctl.c18 Jul 2015 23:23:20 -  1.129
+++ sbin/bioctl/bioctl.c13 Sep 2015 20:40:29 -
@@ -1053,6 +1053,9 @@ bio_createflags(char *lst)
case 'n':
flags |= BIOC_SCNOAUTOASSEMBLE;
break;
+   case 'c':
+   flags |= BIOC_SCCHKSUM;
+   break;
default:
strlcpy(fs, s, sz + 1);
errx(1, "invalid flag %s", fs);
Index: sys/dev/biovar.h
===
RCS file: /cvs/src/sys/dev/biovar.h,v
retrieving revision 1.44
diff -u -p -u -r1.44 biovar.h
--- sys/dev/biovar.h29 May 2015 00:33:37 -  1.44
+++ sys/dev/biovar.h13 Sep 2015 20:40:29 -
@@ -213,6 +213,7 @@ struct bioc_createraid {
 #define BIOC_SCDEVT0x02/* dev_t array or string in dev_list */
 #define BIOC_SCNOAUTOASSEMBLE  0x04/* do not assemble during autoconf */
 #define BIOC_SCBOOTABLE0x08/* device is bootable */
+#define BIOC_SCCHKSUM  0x10/* device provides chksum capability */
u_int32_t   bc_opaque_size;
u_int32_t   bc_opaque_flags;
 #defineBIOC_SOINVALID  0x00/* no opaque pointer */
Index: sys/dev/softraid.c
===
RCS file: /cvs/src/sys/dev/softraid.c,v
retrieving revision 1.364
diff -u -p -u -r1.364 softraid.c
--- sys/dev/softraid.c  19 Aug 2015 19:05:24 -  1.364
+++ sys/dev/softraid.c  13 Sep 2015 20:40:30 -
@@ -71,6 +71,7 @@ uint32_t  sr_debug = 0
/* | SR_D_DIS */
/* | SR_D_STATE */
/* | SR_D_REBUILD */
+   /* | SR_D_CHKSUM  */
;
 #endif
 
@@ -144,6 +145,8 @@ int sr_chunk_in_use(struct sr_softc *,
 intsr_rw(struct sr_softc *, dev_t, char *, 

Re: lpd: move hosts.lpd parsing into lpd proper

2015-09-13 Thread Todd C. Miller
On Sun, 13 Sep 2015 09:25:19 -0600, "Todd C. Miller" wrote:

> This should allow us to stop exporting __ivaliduser and __ivaliduser_sa
> from libc and to eventually remove ruserok from libc entirely.
> 
> Needs testing by someone who actually runs lpd...

Newer version that is easy to test separately from lpd.

 - todd

Index: usr.sbin/lpr/lpd/Makefile
===
RCS file: /cvs/src/usr.sbin/lpr/lpd/Makefile,v
retrieving revision 1.5
diff -u -p -u -r1.5 Makefile
--- usr.sbin/lpr/lpd/Makefile   10 Dec 2013 16:38:04 -  1.5
+++ usr.sbin/lpr/lpd/Makefile   13 Sep 2015 15:21:13 -
@@ -5,7 +5,7 @@ PROG=   lpd
 CFLAGS+=-I${.CURDIR}/../common_source
 MAN=   lpd.8
 SRCS=  lpd.c printjob.c recvjob.c displayq.c rmjob.c startdaemon.c \
-   lpdchar.c common.c key.c modes.c common_vars.c
+   lpdchar.c common.c key.c modes.c common_vars.c allowedhost.c
 BINGRP=daemon
 BINMODE=2550
 .PATH: ${.CURDIR}/../common_source
Index: usr.sbin/lpr/lpd/allowedhost.c
===
RCS file: usr.sbin/lpr/lpd/allowedhost.c
diff -N usr.sbin/lpr/lpd/allowedhost.c
--- /dev/null   1 Jan 1970 00:00:00 -
+++ usr.sbin/lpr/lpd/allowedhost.c  14 Sep 2015 01:42:02 -
@@ -0,0 +1,260 @@
+/*
+ * Copyright (c) 1995, 1996, 1998 Theo de Raadt.  All rights reserved.
+ * Copyright (c) 1983, 1993, 1994
+ * The Regents of the University of California.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *notice, this list of conditions and the following disclaimer in the
+ *documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ *may be used to endorse or promote products derived from this software
+ *without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include 
+#include 
+
+#include 
+#include 
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+static int checkhost(struct sockaddr *, socklen_t, const char *);
+static char *gethostloop(struct sockaddr *, socklen_t);
+
+/*
+ * Check whether the specified addr is listed in hostf.
+ * Returns 0 if ok, -1 if not ok.
+ */
+int
+allowedhost(FILE *hostf, struct sockaddr *raddr, socklen_t salen)
+{
+   char *buf, *cp, *ep;
+   char *rhost = (char *)-1;
+   char host[HOST_NAME_MAX+1], domain[HOST_NAME_MAX+1];
+   size_t buflen;
+   int hostok;
+
+   getdomainname(domain, sizeof(domain));
+
+   while ((buf = fgetln(hostf, ))) {
+   cp = buf;
+   ep = buf + buflen;
+   if (*cp == '#')
+   continue;
+   while (cp < ep && !isspace((unsigned char)*cp)) {
+   if (!isprint((unsigned char)*cp))
+   goto bail;
+   *cp = isupper((unsigned char)*cp) ?
+   tolower((unsigned char)*cp) : *cp;
+   cp++;
+   }
+   if (cp == buf)
+   continue;
+
+   /* Ignore anything after whitespace. */
+   buflen = (size_t)(cp - buf);
+   if (buflen > HOST_NAME_MAX)
+   continue;
+   memcpy(host, buf, buflen);
+   host[buflen] = '\0';
+
+   /*
+* innetgr() must lookup a hostname (we do not attempt
+* to change the semantics so that netgroups may have
+* #.#.#.# addresses in the list.)
+*/
+   switch (host[0]) {
+   case '+':
+   case '-':
+   switch (host[1]) {
+   case '\0':
+   hostok = 1;
+  

Remove unused vars from if_urtwn.c

2015-09-13 Thread Michael McConville
Index: if_urtwn.c
===
RCS file: /cvs/src/sys/dev/usb/if_urtwn.c,v
retrieving revision 1.51
diff -u -p -r1.51 if_urtwn.c
--- if_urtwn.c  10 Sep 2015 11:53:05 -  1.51
+++ if_urtwn.c  13 Sep 2015 21:30:32 -
@@ -2713,7 +2713,7 @@ urtwn_r88e_dma_init(struct urtwn_softc *
 {
usb_interface_descriptor_t  *id;
uint32_t reg;
-   int nrempages, nqpages, nqueues = 1;
+   int nqueues = 1;
int error;
 
/* Initialize LLT table. */
@@ -2724,11 +2724,6 @@ urtwn_r88e_dma_init(struct urtwn_softc *
/* Get Tx queues to USB endpoints mapping. */
id = usbd_get_interface_descriptor(sc->sc_iface);
nqueues = id->bNumEndpoints - 1;
-
-   /* Get the number of pages for each queue. */
-   nqpages = (R92C_TX_PAGE_COUNT - R92C_PUBQ_NPAGES) / nqueues;
-   /* The remaining pages are assigned to the high priority queue. */
-   nrempages = (R92C_TX_PAGE_COUNT - R92C_PUBQ_NPAGES) % nqueues;
 
/* Set number of pages for normal priority queue. */
urtwn_write_2(sc, R92C_RQPN_NPQ, 0x000d);



Brainy: a few bugs

2015-09-13 Thread Maxime Villard
Got some time tonight; nothing new, just emptying my list:

http://m00nbsd.net/e5ab5f6e59d6a0feb7d1a518acc8233d.html#Unsorted-2

Summary:

_17/ UNINITIALIZED VARIABLE: sys/netinet/if_ether.c rev1.165
_18/ UNINITIALIZED VARIABLE: sys/net80211/ieee80211_pae_output.c rev1.20
_19/ UNINITIALIZED VARIABLE: sys/arch/i386/i386/bios.c rev1.112
_20/ UNINITIALIZED VARIABLE: sys/arch/sgi/dev/if_iec.c rev1.14
_21/ UNINITIALIZED VARIABLE: sys/arch/armv7/omap/ti_iic.c rev1.2
_22/ OVERLAP: sys/arch/sparc64/dev/vdsp.c rev1.2
_23/ USE-AFTER-FREE: sys/dev/sun/z8530ms.c rev1.2
_24/ MEMORY LEAK: sys/dev/ic/oosiop.c rev1.22

Found by Brainy.

Maxime



Re: Brainy: a few bugs

2015-09-13 Thread Claudio Jeker
On Fri, Sep 11, 2015 at 09:18:18PM +0200, Maxime Villard wrote:
> Got some time tonight; nothing new, just emptying my list:
> 
>   http://m00nbsd.net/e5ab5f6e59d6a0feb7d1a518acc8233d.html#Unsorted-2
> 
> Summary:
> 
> _17/ UNINITIALIZED VARIABLE: sys/netinet/if_ether.c rev1.165
> _18/ UNINITIALIZED VARIABLE: sys/net80211/ieee80211_pae_output.c rev1.20
> _19/ UNINITIALIZED VARIABLE: sys/arch/i386/i386/bios.c rev1.112
> _20/ UNINITIALIZED VARIABLE: sys/arch/sgi/dev/if_iec.c rev1.14
> _21/ UNINITIALIZED VARIABLE: sys/arch/armv7/omap/ti_iic.c rev1.2
> _22/ OVERLAP: sys/arch/sparc64/dev/vdsp.c rev1.2
> _23/ USE-AFTER-FREE: sys/dev/sun/z8530ms.c rev1.2
> _24/ MEMORY LEAK: sys/dev/ic/oosiop.c rev1.22
> 

Fix for _17

-- 
:wq Claudio

Index: netinet/if_ether.c
===
RCS file: /cvs/src/sys/netinet/if_ether.c,v
retrieving revision 1.168
diff -u -p -r1.168 if_ether.c
--- netinet/if_ether.c  13 Sep 2015 17:53:44 -  1.168
+++ netinet/if_ether.c  14 Sep 2015 04:42:08 -
@@ -367,10 +367,11 @@ arpresolve(struct ifnet *ifp, struct rte
"local address\n", __func__, inet_ntop(AF_INET,
(dst)->sin_addr, addr, sizeof(addr)));
} else {
+   la = NULL;
if ((rt = arplookup(satosin(dst)->sin_addr.s_addr, 1, 0,
ifp->if_rdomain)) != NULL)
la = ((struct llinfo_arp *)rt->rt_llinfo);
-   else
+   if (la == NULL)
log(LOG_DEBUG, "%s: %s: can't allocate llinfo\n",
__func__,
inet_ntop(AF_INET, (dst)->sin_addr,