explicitly check broadcast addresses on some ifa_ifwithaddr() uses

2015-12-02 Thread Vincent Gross
When fed a broadcast address, ifa_ifwitaddr() returns the unicast ifa
whose broadcast address match the input. This is used mainly to select
ifa, and there can be trouble when you have 2 ifas on the same range
(e.g. 10.0.0.1/24@em0 & 10.0.0.20/24@em1) :

netinet/ip_mroute.c:814
net/route.c:785
netinet/ip_divert.c:143
net/if_vxlan.c:241

There are also places where broadcast addresses should not be tolerated :

netinet/ip_input.c:1061  broadcast address is not a module identifier
netinet/ip_input.c:1141  see above
netinet/ip_input.c:1197  see above
netinet6/*:  no broadcast in ipv6
net/route.c:562: gateway shall never be a broadcast addr
net/route.c:713: see above

This diff removes broadcast matching from ifa_ifwithaddr, and
adds or rewrites checks where necessary.

Comments ? Ok ?

Index: sys/net/if.c
===
RCS file: /cvs/src/sys/net/if.c,v
retrieving revision 1.416
diff -u -p -r1.416 if.c
--- sys/net/if.c2 Dec 2015 08:47:00 -   1.416
+++ sys/net/if.c2 Dec 2015 15:17:26 -
@@ -1178,13 +1178,6 @@ ifa_ifwithaddr(struct sockaddr *addr, u_
 
if (equal(addr, ifa->ifa_addr))
return (ifa);
-
-   /* IPv6 doesn't have broadcast */
-   if ((ifp->if_flags & IFF_BROADCAST) &&
-   ifa->ifa_broadaddr &&
-   ifa->ifa_broadaddr->sa_len != 0 &&
-   equal(ifa->ifa_broadaddr, addr))
-   return (ifa);
}
}
return (NULL);
Index: sys/netinet/in_pcb.c
===
RCS file: /cvs/src/sys/netinet/in_pcb.c,v
retrieving revision 1.188
diff -u -p -r1.188 in_pcb.c
--- sys/netinet/in_pcb.c30 Oct 2015 09:39:42 -  1.188
+++ sys/netinet/in_pcb.c2 Dec 2015 15:17:26 -
@@ -328,14 +328,12 @@ in_pcbbind(struct inpcb *inp, struct mbu
 
ia = ifatoia(ifa_ifwithaddr(sintosa(sin),
inp->inp_rtableid));
-   if (ia == NULL)
-   return (EADDRNOTAVAIL);
 
/* SOCK_RAW does not use in_pcbbind() */
-   if (so->so_type != SOCK_DGRAM &&
-   sin->sin_addr.s_addr !=
-   ia->ia_addr.sin_addr.s_addr)
-   return (EADDRNOTAVAIL);
+   if (ia == NULL &&
+   (so->so_type != SOCK_DGRAM ||
+   !in_broadcast(sin->sin_addr, 
inp->inp_rtableid)))
+   return (EADDRNOTAVAIL);
}
}
if (lport) {
Index: sys/netinet/ip_output.c
===
RCS file: /cvs/src/sys/netinet/ip_output.c,v
retrieving revision 1.310
diff -u -p -r1.310 ip_output.c
--- sys/netinet/ip_output.c 2 Dec 2015 13:29:26 -   1.310
+++ sys/netinet/ip_output.c 2 Dec 2015 15:17:27 -
@@ -1387,9 +1387,8 @@ ip_setmoptions(int optname, struct ip_mo
sin.sin_family = AF_INET;
sin.sin_addr = addr;
ia = ifatoia(ifa_ifwithaddr(sintosa(), rtableid));
-   if (ia && in_hosteq(sin.sin_addr, ia->ia_addr.sin_addr))
-   ifp = ia->ia_ifp;
-   if (ifp == NULL || (ifp->if_flags & IFF_MULTICAST) == 0) {
+   if (ia == NULL || (ifp = ia->ia_ifp) == NULL ||
+   (ia->ia_ifp->if_flags & IFF_MULTICAST) == 0) {
error = EADDRNOTAVAIL;
break;
}
@@ -1561,12 +1560,11 @@ ip_setmoptions(int optname, struct ip_mo
sin.sin_family = AF_INET;
sin.sin_addr = mreq->imr_interface;
ia = ifatoia(ifa_ifwithaddr(sintosa(), rtableid));
-   if (ia && in_hosteq(sin.sin_addr, ia->ia_addr.sin_addr))
-   ifp = ia->ia_ifp;
-   else {
+   if (ia == NULL) {
error = EADDRNOTAVAIL;
break;
}
+   ifp = ia->ia_ifp;
}
/*
 * Find the membership in the membership array.
Index: sys/netinet/raw_ip.c
===
RCS file: /cvs/src/sys/netinet/raw_ip.c,v
retrieving revision 1.84
diff -u -p -r1.84 raw_ip.c
--- sys/netinet/raw_ip.c28 Jul 2015 12:22:07 -  1.84
+++ sys/netinet/raw_ip.c2 Dec 2015 15:17:27 -
@@ -473,6 +473,7 @@ 

pf statekey inp chaining

2015-12-02 Thread Alexander Bluhm
Hi,

To avoid that the stack manipules the pf statekeys directly, introduce
some pf_inp_...() functions as an interface.  Locks can be added
to them later.

I have removed the first chaining at the beginning of tcp_input()
and udp_input() directly after in_pcbhashlookup() as it is not
necessary.  It will be done later anyway.  That code was a relict,
from the time before I had added the second chaining.

sashan@ is working at the pf_unlink_state() loop in in_pcbdetach()
so I have not moved that yet.

ok?

bluhm

Index: net/pf.c
===
RCS file: /data/mirror/openbsd/cvs/src/sys/net/pf.c,v
retrieving revision 1.952
diff -u -p -r1.952 pf.c
--- net/pf.c21 Nov 2015 11:29:40 -  1.952
+++ net/pf.c2 Dec 2015 15:25:29 -
@@ -6714,6 +6714,44 @@ pf_pkt_addr_changed(struct mbuf *m)
m->m_pkthdr.pf.inp = NULL;
 }
 
+struct inpcb *
+pf_inp_lookup(struct mbuf *m) {
+   struct inpcb *inp = NULL;
+
+   if (m->m_pkthdr.pf.statekey) {
+   inp = m->m_pkthdr.pf.statekey->inp;
+   if (inp && inp->inp_pf_sk)
+   KASSERT(m->m_pkthdr.pf.statekey == inp->inp_pf_sk);
+   }
+   return (inp);
+}
+
+void
+pf_inp_enter(struct mbuf *m, struct inpcb *inp) {
+   if (inp->inp_socket->so_state & SS_ISCONNECTED)
+   m->m_pkthdr.pf.inp = inp;
+}
+
+void
+pf_inp_chain(struct mbuf *m, struct inpcb *inp) {
+   if (m->m_pkthdr.pf.statekey && inp &&
+   !m->m_pkthdr.pf.statekey->inp && !inp->inp_pf_sk &&
+   (inp->inp_socket->so_state & SS_ISCONNECTED)) {
+   m->m_pkthdr.pf.statekey->inp = inp;
+   inp->inp_pf_sk = m->m_pkthdr.pf.statekey;
+   }
+   /* The statekey has finished finding the inp, it is no longer needed. */
+   m->m_pkthdr.pf.statekey = NULL;
+}
+
+void
+pf_inp_unchain(struct inpcb *inp) {
+   if (inp->inp_pf_sk) {
+   inp->inp_pf_sk->inp = NULL;
+   inp->inp_pf_sk = NULL;
+   }
+}
+
 #if NPFLOG > 0
 void
 pf_log_matches(struct pf_pdesc *pd, struct pf_rule *rm, struct pf_rule *am,
Index: net/pfvar.h
===
RCS file: /data/mirror/openbsd/cvs/src/sys/net/pfvar.h,v
retrieving revision 1.423
diff -u -p -r1.423 pfvar.h
--- net/pfvar.h 20 Nov 2015 03:35:23 -  1.423
+++ net/pfvar.h 2 Dec 2015 15:35:58 -
@@ -1753,6 +1753,10 @@ int  pf_rtlabel_match(struct pf_addr *, s
 intpf_socket_lookup(struct pf_pdesc *);
 struct pf_state_key *pf_alloc_state_key(int);
 void   pf_pkt_addr_changed(struct mbuf *);
+struct inpcb *pf_inp_lookup(struct mbuf *);
+void   pf_inp_enter(struct mbuf *, struct inpcb *);
+void   pf_inp_chain(struct mbuf *, struct inpcb *);
+void   pf_inp_unchain(struct inpcb *);
 intpf_state_key_attach(struct pf_state_key *, struct pf_state *, int);
 intpf_translate(struct pf_pdesc *, struct pf_addr *, u_int16_t,
struct pf_addr *, u_int16_t, u_int16_t, int);
Index: netinet/in_pcb.c
===
RCS file: /data/mirror/openbsd/cvs/src/sys/netinet/in_pcb.c,v
retrieving revision 1.188
diff -u -p -r1.188 in_pcb.c
--- netinet/in_pcb.c30 Oct 2015 09:39:42 -  1.188
+++ netinet/in_pcb.c2 Dec 2015 15:30:25 -
@@ -518,8 +518,7 @@ in_pcbdetach(struct inpcb *inp)
break;
}
/* pf_unlink_state() may have detached the state */
-   if (inp->inp_pf_sk)
-   inp->inp_pf_sk->inp = NULL;
+   pf_inp_unchain(inp);
}
 #endif
s = splnet();
Index: netinet/tcp_input.c
===
RCS file: /data/mirror/openbsd/cvs/src/sys/netinet/tcp_input.c,v
retrieving revision 1.310
diff -u -p -r1.310 tcp_input.c
--- netinet/tcp_input.c 29 Nov 2015 15:09:32 -  1.310
+++ netinet/tcp_input.c 2 Dec 2015 15:25:40 -
@@ -580,11 +580,7 @@ tcp_input(struct mbuf *m, ...)
 * Locate pcb for segment.
 */
 #if NPF > 0
-   if (m->m_pkthdr.pf.statekey) {
-   inp = m->m_pkthdr.pf.statekey->inp;
-   if (inp && inp->inp_pf_sk)
-   KASSERT(m->m_pkthdr.pf.statekey == inp->inp_pf_sk);
-   }
+   inp = pf_inp_lookup(m);
 #endif
 findpcb:
if (inp == NULL) {
@@ -602,12 +598,6 @@ findpcb:
m->m_pkthdr.ph_rtableid);
break;
}
-#if NPF > 0
-   if (m->m_pkthdr.pf.statekey && inp) {
-   m->m_pkthdr.pf.statekey->inp = inp;
-   inp->inp_pf_sk = m->m_pkthdr.pf.statekey;
-   }
-#endif
}
if (inp == NULL) {
int inpl_reverse = 0;
@@ -880,13 +870,7 @@ findpcb:
 #endif
 
 #if NPF > 0
-   if (m->m_pkthdr.pf.statekey && !m->m_pkthdr.pf.statekey->inp &&
-  

ARM as: add .inst support

2015-12-02 Thread Tobias Ulmer
Add support for .inst 0xdeadbeef. Required to move forward with gcc 4.9

No GPLv3 license was violated during writing this trivial diff

ok?

Index: gnu/usr.bin/binutils-2.17/gas/config/tc-arm.c
===
RCS file: 
/home/vcs/cvs/openbsd/src/gnu/usr.bin/binutils-2.17/gas/config/tc-arm.c,v
retrieving revision 1.4
diff -u -p -r1.4 tc-arm.c
--- gnu/usr.bin/binutils-2.17/gas/config/tc-arm.c   13 Jun 2015 09:37:13 
-  1.4
+++ gnu/usr.bin/binutils-2.17/gas/config/tc-arm.c   2 Dec 2015 14:31:20 
-
@@ -1730,6 +1730,37 @@ s_syntax (int unused ATTRIBUTE_UNUSED)
   demand_empty_rest_of_line ();
 }
 
+static void
+s_inst(int unused ATTRIBUTE_UNUSED)
+{
+   expressionS exp;
+
+   if (thumb_mode) {
+   as_bad(".inst not implemented for Thumb mode");
+   ignore_rest_of_line();
+   return;
+   }
+
+   if (is_it_end_of_statement()) {
+   demand_empty_rest_of_line();
+   return;
+   }
+
+   do {
+   expression();
+
+   if (exp.X_op != O_constant)
+   as_bad("constant expression required");
+   else
+   emit_expr(, 4);
+
+   } while (*input_line_pointer++ == ',');
+
+   /* Put terminator back into stream. */
+   input_line_pointer--;
+   demand_empty_rest_of_line();
+}
+
 /* Directives: sectioning and alignment.  */
 
 /* Same as s_align_ptwo but align 0 => align 2. */
@@ -2985,6 +3016,7 @@ const pseudo_typeS md_pseudo_table[] =
   { "ltorg",  s_ltorg,   0 },
   { "pool",   s_ltorg,   0 },
   { "syntax", s_syntax,  0 },
+  { "inst",s_inst,0 },
 #ifdef OBJ_ELF
   { "word",   s_arm_elf_cons, 4 },
   { "long",   s_arm_elf_cons, 4 },



Re: rm bge supported devices

2015-12-02 Thread Alexander Salmin



On 2015-12-02 14:12, Reyk Floeter wrote:

n Wed, Dec 02, 2015 at 06:37:19AM -0500, Ted Unangst wrote:

>There are many other product lists, but starting with the two big broadcom
>flavors here. I've had a dozen machines with bge, but none of them were listed
>in the man page. I don't think these product lists are helpful.
>
>1. If you have a device and want to know if it's supported, there's no reverse
>mapping from product to driver. How do I know what driver supports my NC320m
>nic? It's faster to plug it in and find out than to read every ethernet man
>page looking for it. (And then plugging it in anyway after I don't find it
>because these lists are perpetually out of date.)
>
>2. If you have picked a driver and are trying to find a device, these are very
>incomplete guides. Most of the devices aren't for sale anymore. Many of the
>rest are now revision B or revision C and may or may not work.
>
>I think we are better off not maintaining such lists. We document the chip
>(family) supported by the driver. Consult the spec sheet if you want to know
>which chip is on your network card.
>
>There may be exceptional circumstances for some drivers, so I'm not planning to
>delete all the lists all at once, but deal with one family at a time.
>

The last time I used it was when I looked up if the "Intel X540-T2" is
an ix(4) - before I ordered it online.  It is listed in the manpage,
so I didn't bother asking other people or looking up the chipset.  And
it worked, of course.  I think it is convenient for the most common
devices and doesn't have to be a comprehensive list.

Reyk

I don't mind if this information is removed from the manual of the 
device driver but I do mind if this information is lost without being 
implemented somewhere else. Maybe it can be a list on the web FAQ 
somewhere if you don't want it there. I'd also be happy to help maintain 
that list of "known working hardware for driver X".


Alexander



Re: WAPBL: Adding the FFS capability to alloc files contiguously

2015-12-02 Thread Ted Unangst
Bob Beck wrote:
> On Fri, Nov 27, 2015 at 02:50:57PM -0200, Walter Neto wrote:
> 
> You have a number of places here where you introduce a line of 8 spaces
> after your #endif - please clean up the trailing spaces, they shouldn't be 
> there.
> 
> You also have uses of B_METAONLY that are not inside a #ifdef WAPBL in 
> ffs_balloc.c
> 
> The first one I mostly get - as we are only looking for the first indirect 
> block
> this makes sense.   the second usage I'm not sure is correct... is it?

> > @@ -670,10 +684,11 @@ ffs2_balloc(struct inode *ip, off_t off, int size, 
> > struct ucred *cred,
> > }
> >  
> > if (pref == 0)
> > -   pref = ffs2_blkpref(ip, lbn, i - num - 1, NULL);
> > +   pref = ffs2_blkpref(ip, lbn, i - num - 1,
> > +   flags | B_METAONLY, NULL);
> >  
> > -   error = ffs_alloc(ip, lbn, pref, (int) fs->fs_bsize, cred,
> > -   );
> > +   error = ffs_alloc(ip, lbn, pref, (int) fs->fs_bsize,
> > +   flags | B_METAONLY, cred, );

I'm ok with leaving this flag unguarded by ifdef. There's no functional change
if the code *testing* the flag is guarded. The less intrusive the changes to
code that doesn't really care, the better.



rm bonus inet6 option

2015-12-02 Thread Ted Unangst
We have a socket option guarded by ifdef _KERNEL that therefore cannot be used
by userland (nor used in kernel). No pcb code tests for the flag either.

Index: netinet/in_pcb.h
===
RCS file: /cvs/src/sys/netinet/in_pcb.h,v
retrieving revision 1.91
diff -u -p -r1.91 in_pcb.h
--- netinet/in_pcb.h24 Oct 2015 16:08:48 -  1.91
+++ netinet/in_pcb.h2 Dec 2015 17:48:17 -
@@ -196,7 +196,6 @@ struct inpcbtable {
 #define IN6P_HOPOPTS   0x04 /* receive hop-by-hop options */
 #define IN6P_DSTOPTS   0x08 /* receive dst options after rthdr */
 #define IN6P_RTHDR 0x10 /* receive routing header */
-#define IN6P_RTHDRDSTOPTS  0x20 /* receive dstoptions before rthdr */
 #define IN6P_TCLASS0x40 /* receive traffic class value */
 #define IN6P_AUTOFLOWLABEL 0x80 /* attach flowlabel automatically */
 
@@ -207,7 +206,7 @@ struct inpcbtable {
 #define IN6P_MINMTU0x2000 /* use minimum MTU */
 
 #define IN6P_CONTROLOPTS   (IN6P_PKTINFO|IN6P_HOPLIMIT|IN6P_HOPOPTS|\
-IN6P_DSTOPTS|IN6P_RTHDR|IN6P_RTHDRDSTOPTS|\
+IN6P_DSTOPTS|IN6P_RTHDR|\
 IN6P_TCLASS|IN6P_AUTOFLOWLABEL|IN6P_RFC2292|\
 IN6P_MTU|IN6P_RECVDSTPORT)
 
Index: netinet6/in6.h
===
RCS file: /cvs/src/sys/netinet6/in6.h,v
retrieving revision 1.86
diff -u -p -r1.86 in6.h
--- netinet6/in6.h  29 Oct 2015 16:04:10 -  1.86
+++ netinet6/in6.h  2 Dec 2015 17:47:02 -
@@ -315,9 +315,6 @@ struct route_in6 {
 #define IPV6_RECVRTHDR 38 /* bool; recv routing header */
 #define IPV6_RECVHOPOPTS   39 /* bool; recv hop-by-hop option */
 #define IPV6_RECVDSTOPTS   40 /* bool; recv dst option after rthdr */
-#ifdef _KERNEL
-#define IPV6_RECVRTHDRDSTOPTS  41 /* bool; recv dst option before rthdr */
-#endif
 
 #define IPV6_USE_MIN_MTU   42 /* bool; send packets at the minimum MTU */
 #define IPV6_RECVPATHMTU   43 /* bool; notify an according MTU */
Index: netinet6/ip6_output.c
===
RCS file: /cvs/src/sys/netinet6/ip6_output.c,v
retrieving revision 1.200
diff -u -p -r1.200 ip6_output.c
--- netinet6/ip6_output.c   29 Nov 2015 15:12:36 -  1.200
+++ netinet6/ip6_output.c   2 Dec 2015 17:47:34 -
@@ -1229,7 +1229,6 @@ ip6_ctloutput(int op, struct socket *so,
 */
case IPV6_RECVHOPOPTS:
case IPV6_RECVDSTOPTS:
-   case IPV6_RECVRTHDRDSTOPTS:
if (!privileged) {
error = EPERM;
break;
@@ -1299,10 +1298,6 @@ do { \
OPTSET(IN6P_DSTOPTS);
break;
 
-   case IPV6_RECVRTHDRDSTOPTS:
-   OPTSET(IN6P_RTHDRDSTOPTS);
-   break;
-
case IPV6_RECVRTHDR:
OPTSET(IN6P_RTHDR);
break;
@@ -1538,7 +1533,6 @@ do { \
 
case IPV6_RECVHOPOPTS:
case IPV6_RECVDSTOPTS:
-   case IPV6_RECVRTHDRDSTOPTS:
case IPV6_UNICAST_HOPS:
case IPV6_RECVPKTINFO:
case IPV6_RECVHOPLIMIT:
@@ -1558,10 +1552,6 @@ do { \
 
case IPV6_RECVDSTOPTS:
optval = OPTBIT(IN6P_DSTOPTS);
-   break;
-
-   case IPV6_RECVRTHDRDSTOPTS:
-   optval = OPTBIT(IN6P_RTHDRDSTOPTS);
break;
 
case IPV6_UNICAST_HOPS:



Re: WAPBL: Adding the FFS capability to alloc files contiguously

2015-12-02 Thread Ted Unangst
Walter Neto wrote:
> > You also have uses of B_METAONLY that are not inside a #ifdef WAPBL in 
> > ffs_balloc.c
> >
> 
> Yeah, but I don't know what is the best way to correct it.
> Should I use:
> #ifdef WAPBL
>   foo(..., flags | B_METAONLY, ...);
> #else
>   foo(..., flags, ...);
> #endif
> 
> or
> 
>   foo(..., flags
> #ifdef WAPBL
>   | B_METAONLY
> #endif
>   , ...)
> 
> ?

flags = B_ANANA;
#ifdef WAPBL
flags |= B_METAONLY;
#endif
foo(flags);



Re: rm bge supported devices

2015-12-02 Thread Theo de Raadt
> On 2015/12/02 12:09, jus...@postgresql.org wrote:
> > On 2015-12-02 11:37, Ted Unangst wrote:
> > >2. If you have picked a driver and are trying to find a device, these
> > >are very incomplete guides. Most of the devices aren't for sale anymore.
> > >Many of the rest are now revision B or revision C and may or may not work.
> 
> For those of us whose hardware procurement policy typically involves
> ebay, they can be quite useful, they are incomplete but there are loads
> of e.g. the HP nics available, and there are a lot fewer junk results if
> you can search for NC380T/NC382T than "dual port pci express gigabit"
> and have to sift through all the PCI-X ones that have been miscategorised.

I agree with Stuart.

When these lists include chip numbers, that is valuable.  Lists
containing names like Belkin RandomProduct may be less helpful, but
the case hasn't been proven the lists should be removed.



Re: rm bge supported devices

2015-12-02 Thread justin

On 2015-12-02 16:07, Alexander Salmin wrote:


I don't mind if this information is removed from the manual of the
device driver but I do mind if this information is lost without being
implemented somewhere else. Maybe it can be a list on the web FAQ
somewhere if you don't want it there. I'd also be happy to help
maintain that list of "known working hardware for driver X".


For this kind of thought, the hardware lists could be extracted from
each of the driver man pages, then turned into a "Hardware 
Compatibility

List".  eg:

  1GbE network cards
  **

  Model   Driver
  Intel I340-T2   em
  Intel I340-T4   em
  Intel I350-T2   em
  Intel I350-T4   em


  10GbE network cards
  ***

  Model   Driver
  Intel X350-T4   ix


  Wifi cards
  **

  Model   Driver
  A-Link WL54Hral
  AirLive WN-5000PCI  ral
  Amigo AWI-926W  ral
  AMIT WL531P ral
  AOpen AOI-831   ral
  ASUS WL-130Gral
  ASUS WL-130Nral
  ASUS WIFI-G-AAY ral


Having this info in one easy-to-search location sounds like it would
be even better for some use cases (eg people looking for hardware by
category, instead of by driver).

Thoughts? :)

Regards and best wishes,

Justin Clift



Re: WAPBL: Adding the FFS capability to alloc files contiguously

2015-12-02 Thread Walter Neto
On Sat, Nov 28, 2015 at 03:49:21PM -0700, Bob Beck wrote:
> On Fri, Nov 27, 2015 at 02:50:57PM -0200, Walter Neto wrote:
> 
> You have a number of places here where you introduce a line of 8 spaces
> after your #endif - please clean up the trailing spaces, they shouldn't be 
> there.
> 
Ok, cleaned :)

> You also have uses of B_METAONLY that are not inside a #ifdef WAPBL in 
> ffs_balloc.c
>

Yeah, but I don't know what is the best way to correct it.
Should I use:
#ifdef WAPBL
foo(..., flags | B_METAONLY, ...);
#else
foo(..., flags, ...);
#endif

or

foo(..., flags
#ifdef WAPBL
| B_METAONLY
#endif
, ...)

?

(Waiting this answer to send the fixed diff.

> The first one I mostly get - as we are only looking for the first indirect 
> block
> this makes sense.   the second usage I'm not sure is correct... is it?
> 

Yes Bob, It is correct! After many hours reading and re-reading the FFS
code (it is a dragon) I understood it better, and the socond makes sense
too cause it is where other data block is been allocated to store new
indirect data-blocks address, so it is a B_METAONLY data-block.

I don't know if I was clear, any doubts we can discuss.

> I would like some more FFS savvy eyes on this one and not just me. 
> (This is a large hint to some other people)
> 
> -Bob
> 
> 
> > After mpi@ review
> > 
> > --
> > Walter Neto
> > 
> > diff --git a/sys/sys/buf.h b/sys/sys/buf.h
> > index c47f3f9..fd38c28 100644
> > --- a/sys/sys/buf.h
> > +++ b/sys/sys/buf.h
> > @@ -254,6 +254,8 @@ struct cluster_save {
> >  /* Flags to low-level allocation routines. */
> >  #define B_CLRBUF   0x01/* Request allocated buffer be cleared. */
> >  #define B_SYNC 0x02/* Do all allocations synchronously. */
> > +#define B_METAONLY 0x04/* return indirect block buffer */
> > +#define B_CONTIG   0x08/* allocate file contiguously */
> >  
> >  struct cluster_info {
> > daddr_t ci_lastr;   /* last read (read-ahead) */
> > diff --git a/sys/ufs/ffs/ffs_alloc.c b/sys/ufs/ffs/ffs_alloc.c
> > index 08961b9..807a2d1 100644
> > --- a/sys/ufs/ffs/ffs_alloc.c
> > +++ b/sys/ufs/ffs/ffs_alloc.c
> > @@ -63,16 +63,19 @@
> > (fs)->fs_fsmnt, (cp));  \
> >  } while (0)
> >  
> > -daddr_tffs_alloccg(struct inode *, int, daddr_t, int);
> > +daddr_tffs_alloccg(struct inode *, int, daddr_t, int, int);
> >  struct buf *   ffs_cgread(struct fs *, struct inode *, int);
> > -daddr_tffs_alloccgblk(struct inode *, struct buf *, daddr_t);
> > -daddr_tffs_clusteralloc(struct inode *, int, daddr_t, int);
> > +daddr_tffs_alloccgblk(struct inode *, struct buf *, daddr_t, 
> > int);
> > +daddr_tffs_clusteralloc(struct inode *, int, daddr_t, int, 
> > int);
> >  ufsino_t   ffs_dirpref(struct inode *);
> >  daddr_tffs_fragextend(struct inode *, int, daddr_t, int, int);
> > -daddr_tffs_hashalloc(struct inode *, int, daddr_t, int,
> > -   daddr_t (*)(struct inode *, int, daddr_t, int));
> > -daddr_tffs_nodealloccg(struct inode *, int, daddr_t, int);
> > +daddr_tffs_hashalloc(struct inode *, int, daddr_t, int, int,
> > +daddr_t (*)(struct inode *, int, daddr_t, int, int));
> > +daddr_tffs_nodealloccg(struct inode *, int, daddr_t, int, int);
> >  daddr_tffs_mapsearch(struct fs *, struct cg *, daddr_t, int);
> > +void   ffs_blkfree_subr(struct fs *, struct vnode *,
> > +   struct inode *, daddr_t bno, long size);
> > +
> >  
> >  int ffs1_reallocblks(void *);
> >  #ifdef FFS2
> > @@ -106,7 +109,7 @@ static const struct timeval fserr_interval = { 2, 0 
> > };
> >   *  available block is located.
> >   */
> >  int
> > -ffs_alloc(struct inode *ip, daddr_t lbn, daddr_t bpref, int size,
> > +ffs_alloc(struct inode *ip, daddr_t lbn, daddr_t bpref, int size, int 
> > flags,
> >  struct ucred *cred, daddr_t *bnp)
> >  {
> > static struct timeval fsfull_last;
> > @@ -147,7 +150,7 @@ ffs_alloc(struct inode *ip, daddr_t lbn, daddr_t bpref, 
> > int size,
> > cg = dtog(fs, bpref);
> >  
> > /* Try allocating a block. */
> > -   bno = ffs_hashalloc(ip, cg, bpref, size, ffs_alloccg);
> > +   bno = ffs_hashalloc(ip, cg, bpref, size, flags, ffs_alloccg);
> > if (bno > 0) {
> > /* allocation successful, update inode data */
> > DIP_ADD(ip, blocks, btodb(size));
> > @@ -159,6 +162,14 @@ ffs_alloc(struct inode *ip, daddr_t lbn, daddr_t 
> > bpref, int size,
> > /* Restore user's disk quota because allocation failed. */
> > (void) ufs_quota_free_blocks(ip, btodb(size), cred);
> >  
> > +#ifdef WAPBL
> > +   if (flags & B_CONTIG) {
> > +   /*
> > +* Fail silently -- it's up to our caller to report errors.
> > +*/
> > +   return (ENOSPC);
> > +   }
> > +#endif /* WAPBL */

netinet6 - bcopy -> memcpy

2015-12-02 Thread David Hill
Hello -

Here are a few bcopy -> memcpy conversions for buffers that do not
overlap.

Index: sys/netinet6/ip6_forward.c
===
RCS file: /cvs/src/sys/netinet6/ip6_forward.c,v
retrieving revision 1.86
diff -u -p -r1.86 ip6_forward.c
--- sys/netinet6/ip6_forward.c  2 Nov 2015 07:22:28 -   1.86
+++ sys/netinet6/ip6_forward.c  2 Dec 2015 17:20:27 -
@@ -206,7 +206,7 @@ reroute:
}
 
/* We need to do IPsec */
-   bcopy(>tdb_dst, , sizeof(sdst));
+   memcpy(, >tdb_dst, sizeof(sdst));
sspi = tdb->tdb_spi;
sproto = tdb->tdb_sproto;
}
Index: sys/netinet6/ip6_input.c
===
RCS file: /cvs/src/sys/netinet6/ip6_input.c,v
retrieving revision 1.151
diff -u -p -r1.151 ip6_input.c
--- sys/netinet6/ip6_input.c11 Nov 2015 10:23:23 -  1.151
+++ sys/netinet6/ip6_input.c2 Dec 2015 17:20:28 -
@@ -804,7 +804,7 @@ ip6_process_hopopts(struct mbuf *m, u_in
return (-1);
}
optlen = IP6OPT_RTALERT_LEN;
-   bcopy((caddr_t)(opt + 2), (caddr_t)_val, 2);
+   memcpy(_val, opt + 2, sizeof(rtalert_val));
*rtalertp = ntohs(rtalert_val);
break;
case IP6OPT_JUMBO:
@@ -837,9 +837,9 @@ ip6_process_hopopts(struct mbuf *m, u_in
 
/*
 * We may see jumbolen in unaligned location, so
-* we'd need to perform bcopy().
+* we'd need to perform memcpy().
 */
-   bcopy(opt + 2, , sizeof(jumboplen));
+   memcpy(, opt + 2, sizeof(jumboplen));
jumboplen = (u_int32_t)htonl(jumboplen);
 
 #if 1
@@ -962,7 +962,7 @@ ip6_savecontrol(struct inpcb *in6p, stru
/* RFC 2292 sec. 5 */
if ((in6p->inp_flags & IN6P_PKTINFO) != 0) {
struct in6_pktinfo pi6;
-   bcopy(>ip6_dst, _addr, sizeof(struct in6_addr));
+   memcpy(_addr, >ip6_dst, sizeof(struct in6_addr));
if (IN6_IS_SCOPE_EMBED(_addr))
pi6.ipi6_addr.s6_addr16[1] = 0;
pi6.ipi6_ifindex = m ? m->m_pkthdr.ph_ifidx : 0;
Index: sys/netinet6/ip6_output.c
===
RCS file: /cvs/src/sys/netinet6/ip6_output.c,v
retrieving revision 1.201
diff -u -p -r1.201 ip6_output.c
--- sys/netinet6/ip6_output.c   2 Dec 2015 13:29:26 -   1.201
+++ sys/netinet6/ip6_output.c   2 Dec 2015 17:20:28 -
@@ -2015,7 +2015,7 @@ do {\
dst->type = malloc(hlen, M_IP6OPT, canwait);\
if (dst->type == NULL && canwait == M_NOWAIT)\
goto bad;\
-   bcopy(src->type, dst->type, hlen);\
+   memcpy(dst->type, src->type, hlen);\
}\
 } while (/*CONSTCOND*/ 0)
 
Index: sys/netinet6/raw_ip6.c
===
RCS file: /cvs/src/sys/netinet6/raw_ip6.c,v
retrieving revision 1.87
diff -u -p -r1.87 raw_ip6.c
--- sys/netinet6/raw_ip6.c  24 Nov 2015 13:37:16 -  1.87
+++ sys/netinet6/raw_ip6.c  2 Dec 2015 17:20:28 -
@@ -756,7 +756,7 @@ rip6_usrreq(struct socket *so, int req, 
bzero(, sizeof(tmp));
tmp.sin6_family = AF_INET6;
tmp.sin6_len = sizeof(struct sockaddr_in6);
-   bcopy(>inp_faddr6, _addr,
+   memcpy(_addr, >inp_faddr6,
sizeof(struct in6_addr));
dst = 
} else {




Re: rm bge supported devices

2015-12-02 Thread Bryan Vyhmeister
On Wed, Dec 02, 2015 at 09:30:30AM -0700, Theo de Raadt wrote:
> I agree with Stuart.
> 
> When these lists include chip numbers, that is valuable.  Lists
> containing names like Belkin RandomProduct may be less helpful, but
> the case hasn't been proven the lists should be removed.

I completely agree as well. I use the lists, particularly for wireless
adapters, to at least get an idea what type of parts to look for on
Amazon or eBay.  Last month I pickup up a urtwn(4) device that I would
never have found had it not been listed in the man page.

Although I haven't checked the bge(4) man page in a long time, I have
checked the em(4) and ix(4) man pages recently in search for hardware. I
would really like to see this information remain in the man pages. I
recognize it can't be totally complete but it at least gives a starting
point. Anyone who looks at the manpage and sees a list of chipsets
followed by "including the following:" should realize that it is not an
exhaustive list.

If this information is removed, it will also lead to many more "Does
this work?" posts on misc@ since many people can't buy hardware for trial
and error.

Bryan



Re: rm bge supported devices

2015-12-02 Thread Stuart Henderson
On 2015/12/02 16:40, jus...@postgresql.org wrote:
> On 2015-12-02 16:07, Alexander Salmin wrote:
> 
> >I don't mind if this information is removed from the manual of the
> >device driver but I do mind if this information is lost without being
> >implemented somewhere else. Maybe it can be a list on the web FAQ
> >somewhere if you don't want it there. I'd also be happy to help
> >maintain that list of "known working hardware for driver X".
> 
> For this kind of thought, the hardware lists could be extracted from
> each of the driver man pages, then turned into a "Hardware Compatibility
> List".  eg:

We previously had lists by category in the "arch" pages on the website
but they got out of sync, we removed them in favour of having the
information in one place (in the driver manual).



Re: rm bge supported devices

2015-12-02 Thread justin

On 2015-12-02 17:39, Theo de Raadt wrote:


Sorry to have to tell you - what you propose is competely impossible.
At the low-end, we have experienced numerous cases where model 
numbers

don't change, but chipsets do.  What you propose is not time well
spent.


Oh well.  Another case of theory != reality. :)

+ Justin



Re: rm bge supported devices

2015-12-02 Thread Theo de Raadt
> > 
> >> I don't mind if this information is removed from the manual of the
> >> device driver but I do mind if this information is lost without 
> >> being
> >> implemented somewhere else. Maybe it can be a list on the web FAQ
> >> somewhere if you don't want it there. I'd also be happy to help
> >> maintain that list of "known working hardware for driver X".
> >
> > For this kind of thought, the hardware lists could be extracted from
> > each of the driver man pages, then turned into a "Hardware 
> > Compatibility
> > List".  eg:
> >
> >   1GbE network cards
> >   **
> >
> >   Model   Driver
> >   Intel I340-T2   em
> >   Intel I340-T4   em
> >   Intel I350-T2   em
> >   Intel I350-T4   em
> >
> >
> >   10GbE network cards
> >   ***
> >
> >   Model   Driver
> >   Intel X350-T4   ix
> >
> >
> >   Wifi cards
> >   **
> >
> >   Model   Driver
> >   A-Link WL54Hral
> >   AirLive WN-5000PCI  ral
> >   Amigo AWI-926W  ral
> >   AMIT WL531P ral
> >   AOpen AOI-831   ral
> >   ASUS WL-130Gral
> >   ASUS WL-130Nral
> >   ASUS WIFI-G-AAY ral
> >
> >
> > Having this info in one easy-to-search location sounds like it would
> > be even better for some use cases (eg people looking for hardware by
> > category, instead of by driver).
> 
> This kind of list could probably benefit from a field like "Supported
> from", indicating which release of OpenBSD added the support.
> 
>eg 5.8, 5.9, etc.

Sorry to have to tell you - what you propose is competely impossible.
At the low-end, we have experienced numerous cases where model numbers
don't change, but chipsets do.  What you propose is not time well
spent.




Re: rm bge supported devices

2015-12-02 Thread justin

On 2015-12-02 17:24, Stuart Henderson wrote:

On 2015/12/02 16:40, jus...@postgresql.org wrote:

On 2015-12-02 16:07, Alexander Salmin wrote:

>I don't mind if this information is removed from the manual of the
>device driver but I do mind if this information is lost without 
being

>implemented somewhere else. Maybe it can be a list on the web FAQ
>somewhere if you don't want it there. I'd also be happy to help
>maintain that list of "known working hardware for driver X".

For this kind of thought, the hardware lists could be extracted from
each of the driver man pages, then turned into a "Hardware 
Compatibility

List".  eg:


We previously had lists by category in the "arch" pages on the 
website

but they got out of sync, we removed them in favour of having the
information in one place (in the driver manual).


Sorry then.  Newbie-ness showing. ;)

Though since both approaches have been tried now, using hindsight has 
one
of the approaches been markedly better than the others for some use 
cases?


Personally, finding equipment was difficult for me as there's no "whole
category" list at the moment.  But, it's possible I'm an idiot. :D

+ Justin



kill another carp madness

2015-12-02 Thread Claudio Jeker
The check in if_ether.c for carp here does not make any sense.

There are two possible cases.
- parent interface without IP address
- parent interface with IP address

In the first case the carp mac-address will always be used. So no need to
do the check. In the 2nd case the parent interface mac-address will be
used and that is also always correct since we clone from there.
There is no way that the ifp and the rt->rt_ifp are not the same in this
case. So just remove this code and get rid of one rt_ifp.

-- 
:wq Claudio

Index: if_ether.c
===
RCS file: /cvs/src/sys/netinet/if_ether.c,v
retrieving revision 1.193
diff -u -p -r1.193 if_ether.c
--- if_ether.c  2 Dec 2015 13:29:26 -   1.193
+++ if_ether.c  2 Dec 2015 17:29:45 -
@@ -401,11 +401,6 @@ arpresolve(struct ifnet *ifp, struct rte
arprequest(ifp,

(rt->rt_ifa->ifa_addr)->sin_addr.s_addr,
(dst)->sin_addr.s_addr,
-#if NCARP > 0
-   (rt->rt_ifp->if_type == IFT_CARP) ?
-   ((struct arpcom *) rt->rt_ifp->if_softc
-   )->ac_enaddr :
-#endif
ac->ac_enaddr);
else {
rt->rt_flags |= RTF_REJECT;



Re: explicitly check broadcast addresses on some ifa_ifwithaddr() uses

2015-12-02 Thread Martin Pieuchot
On 02/12/15(Wed) 16:18, Vincent Gross wrote:
> When fed a broadcast address, ifa_ifwitaddr() returns the unicast ifa
> whose broadcast address match the input. This is used mainly to select
> ifa, and there can be trouble when you have 2 ifas on the same range
> (e.g. 10.0.0.1/24@em0 & 10.0.0.20/24@em1) :
> 
> netinet/ip_mroute.c:814
> net/route.c:785
> netinet/ip_divert.c:143
> net/if_vxlan.c:241
> 
> There are also places where broadcast addresses should not be tolerated :
> 
> netinet/ip_input.c:1061  broadcast address is not a module identifier
> netinet/ip_input.c:1141  see above
> netinet/ip_input.c:1197  see above
> netinet6/*:  no broadcast in ipv6
> net/route.c:562: gateway shall never be a broadcast addr
> net/route.c:713: see above
> 
> This diff removes broadcast matching from ifa_ifwithaddr, and
> adds or rewrites checks where necessary.
> 
> Comments ? Ok ?

Looks good to me.  Some nits below.

> Index: sys/netinet/in_pcb.c
> ===
> RCS file: /cvs/src/sys/netinet/in_pcb.c,v
> retrieving revision 1.188
> diff -u -p -r1.188 in_pcb.c
> --- sys/netinet/in_pcb.c  30 Oct 2015 09:39:42 -  1.188
> +++ sys/netinet/in_pcb.c  2 Dec 2015 15:17:26 -
> @@ -328,14 +328,12 @@ in_pcbbind(struct inpcb *inp, struct mbu
>  
>   ia = ifatoia(ifa_ifwithaddr(sintosa(sin),
>   inp->inp_rtableid));
> - if (ia == NULL)
> - return (EADDRNOTAVAIL);
>  
>   /* SOCK_RAW does not use in_pcbbind() */
> - if (so->so_type != SOCK_DGRAM &&
> - sin->sin_addr.s_addr !=
> - ia->ia_addr.sin_addr.s_addr)
> - return (EADDRNOTAVAIL);
> + if (ia == NULL &&
> + (so->so_type != SOCK_DGRAM ||
> + !in_broadcast(sin->sin_addr, inp->inp_rtable
id)))
^
Code should fit in 80 columns.

> + return (EADDRNOTAVAIL);
>   }
>   }
>   if (lport) {
> Index: sys/netinet/ip_output.c
> ===
> RCS file: /cvs/src/sys/netinet/ip_output.c,v
> retrieving revision 1.310
> diff -u -p -r1.310 ip_output.c
> --- sys/netinet/ip_output.c   2 Dec 2015 13:29:26 -   1.310
> +++ sys/netinet/ip_output.c   2 Dec 2015 15:17:27 -
> @@ -1387,9 +1387,8 @@ ip_setmoptions(int optname, struct ip_mo
>   sin.sin_family = AF_INET;
>   sin.sin_addr = addr;
>   ia = ifatoia(ifa_ifwithaddr(sintosa(), rtableid));
> - if (ia && in_hosteq(sin.sin_addr, ia->ia_addr.sin_addr))
> - ifp = ia->ia_ifp;
> - if (ifp == NULL || (ifp->if_flags & IFF_MULTICAST) == 0) {
> + if (ia == NULL || (ifp = ia->ia_ifp) == NULL ||

ia_ifp MUST not be NULL since you got it from the per-ifp list, so need
to check for NULL.

> + (ia->ia_ifp->if_flags & IFF_MULTICAST) == 0) {
>   error = EADDRNOTAVAIL;
>   break;
>   }



Re: doas password prompt

2015-12-02 Thread Ted Unangst
Vadim Zhukov wrote:
> 2015-12-02 12:40 GMT+03:00 Ted Unangst :
> > henning points out that if you are seven levels deep when doas asks for a
> > password, it can be hard to tell who is asking for what password.
> >
> > modify the prompt to include the program name and user@host.
> 
> The patch itself looks like fine for me, but why not just add '\u@\h'
> to PS1 instead?

If you run "ssh host doas -u user ssh host doas reboot" you don't get a
prompt. :)



Re: doas password prompt

2015-12-02 Thread Vadim Zhukov
2015-12-02 12:40 GMT+03:00 Ted Unangst :
> henning points out that if you are seven levels deep when doas asks for a
> password, it can be hard to tell who is asking for what password.
>
> modify the prompt to include the program name and user@host.

The patch itself looks like fine for me, but why not just add '\u@\h'
to PS1 instead?

--
  WBR,
  Vadim Zhukov



remove language catalogs from vi

2015-12-02 Thread Martijn van Duren

Hello tech@,

I've had a discussion with bentley@ about some patches for vi. Some of 
which I've send to Zhihao from the nvi2 project to keep the projects 
somewhat in sync. I'm still awaiting his response on those before 
sending them here.


nvi2 switched with catalog support to using the cat{open,gets,close}. 
Since OpenBSD moved away from translations in general and catopen is 
limited in it's usability since the default NL_CAT_LOCALE is removed I 
think we should remove catalog support. bentley@ agrees with me on this 
point.


Attached are four diffs, for easier reviewing, to incrementally remove 
support. After the last diff the catalog directory can be removed entirely.


Martijn van Duren
diff --git common/gs.h common/gs.h
index 8d64493..8859ba7 100644
--- common/gs.h
+++ common/gs.h
@@ -74,7 +74,6 @@ struct _gs {
 #define	GO_TERM		3		/* Global options: terminal type. */
 	OPTION	 opts[GO_TERM + 1];
 
-	DB	*msg;			/* Message catalog DB. */
 	MSGH	 msgq;			/* User message list. */
 #define	DEFAULT_NOPRINT	'\1'		/* Emergency non-printable character. */
 	CHAR_T	 noprint;		/* Cached, unprintable character. */
diff --git common/main.c common/main.c
index 4669fd3..7d0fc5c 100644
--- common/main.c
+++ common/main.c
@@ -493,9 +493,6 @@ v_end(GS *gp)
 
 	/* Free default buffer storage. */
 	(void)text_lfree(>dcb_store.textq);
-
-	/* Close message catalogs. */
-	msg_close(gp);
 #endif
 
 	/* Ring the bell if scheduled. */
diff --git common/msg.c common/msg.c
index 8e0a653..f10cc91 100644
--- common/msg.c
+++ common/msg.c
@@ -497,88 +497,6 @@ alloc_err:
 }
 
 /*
- * msg_open --
- *	Open the message catalogs.
- *
- * PUBLIC: int msg_open(SCR *, char *);
- */
-int
-msg_open(SCR *sp, char *file)
-{
-	/*
-	 * !!!
-	 * Assume that the first file opened is the system default, and that
-	 * all subsequent ones user defined.  Only display error messages
-	 * if we can't open the user defined ones -- it's useful to know if
-	 * the system one wasn't there, but if nvi is being shipped with an
-	 * installed system, the file will be there, if it's not, then the
-	 * message will be repeated every time nvi is started up.
-	 */
-	static int first = 1;
-	DB *db;
-	DBT data, key;
-	recno_t msgno;
-	char *p, *t, buf[PATH_MAX];
-
-	if ((p = strrchr(file, '/')) != NULL && p[1] == '\0' &&
-	(((t = getenv("LC_MESSAGES")) != NULL && t[0] != '\0') ||
-	((t = getenv("LANG")) != NULL && t[0] != '\0'))) {
-		(void)snprintf(buf, sizeof(buf), "%s%s", file, t);
-		p = buf;
-	} else
-		p = file;
-	if ((db = dbopen(p,
-	O_NONBLOCK | O_RDONLY, 0, DB_RECNO, NULL)) == NULL) {
-		if (first) {
-			first = 0;
-			return (1);
-		}
-		msgq_str(sp, M_SYSERR, p, "%s");
-		return (1);
-	}
-
-	/*
-	 * Test record 1 for the magic string.  The msgq call is here so
-	 * the message catalog build finds it.
-	 */
-#define	VMC	"VI_MESSAGE_CATALOG"
-	key.data = 
-	key.size = sizeof(recno_t);
-	msgno = 1;
-	if (db->get(db, , , 0) != 0 ||
-	data.size != sizeof(VMC) - 1 ||
-	memcmp(data.data, VMC, sizeof(VMC) - 1)) {
-		(void)db->close(db);
-		if (first) {
-			first = 0;
-			return (1);
-		}
-		msgq_str(sp, M_ERR, p,
-		"030|The file %s is not a message catalog");
-		return (1);
-	}
-	first = 0;
-
-	if (sp->gp->msg != NULL)
-		(void)sp->gp->msg->close(sp->gp->msg);
-	sp->gp->msg = db;
-	return (0);
-}
-
-/*
- * msg_close --
- *	Close the message catalogs.
- *
- * PUBLIC: void msg_close(GS *);
- */
-void
-msg_close(GS *gp)
-{
-	if (gp->msg != NULL)
-		(void)gp->msg->close(gp->msg);
-}
-
-/*
  * msg_cont --
  *	Return common continuation messages.
  *
@@ -613,10 +531,6 @@ msg_cmsg(SCR *sp, cmsg_t which, size_t *lenp)
  * msg_cat --
  *	Return a single message from the catalog, plus its length.
  *
- * !!!
- * Only a single catalog message can be accessed at a time, if multiple
- * ones are needed, they must be copied into local memory.
- *
  * PUBLIC: const char *msg_cat(SCR *, const char *, size_t *);
  */
 const char *
@@ -631,30 +545,8 @@ msg_cat(SCR *sp, const char *str, size_t *lenp)
 	 * number and '|' symbol, we're done.
 	 */
 	if (isdigit(str[0]) &&
-	isdigit(str[1]) && isdigit(str[2]) && str[3] == '|') {
-		key.data = 
-		key.size = sizeof(recno_t);
-		msgno = atoi(str);
-
-		/*
-		 * XXX
-		 * Really sleazy hack -- we put an extra character on the
-		 * end of the format string, and then we change it to be
-		 * the nul termination of the string.  There ought to be
-		 * a better way.  Once we can allocate multiple temporary
-		 * memory buffers, maybe we can use one of them instead.
-		 */
-		gp = sp == NULL ? NULL : sp->gp;
-		if (gp != NULL && gp->msg != NULL &&
-		gp->msg->get(gp->msg, , , 0) == 0 &&
-		data.size != 0) {
-			if (lenp != NULL)
-*lenp = data.size - 1;
-			((char *)data.data)[data.size - 1] = '\0';
-			return (data.data);
-		}
+	isdigit(str[1]) && isdigit(str[2]) && str[3] == '|')
 		str = [4];
-	}
 	if (lenp != NULL)
 		*lenp = strlen(str);
 	return (str);
diff --git common/options.c 

Ansify phantasia(6)

2015-12-02 Thread Ricardo Mestre
phantasia(6) needs some KNF love, but for now here is a patch to ansify it:

Index: fight.c
===
RCS file: /cvs/src/games/phantasia/fight.c,v
retrieving revision 1.11
diff -u -p -u -r1.11 fight.c
--- fight.c 12 Jul 2014 03:41:04 -  1.11
+++ fight.c 2 Dec 2015 19:25:53 -
@@ -38,8 +38,7 @@
 */
 
 void
-encounter(particular)
-   int particular;
+encounter(int particular)
 {
int flockcnt = 1;   /* how many time flocked */
volatile bool firsthit = Player.p_blessing; /* set if player gets
@@ -207,7 +206,7 @@ encounter(particular)
 */
 
 int
-pickmonster()
+pickmonster(void)
 {
if (Player.p_specialtype == SC_VALAR)
/* even chance of any monster */
@@ -264,7 +263,7 @@ pickmonster()
 */
 
 void
-playerhits()
+playerhits(void)
 {
double  inflict;/* damage inflicted */
int ch; /* input */
@@ -435,7 +434,7 @@ playerhits()
 */
 
 void
-monsthits()
+monsthits(void)
 {
double  inflict;/* damage inflicted */
int ch; /* input */
@@ -709,7 +708,7 @@ SPECIALHIT:
 */
 
 void
-cancelmonster()
+cancelmonster(void)
 {
 Curmonster.m_energy = 0.0;
 Curmonster.m_experience = 0.0;
@@ -743,8 +742,7 @@ cancelmonster()
 */
 
 void
-hitmonster(inflict)
-   double  inflict;
+hitmonster(double inflict)
 {
mvprintw(Lines++, 0, "You hit %s %.0f times!", Enemyname, inflict);
Curmonster.m_energy -= inflict;
@@ -797,7 +795,7 @@ hitmonster(inflict)
 */
 
 void
-throwspell()
+throwspell(void)
 {
double  inflict;/* damage inflicted */
double  dtemp;  /* for dtemporary calculations */
@@ -1028,8 +1026,7 @@ throwspell()
 */
 
 void
-callmonster(which)
-   int which;
+callmonster(int which)
 {
struct monster Othermonster;/* to find a name for mimics */
 
@@ -1136,7 +1133,7 @@ callmonster(which)
 */
 
 void
-awardtreasure()
+awardtreasure(void)
 {
int whichtreasure;  /* calculated treasure to grant */
int temp;   /* temporary */
@@ -1573,7 +1570,7 @@ awardtreasure()
 */
 
 void
-cursedtreasure()
+cursedtreasure(void)
 {
if (Player.p_charms > 0) {
addstr("But your charm saved you!\n");
@@ -1613,7 +1610,7 @@ cursedtreasure()
 */
 
 void
-scramblestats()
+scramblestats(void)
 {
double  dbuf[6];/* to put statistic in */
double  dtemp1, dtemp2; /* for swapping values */
Index: gamesupport.c
===
RCS file: /cvs/src/games/phantasia/gamesupport.c,v
retrieving revision 1.7
diff -u -p -u -r1.7 gamesupport.c
--- gamesupport.c   15 Dec 2010 06:40:39 -  1.7
+++ gamesupport.c   2 Dec 2015 19:25:55 -
@@ -54,8 +54,7 @@
 */
 
 void
-changestats(ingameflag)
-   boolingameflag;
+changestats(bool ingameflag)
 {
static char flag[2] =   /* for printing values of bools */
{'F', 'T'};
@@ -509,7 +508,7 @@ BALTER:
 */
 
 void
-monstlist()
+monstlist(void)
 {
int count = 0;  /* count in file */
 
@@ -546,7 +545,7 @@ monstlist()
 */
 
 void
-scorelist()
+scorelist(void)
 {
struct scoreboard sbuf; /* for reading entries */
FILE   *fp; /* to open the file */
@@ -583,7 +582,7 @@ scorelist()
 */
 
 void
-activelist()
+activelist(void)
 {
fseek(Playersfp, 0L, SEEK_SET);
printf("Current characters on file are:\n\n");
@@ -621,7 +620,7 @@ activelist()
 */
 
 void
-purgeoldplayers()
+purgeoldplayers(void)
 {
int today;  /* day of year for today */
int daysold;/* how many days since the character has been
@@ -678,7 +677,7 @@ purgeoldplayers()
 

Re: WAPBL: Adding the FFS capability to alloc files contiguously

2015-12-02 Thread Walter Neto
Fixed diff

Ok beck@ and tedu@

--
Walter Neto

diff --git a/sys/sys/buf.h b/sys/sys/buf.h
index c47f3f9..fd38c28 100644
--- a/sys/sys/buf.h
+++ b/sys/sys/buf.h
@@ -254,6 +254,8 @@ struct cluster_save {
 /* Flags to low-level allocation routines. */
 #define B_CLRBUF   0x01/* Request allocated buffer be cleared. */
 #define B_SYNC 0x02/* Do all allocations synchronously. */
+#define B_METAONLY 0x04/* return indirect block buffer */
+#define B_CONTIG   0x08/* allocate file contiguously */
 
 struct cluster_info {
daddr_t ci_lastr;   /* last read (read-ahead) */
diff --git a/sys/ufs/ffs/ffs_alloc.c b/sys/ufs/ffs/ffs_alloc.c
index 08961b9..f692261 100644
--- a/sys/ufs/ffs/ffs_alloc.c
+++ b/sys/ufs/ffs/ffs_alloc.c
@@ -63,16 +63,19 @@
(fs)->fs_fsmnt, (cp));  \
 } while (0)
 
-daddr_tffs_alloccg(struct inode *, int, daddr_t, int);
+daddr_tffs_alloccg(struct inode *, int, daddr_t, int, int);
 struct buf *   ffs_cgread(struct fs *, struct inode *, int);
-daddr_tffs_alloccgblk(struct inode *, struct buf *, daddr_t);
-daddr_tffs_clusteralloc(struct inode *, int, daddr_t, int);
+daddr_tffs_alloccgblk(struct inode *, struct buf *, daddr_t, 
int);
+daddr_tffs_clusteralloc(struct inode *, int, daddr_t, int, 
int);
 ufsino_t   ffs_dirpref(struct inode *);
 daddr_tffs_fragextend(struct inode *, int, daddr_t, int, int);
-daddr_tffs_hashalloc(struct inode *, int, daddr_t, int,
-   daddr_t (*)(struct inode *, int, daddr_t, int));
-daddr_tffs_nodealloccg(struct inode *, int, daddr_t, int);
+daddr_tffs_hashalloc(struct inode *, int, daddr_t, int, int,
+daddr_t (*)(struct inode *, int, daddr_t, int, int));
+daddr_tffs_nodealloccg(struct inode *, int, daddr_t, int, int);
 daddr_tffs_mapsearch(struct fs *, struct cg *, daddr_t, int);
+void   ffs_blkfree_subr(struct fs *, struct vnode *,
+   struct inode *, daddr_t bno, long size);
+
 
 int ffs1_reallocblks(void *);
 #ifdef FFS2
@@ -106,7 +109,7 @@ static const struct timeval fserr_interval = { 2, 0 };
  *  available block is located.
  */
 int
-ffs_alloc(struct inode *ip, daddr_t lbn, daddr_t bpref, int size,
+ffs_alloc(struct inode *ip, daddr_t lbn, daddr_t bpref, int size, int flags,
 struct ucred *cred, daddr_t *bnp)
 {
static struct timeval fsfull_last;
@@ -147,7 +150,7 @@ ffs_alloc(struct inode *ip, daddr_t lbn, daddr_t bpref, int 
size,
cg = dtog(fs, bpref);
 
/* Try allocating a block. */
-   bno = ffs_hashalloc(ip, cg, bpref, size, ffs_alloccg);
+   bno = ffs_hashalloc(ip, cg, bpref, size, flags, ffs_alloccg);
if (bno > 0) {
/* allocation successful, update inode data */
DIP_ADD(ip, blocks, btodb(size));
@@ -160,6 +163,14 @@ ffs_alloc(struct inode *ip, daddr_t lbn, daddr_t bpref, 
int size,
(void) ufs_quota_free_blocks(ip, btodb(size), cred);
 
 nospace:
+#ifdef WAPBL
+   if (flags & B_CONTIG) {
+   /*
+* Fail silently -- it's up to our caller to report errors.
+*/
+   return (ENOSPC);
+   }
+#endif /* WAPBL */
if (ratecheck(_last, _interval)) {
ffs_fserr(fs, cred->cr_uid, "file system full");
uprintf("\n%s: write failed, file system is full\n",
@@ -178,7 +189,7 @@ nospace:
  */
 int
 ffs_realloccg(struct inode *ip, daddr_t lbprev, daddr_t bpref, int osize,
-int nsize, struct ucred *cred, struct buf **bpp, daddr_t *blknop)
+int nsize, int flags, struct ucred *cred, struct buf **bpp, daddr_t 
*blknop)
 {
static struct timeval fsfull_last;
struct fs *fs;
@@ -295,7 +306,7 @@ ffs_realloccg(struct inode *ip, daddr_t lbprev, daddr_t 
bpref, int osize,
panic("ffs_realloccg: bad optim");
/* NOTREACHED */
}
-   bno = ffs_hashalloc(ip, cg, bpref, request, ffs_alloccg);
+   bno = ffs_hashalloc(ip, cg, bpref, request, flags, ffs_alloccg);
if (bno <= 0)
goto nospace;
 
@@ -434,7 +445,7 @@ ffs1_reallocblks(void *v)
/*
 * Find the preferred location for the cluster.
 */
-   pref = ffs1_blkpref(ip, start_lbn, soff, sbap);
+   pref = ffs1_blkpref(ip, start_lbn, soff, 0, sbap);
/*
 * If the block range spans two block maps, get the second map.
 */
@@ -454,7 +465,7 @@ ffs1_reallocblks(void *v)
/*
 * Search the block map looking for an allocation of the desired size.
 */
-   if ((newblk = ffs_hashalloc(ip, dtog(fs, pref), pref, len,
+   if ((newblk = ffs_hashalloc(ip, dtog(fs, pref), pref, len, 0,
ffs_clusteralloc)) == 0)
goto fail;
/*
@@ 

libc: locale/rune.c input validation

2015-12-02 Thread Tobias Stoeckmann
Hi,

this patch adds a lot of input validation to libc/locale/rune.c.
The kind of validations are borrowed from my nls changes some
weeks ago.

I've contacted stsp@ about this. I think it's ready to get more
review from tech@. Let me know what you think!


Tobias

Index: rune.c
===
RCS file: /cvs/src/lib/libc/locale/rune.c,v
retrieving revision 1.4
diff -u -p -u -p -r1.4 rune.c
--- rune.c  25 May 2014 17:47:04 -  1.4
+++ rune.c  30 Oct 2015 16:13:01 -
@@ -59,23 +59,31 @@
  * SUCH DAMAGE.
  */
 
+#include 
+#include 
 #include 
+#include 
+#include 
 #include 
-#include 
 #include 
-#include 
+#include 
 #include 
-#include 
-#include 
 #include "rune.h"
 #include "rune_local.h"
 
-static int readrange(_RuneLocale *, _RuneRange *, _FileRuneRange *, void *, 
FILE *);
+#define SAFE_ADD(x, y) \
+do {   \
+   if ((x) > SIZE_MAX - (y))   \
+   return NULL;\
+   (x) += (y); \
+} while (0);
+
+static int readrange(_RuneLocale *, _RuneRange *, rune_t, void *, FILE *);
 static void _freeentry(_RuneRange *);
 static void _wctype_init(_RuneLocale *rl);
 
 static int
-readrange(_RuneLocale *rl, _RuneRange *rr, _FileRuneRange *frr, void *lastp,
+readrange(_RuneLocale *rl, _RuneRange *rr, rune_t nranges, void *lastp,
FILE *fp)
 {
uint32_t i;
@@ -84,7 +92,7 @@ readrange(_RuneLocale *rl, _RuneRange *r
 
re = (_RuneEntry *)rl->rl_variable;
 
-   rr->rr_nranges = ntohl(frr->frr_nranges);
+   rr->rr_nranges = nranges;
if (rr->rr_nranges == 0) {
rr->rr_rune_ranges = NULL;
return 0;
@@ -92,6 +100,9 @@ readrange(_RuneLocale *rl, _RuneRange *r
 
rr->rr_rune_ranges = re;
for (i = 0; i < rr->rr_nranges; i++) {
+   if ((void *)re >= lastp)
+   return -1;
+
if (fread(, sizeof(fre), 1, fp) != 1)
return -1;
 
@@ -99,9 +110,6 @@ readrange(_RuneLocale *rl, _RuneRange *r
re->re_max = ntohl((u_int32_t)fre.fre_max);
re->re_map = ntohl((u_int32_t)fre.fre_map);
re++;
-
-   if ((void *)re > lastp)
-   return -1;
}
rl->rl_variable = re;
return 0;
@@ -121,6 +129,9 @@ readentry(_RuneRange *rr, FILE *fp)
continue;
}
 
+   if (re[i].re_max < re[i].re_min)
+   goto fail;
+
l = re[i].re_max - re[i].re_min + 1;
re[i].re_rune_types = calloc(l, sizeof(_RuneType));
if (!re[i].re_rune_types) {
@@ -151,17 +162,20 @@ fail2:
 }
 
 /* XXX: temporary implementation */
-static void
+static int
 find_codeset(_RuneLocale *rl)
 {
char *top, *codeset, *tail, *ep;
 
+   if (rl->rl_variable == NULL)
+   return 0;
+
/* end of rl_variable region */
ep = (char *)rl->rl_variable;
ep += rl->rl_variable_len;
rl->rl_codeset = NULL;
if (!(top = strstr(rl->rl_variable, _RUNE_CODESET)))
-   return;
+   return 0;
tail = strpbrk(top, " \t");
codeset = top + sizeof(_RUNE_CODESET) - 1;
if (tail) {
@@ -173,6 +187,7 @@ find_codeset(_RuneLocale *rl)
*top = '\0';
rl->rl_codeset = strdup(codeset);
}
+   return (rl->rl_codeset == NULL);
 }
 
 void
@@ -183,8 +198,7 @@ _freeentry(_RuneRange *rr)
 
re = rr->rr_rune_ranges;
for (i = 0; i < rr->rr_nranges; i++) {
-   if (re[i].re_rune_types)
-   free(re[i].re_rune_types);
+   free(re[i].re_rune_types);
re[i].re_rune_types = NULL;
}
 }
@@ -209,6 +223,7 @@ _Read_RuneMagi(FILE *fp)
_RuneLocale *rl;
struct stat sb;
int x;
+   rune_t runetype_nranges, maplower_nranges, mapupper_nranges;
 
if (fstat(fileno(fp), ) < 0)
return NULL;
@@ -225,10 +240,24 @@ _Read_RuneMagi(FILE *fp)
if (memcmp(frl.frl_magic, _RUNE_MAGIC_1, sizeof(frl.frl_magic)))
return NULL;
 
-   hostdatalen = sizeof(*rl) + ntohl((u_int32_t)frl.frl_variable_len) +
-   ntohl(frl.frl_runetype_ext.frr_nranges) * sizeof(_RuneEntry) +
-   ntohl(frl.frl_maplower_ext.frr_nranges) * sizeof(_RuneEntry) +
-   ntohl(frl.frl_mapupper_ext.frr_nranges) * sizeof(_RuneEntry);
+   /* XXX assumes rune_t = u_int32_t */
+   runetype_nranges = ntohl(frl.frl_runetype_ext.frr_nranges);
+   maplower_nranges = ntohl(frl.frl_maplower_ext.frr_nranges);
+   mapupper_nranges = ntohl(frl.frl_mapupper_ext.frr_nranges);
+
+#ifndef __LP64__
+   if (runetype_nranges > SIZE_MAX / sizeof(_RuneEntry) ||
+   maplower_nranges > SIZE_MAX / sizeof(_RuneEntry) ||
+   mapupper_nranges > 

more arp cleanup

2015-12-02 Thread Claudio Jeker
More rt_ifp killing. This time in in_arpinput().
This function is a bit special because of the way we propagte multicast
and broadcast packets it is possible that multiple interfaces recieve the
same request. In most cases this is because of -- you can guess --
carp(4). So simplify these checks and make them more generic at the same
time (in the SINPROXY case). In other words only the interface holding the
proxy arp route will answer to the requests.

OK?
-- 
:wq Claudio

Index: if_ether.c
===
RCS file: /cvs/src/sys/netinet/if_ether.c,v
retrieving revision 1.195
diff -u -p -r1.195 if_ether.c
--- if_ether.c  2 Dec 2015 18:38:19 -   1.195
+++ if_ether.c  2 Dec 2015 18:42:36 -
@@ -560,7 +560,7 @@ in_arpinput(struct mbuf *m)
   ether_sprintf(ea->arp_sha),
   ifp->if_xname);
goto out;
-   } else if (rt->rt_ifp != ifp) {
+   } else if (rt->rt_ifidx != ifp->if_index) {
 #if NCARP > 0
if (ifp->if_type != IFT_CARP)
 #endif
@@ -639,10 +639,9 @@ out:
rt = arplookup(itaddr.s_addr, 0, SIN_PROXY, rdomain);
if (rt == NULL)
goto out;
-#if NCARP > 0
-   if (rt->rt_ifp->if_type == IFT_CARP && ifp->if_type != IFT_CARP)
+   /* protect from possible duplicates only owner should respond */
+   if (rt->rt_ifidx != ifp->if_index)
goto out;
-#endif
memcpy(ea->arp_tha, ea->arp_sha, sizeof(ea->arp_sha));
sdl = satosdl(rt->rt_gateway);
memcpy(ea->arp_sha, LLADDR(sdl), sizeof(ea->arp_sha));



Re: pf statekey inp chaining

2015-12-02 Thread Alexander Bluhm
On Wed, Dec 02, 2015 at 04:48:51PM +0100, Alexander Bluhm wrote:
> To avoid that the stack manipules the pf statekeys directly, introduce
> some pf_inp_...() functions as an interface.  Locks can be added
> to them later.

Here is a new version of the diff.  This is new:

- rename "chain" to "link" after some bikeshedding in the hackroom
- propper function style
- merge with sashan@'s diff
- no pf_inp_enter() function, manipulate the mbuf directly
- do not move the SS_ISCONNECTED checks into pf

ok?

bluhm

Index: net/pf.c
===
RCS file: /data/mirror/openbsd/cvs/src/sys/net/pf.c,v
retrieving revision 1.954
diff -u -p -r1.954 pf.c
--- net/pf.c2 Dec 2015 16:00:42 -   1.954
+++ net/pf.c2 Dec 2015 18:32:50 -
@@ -6728,6 +6728,40 @@ pf_pkt_addr_changed(struct mbuf *m)
m->m_pkthdr.pf.inp = NULL;
 }
 
+struct inpcb *
+pf_inp_lookup(struct mbuf *m)
+{
+   struct inpcb *inp = NULL;
+
+   if (m->m_pkthdr.pf.statekey) {
+   inp = m->m_pkthdr.pf.statekey->inp;
+   if (inp && inp->inp_pf_sk)
+   KASSERT(m->m_pkthdr.pf.statekey == inp->inp_pf_sk);
+   }
+   return (inp);
+}
+
+void
+pf_inp_link(struct mbuf *m, struct inpcb *inp)
+{
+   if (m->m_pkthdr.pf.statekey && inp &&
+   !m->m_pkthdr.pf.statekey->inp && !inp->inp_pf_sk) {
+   m->m_pkthdr.pf.statekey->inp = inp;
+   inp->inp_pf_sk = m->m_pkthdr.pf.statekey;
+   }
+   /* The statekey has finished finding the inp, it is no longer needed. */
+   m->m_pkthdr.pf.statekey = NULL;
+}
+
+void
+pf_inp_unlink(struct inpcb *inp)
+{
+   if (inp->inp_pf_sk) {
+   inp->inp_pf_sk->inp = NULL;
+   inp->inp_pf_sk = NULL;
+   }
+}
+
 #if NPFLOG > 0
 void
 pf_log_matches(struct pf_pdesc *pd, struct pf_rule *rm, struct pf_rule *am,
Index: net/pfvar.h
===
RCS file: /data/mirror/openbsd/cvs/src/sys/net/pfvar.h,v
retrieving revision 1.424
diff -u -p -r1.424 pfvar.h
--- net/pfvar.h 2 Dec 2015 16:00:42 -   1.424
+++ net/pfvar.h 2 Dec 2015 18:32:50 -
@@ -1754,6 +1754,9 @@ int   pf_rtlabel_match(struct pf_addr *, s
 intpf_socket_lookup(struct pf_pdesc *);
 struct pf_state_key *pf_alloc_state_key(int);
 void   pf_pkt_addr_changed(struct mbuf *);
+struct inpcb *pf_inp_lookup(struct mbuf *);
+void   pf_inp_link(struct mbuf *, struct inpcb *);
+void   pf_inp_unlink(struct inpcb *);
 intpf_state_key_attach(struct pf_state_key *, struct pf_state *, int);
 intpf_translate(struct pf_pdesc *, struct pf_addr *, u_int16_t,
struct pf_addr *, u_int16_t, u_int16_t, int);
Index: netinet/in_pcb.c
===
RCS file: /data/mirror/openbsd/cvs/src/sys/netinet/in_pcb.c,v
retrieving revision 1.189
diff -u -p -r1.189 in_pcb.c
--- netinet/in_pcb.c2 Dec 2015 16:00:42 -   1.189
+++ netinet/in_pcb.c2 Dec 2015 17:37:56 -
@@ -509,8 +509,7 @@ in_pcbdetach(struct inpcb *inp)
if (inp->inp_pf_sk) {
pf_unlink_divert_state(inp->inp_pf_sk);
/* pf_unlink_divert_state() may have detached the state */
-   if (inp->inp_pf_sk)
-   inp->inp_pf_sk->inp = NULL;
+   pf_inp_unlink(inp);
}
 #endif
s = splnet();
Index: netinet/tcp_input.c
===
RCS file: /data/mirror/openbsd/cvs/src/sys/netinet/tcp_input.c,v
retrieving revision 1.310
diff -u -p -r1.310 tcp_input.c
--- netinet/tcp_input.c 29 Nov 2015 15:09:32 -  1.310
+++ netinet/tcp_input.c 2 Dec 2015 17:38:07 -
@@ -580,11 +580,7 @@ tcp_input(struct mbuf *m, ...)
 * Locate pcb for segment.
 */
 #if NPF > 0
-   if (m->m_pkthdr.pf.statekey) {
-   inp = m->m_pkthdr.pf.statekey->inp;
-   if (inp && inp->inp_pf_sk)
-   KASSERT(m->m_pkthdr.pf.statekey == inp->inp_pf_sk);
-   }
+   inp = pf_inp_lookup(m);
 #endif
 findpcb:
if (inp == NULL) {
@@ -602,12 +598,6 @@ findpcb:
m->m_pkthdr.ph_rtableid);
break;
}
-#if NPF > 0
-   if (m->m_pkthdr.pf.statekey && inp) {
-   m->m_pkthdr.pf.statekey->inp = inp;
-   inp->inp_pf_sk = m->m_pkthdr.pf.statekey;
-   }
-#endif
}
if (inp == NULL) {
int inpl_reverse = 0;
@@ -880,13 +870,8 @@ findpcb:
 #endif
 
 #if NPF > 0
-   if (m->m_pkthdr.pf.statekey && !m->m_pkthdr.pf.statekey->inp &&
-   !inp->inp_pf_sk) {
-   m->m_pkthdr.pf.statekey->inp = inp;
-   inp->inp_pf_sk = m->m_pkthdr.pf.statekey;
-   }
-   /* The statekey has finished finding the inp, it is no longer needed. */
-   

Re: unifdef(1) - in-place editing without backups

2015-12-02 Thread Stuart Henderson
On 2015/12/02 00:04, Michael McConville wrote:
> unifdef's -M option is like sed's -i option, editing in-place and saving
> a backup with the supplied extension.

There is an upstream for unifdef: http://dotat.at/prog/unifdef/
Please talk to Tony Finch and see if he'll take the diff; it's helpful
to not diverge too much.



bridge(4) never outputs packets

2015-12-02 Thread Martin Pieuchot
Make sure if_output() and if_start() will never be called for the
bridge(4).

Concerns?

Index: net/if_bridge.c
===
RCS file: /cvs/src/sys/net/if_bridge.c,v
retrieving revision 1.273
diff -u -p -r1.273 if_bridge.c
--- net/if_bridge.c 2 Dec 2015 08:04:12 -   1.273
+++ net/if_bridge.c 2 Dec 2015 08:07:38 -
@@ -111,7 +111,6 @@
 void   bridgeattach(int);
 intbridge_ioctl(struct ifnet *, u_long, caddr_t);
 intbridge_input(struct ifnet *, struct mbuf *, void *);
-void   bridge_start(struct ifnet *);
 void   bridge_process(struct ifnet *, struct mbuf *);
 void   bridgeintr_frame(struct bridge_softc *, struct ifnet *, struct mbuf *);
 void   bridge_broadcast(struct bridge_softc *, struct ifnet *,
@@ -189,8 +188,8 @@ bridge_clone_create(struct if_clone *ifc
ifp->if_softc = sc;
ifp->if_mtu = ETHERMTU;
ifp->if_ioctl = bridge_ioctl;
-   ifp->if_output = bridge_output;
-   ifp->if_start = bridge_start;
+   ifp->if_output = NULL;
+   ifp->if_start = NULL;
ifp->if_type = IFT_BRIDGE;
ifp->if_hdrlen = ETHER_HDR_LEN;
 
@@ -830,14 +829,6 @@ sendunicast:
}
bridge_ifenqueue(sc, dst_if, m);
return (0);
-}
-
-/*
- * Start output on the bridge.  This function should never be called.
- */
-void
-bridge_start(struct ifnet *ifp)
-{
 }
 
 /*



Re: pledge dhcpd(8), 1st attempt

2015-12-02 Thread Ricardo Mestre
Hi Stuart,

You are right, they have, my problem in this case was that I'm trying to
pledge earlier and with the codepaths I was using I was being blocked
right there.

I should have checked kern_pledge.c first and/or removed those earlier
pledges to confirm if the problem really was from sendto(2), which in
this case wasn't. That being said, please disregard that swap, although
the pledge annotation still applies.

If my job workload today allows me I will try to have a further look on
how to place a couple of earlier pledges, considering the fiddling with
pf tables and the UDP code paths, although the latter is more tricky.

On 01/12/2015 22:10, Stuart Henderson wrote:
> On 2015/12/01 21:24, Ricardo Mestre wrote:
>> Hi tech@
>>
>> This is my first attempt at pledging dhcpd(8), right now I don't have time to
>> go further, but this is a working diff I having seating at my tree I want to
>> show you, although tomorrow I intend to get back at it.
>>
>> Declare usage() as __dead since it never returns, hoist up sync_init() since 
>> it
>> calls a setsockopt(2) for multicast not allowed (yet?) by pledge(2) so I
>> (someone else?) can apply pledge ealier on and then finally if dhcpd(8) was 
>> NOT
>> called with "-u" parameter (!udpsockmode) then request "inet" since this is a
>> network daemon and therefore needs to perform network operations and "sendfd"
>> to send a msg.
>>
>> For this last annotation I changed sendto(2) to sendmsg(2) in icmp.c so we
>> don't have to give permissions to the daemon it doesn't need and it just 
>> sends
>> an ICMP echo request (hey here is a DHCPOFFER) to the host that is requesting
>> an IP address.
> 
> Don't these (sendto, sendmsg) need the same permissions anyway?
> 
>> +++ icmp.c   1 Dec 2015 20:59:31 -
> ..
>>  icmp.icmp_cksum = wrapsum(checksum((unsigned char *),
>> -sizeof(icmp), 0));
>> +sizeof(icmp), 0));
>> +
> 
> KNF here, the previous indentation was correct
> 



Dumb arplookup()

2015-12-02 Thread Martin Pieuchot
If the kernel tries to create (cloned) an ARP entry and found an
existing conflicting route, do not try to be clever and just bail.

I'm fine with rtalloc(9) taking the KERNEL_LOCK when cloning an entry
but I'd prefer the ARP layer to not try to delete anything in the hot
path.

If you entered a conflicting entry in your routing table, that's your
problem, you deal with it.

Ok?

Index: netinet/if_ether.c
===
RCS file: /cvs/src/sys/netinet/if_ether.c,v
retrieving revision 1.191
diff -u -p -r1.191 if_ether.c
--- netinet/if_ether.c  1 Dec 2015 12:22:18 -   1.191
+++ netinet/if_ether.c  2 Dec 2015 08:40:13 -
@@ -707,12 +707,9 @@ arplookup(u_int32_t addr, int create, in
flags = (create) ? (RT_REPORT|RT_RESOLVE) : 0;
 
rt = rtalloc((struct sockaddr *), flags, tableid);
-   if (rt == NULL)
-   return (NULL);
-   if ((rt->rt_flags & RTF_GATEWAY) || (rt->rt_flags & RTF_LLINFO) == 0 ||
+   if (!rtisvalid(rt) || ISSET(rt->rt_flags, RTF_GATEWAY) ||
+   !ISSET(rt->rt_flags, RTF_LLINFO) ||
rt->rt_gateway->sa_family != AF_LINK) {
-   if (create && (rt->rt_flags & RTF_CLONED))
-   rtdeletemsg(rt, tableid);
rtfree(rt);
return (NULL);
}



Re: Completely disable 2D acceleration on Broadwell

2015-12-02 Thread Peter Hessler
On 2015 Dec 02 (Wed) at 17:13:32 +1100 (+1100), Jonathan Gray wrote:
:On Tue, Dec 01, 2015 at 04:44:39PM +0100, Mark Kettenis wrote:
:> As tedu@ reported (and some pople on misc@ confirmed) partly disabling
:> 2D acceleration on Broadwell made X unstable.  It really looks like
:> the alternative BLT path isn't well tested and therefore buggy.  So
:> here is a diff that disables 2D acceleration completely.  Those who
:> don't care about suspend/resume can still enable it if they want.  3D
:> acceleration should continue to work.
:> 
:> ok?
:
:chrome and mplayer seem basically unuseable with this.  Perhaps it
:should be those who want to suspend/resume can run the modesetting
:driver or disable acceleration via xorg.conf.
:

mplayer with vo=gl or with vo=xv?


:> 
:> 
:> Index: sna_accel.c
:> ===
:> RCS file: /home/cvs/xenocara/driver/xf86-video-intel/src/sna/sna_accel.c,v
:> retrieving revision 1.6
:> diff -u -p -r1.6 sna_accel.c
:> --- sna_accel.c  15 Nov 2015 15:33:57 -  1.6
:> +++ sna_accel.c  1 Dec 2015 15:37:44 -
:> @@ -17659,6 +17659,9 @@ static bool sna_option_accel_none(struct
:>  return true;
:>  
:>  s = xf86GetOptValString(sna->Options, OPTION_ACCEL_METHOD);
:> +/* XXX avoid render ring since it gets stuck after resume */
:> +if (s == NULL && sna->info->gen >= 0100)
:> +return true;
:>  if (s == NULL)
:>  return IS_DEFAULT_ACCEL_METHOD(NOACCEL);
:>  
:> @@ -17670,9 +17673,6 @@ static bool sna_option_accel_blt(struct 
:>  const char *s;
:>  
:>  s = xf86GetOptValString(sna->Options, OPTION_ACCEL_METHOD);
:> -/* XXX avoid render ring since it gets stuck after resume */
:> -if (s == NULL && sna->info->gen >= 0100)
:> -return true;
:>  if (s == NULL)
:>  return false;
:>  
:> 
:



Re: Dumb arplookup()

2015-12-02 Thread Claudio Jeker
On Wed, Dec 02, 2015 at 09:44:15AM +0100, Martin Pieuchot wrote:
> If the kernel tries to create (cloned) an ARP entry and found an
> existing conflicting route, do not try to be clever and just bail.
> 
> I'm fine with rtalloc(9) taking the KERNEL_LOCK when cloning an entry
> but I'd prefer the ARP layer to not try to delete anything in the hot
> path.
> 
> If you entered a conflicting entry in your routing table, that's your
> problem, you deal with it.
> 
> Ok?

OK claudio@
 
> Index: netinet/if_ether.c
> ===
> RCS file: /cvs/src/sys/netinet/if_ether.c,v
> retrieving revision 1.191
> diff -u -p -r1.191 if_ether.c
> --- netinet/if_ether.c1 Dec 2015 12:22:18 -   1.191
> +++ netinet/if_ether.c2 Dec 2015 08:40:13 -
> @@ -707,12 +707,9 @@ arplookup(u_int32_t addr, int create, in
>   flags = (create) ? (RT_REPORT|RT_RESOLVE) : 0;
>  
>   rt = rtalloc((struct sockaddr *), flags, tableid);
> - if (rt == NULL)
> - return (NULL);
> - if ((rt->rt_flags & RTF_GATEWAY) || (rt->rt_flags & RTF_LLINFO) == 0 ||
> + if (!rtisvalid(rt) || ISSET(rt->rt_flags, RTF_GATEWAY) ||
> + !ISSET(rt->rt_flags, RTF_LLINFO) ||
>   rt->rt_gateway->sa_family != AF_LINK) {
> - if (create && (rt->rt_flags & RTF_CLONED))
> - rtdeletemsg(rt, tableid);
>   rtfree(rt);
>   return (NULL);
>   }
> 

-- 
:wq Claudio



pf unlink remove

2015-12-02 Thread Alexander Bluhm
Hi,

So here is the result of the pf unlink bikeshedding.  Rename
pf_unlink_state() to pf_remove_state() so the name does not collide
with the statekey to inp unlinking.

ok?

bluhm

Index: net/if_pfsync.c
===
RCS file: /data/mirror/openbsd/cvs/src/sys/net/if_pfsync.c,v
retrieving revision 1.222
diff -u -p -r1.222 if_pfsync.c
--- net/if_pfsync.c 10 Nov 2015 06:36:14 -  1.222
+++ net/if_pfsync.c 2 Dec 2015 21:29:09 -
@@ -752,7 +752,7 @@ pfsync_in_clr(caddr_t buf, int len, int 
if (st->creatorid == creatorid &&
((kif && st->kif == kif) || !kif)) {
SET(st->state_flags, PFSTATE_NOSYNC);
-   pf_unlink_state(st);
+   pf_remove_state(st);
}
}
}
@@ -1056,7 +1056,7 @@ pfsync_in_del(caddr_t buf, int len, int 
continue;
}
SET(st->state_flags, PFSTATE_NOSYNC);
-   pf_unlink_state(st);
+   pf_remove_state(st);
}
 
return (0);
@@ -1083,7 +1083,7 @@ pfsync_in_del_c(caddr_t buf, int len, in
}
 
SET(st->state_flags, PFSTATE_NOSYNC);
-   pf_unlink_state(st);
+   pf_remove_state(st);
}
 
return (0);
Index: net/pf.c
===
RCS file: /data/mirror/openbsd/cvs/src/sys/net/pf.c,v
retrieving revision 1.954
diff -u -p -r1.954 pf.c
--- net/pf.c2 Dec 2015 16:00:42 -   1.954
+++ net/pf.c2 Dec 2015 21:29:09 -
@@ -668,7 +668,7 @@ pf_state_key_attach(struct pf_state_key 
si->s->dst.state >= TCPS_FIN_WAIT_2) {
si->s->src.state = si->s->dst.state =
TCPS_CLOSED;
-   /* unlink late or sks can go away */
+   /* remove late or sks can go away */
olds = si->s;
} else {
if (pf_status.debug >= LOG_NOTICE) {
@@ -713,7 +713,7 @@ pf_state_key_attach(struct pf_state_key 
TAILQ_INSERT_HEAD(>key[idx]->states, si, entry);
 
if (olds)
-   pf_unlink_state(olds);
+   pf_remove_state(olds);
 
return (0);
 }
@@ -1249,7 +1249,7 @@ pf_src_tree_remove_state(struct pf_state
 
 /* callers should be at splsoftnet */
 void
-pf_unlink_state(struct pf_state *cur)
+pf_remove_state(struct pf_state *cur)
 {
splsoftassert(IPL_SOFTNET);
 
@@ -1280,14 +1280,14 @@ pf_unlink_state(struct pf_state *cur)
 }
 
 void
-pf_unlink_divert_state(struct pf_state_key *sk)
+pf_remove_divert_state(struct pf_state_key *sk)
 {
struct pf_state_item*si;
 
TAILQ_FOREACH(si, >states, entry) {
if (sk == si->s->key[PF_SK_STACK] && si->s->rule.ptr &&
si->s->rule.ptr->divert.port) {
-   pf_unlink_state(si->s);
+   pf_remove_state(si->s);
break;
}
}
@@ -1349,15 +1349,15 @@ pf_purge_expired_states(u_int32_t maxche
next = TAILQ_NEXT(cur, entry_list);
 
if (cur->timeout == PFTM_UNLINKED) {
-   /* free unlinked state */
+   /* free removed state */
if (! locked) {
rw_enter_write(_consistency_lock);
locked = 1;
}
pf_free_state(cur);
} else if (pf_state_expires(cur) <= time_uptime) {
-   /* unlink and free expired state */
-   pf_unlink_state(cur);
+   /* remove and free expired state */
+   pf_remove_state(cur);
if (! locked) {
rw_enter_write(_consistency_lock);
locked = 1;
@@ -4346,7 +4346,7 @@ pf_test_state(struct pf_pdesc *pd, struc
}
/* XXX make sure it's the same direction ?? */
(*state)->src.state = (*state)->dst.state = TCPS_CLOSED;
-   pf_unlink_state(*state);
+   pf_remove_state(*state);
*state = NULL;
pd->m->m_pkthdr.pf.inp = inp;
return (PF_DROP);
Index: net/pf_ioctl.c
===
RCS file: /data/mirror/openbsd/cvs/src/sys/net/pf_ioctl.c,v
retrieving revision 1.294
diff -u -p -r1.294 pf_ioctl.c
--- net/pf_ioctl.c  24 Nov 2015 13:37:16 -  1.294
+++ 

Re: more arp cleanup

2015-12-02 Thread Claudio Jeker
Last but of rt_ifp cleanup. Since we want to print the interface names in
those log messages we need to do the if_get/if_put dance there. Since this
is only in 2 places which should not be super common that should be fine
and with this arp should be MP save :)

-- 
:wq Claudio

Index: if_ether.c
===
RCS file: /cvs/src/sys/netinet/if_ether.c,v
retrieving revision 1.196
diff -u -p -r1.196 if_ether.c
--- if_ether.c  2 Dec 2015 21:09:06 -   1.196
+++ if_ether.c  2 Dec 2015 21:16:14 -
@@ -565,14 +565,19 @@ in_arpinput(struct mbuf *m)
if (ifp->if_type != IFT_CARP)
 #endif
{
+   struct ifnet *rifp = if_get(
+   rt->rt_ifidx);
+   if (rifp == NULL)
+   goto out;
inet_ntop(AF_INET, ,
addr, sizeof(addr));
log(LOG_WARNING, "arp: attempt"
   " to overwrite entry for"
   " %s on %s by %s on %s\n",
-  addr, rt->rt_ifp->if_xname,
+  addr, rifp->if_xname,
   ether_sprintf(ea->arp_sha),
   ifp->if_xname);
+   if_put(rifp);
}
goto out;
} else {
@@ -587,13 +592,17 @@ in_arpinput(struct mbuf *m)
changed = 1;
}
} else if (!if_isconnected(ifp, rt->rt_ifidx)) {
+   struct ifnet *rifp = if_get(rt->rt_ifidx);
+   if (rifp == NULL)
+   goto out;
inet_ntop(AF_INET, , addr, sizeof(addr));
log(LOG_WARNING,
"arp: attempt to add entry for %s "
"on %s by %s on %s\n", addr,
-   rt->rt_ifp->if_xname,
+   rifp->if_xname,
ether_sprintf(ea->arp_sha),
ifp->if_xname);
+   if_put(rifp);
goto out;
}
sdl->sdl_alen = sizeof(ea->arp_sha);




Pledge `dns' in httpd(8)

2015-12-02 Thread Gregor Best
Hi people,

httpd needs to pledge `dns' for name resolution to work while loading
the configuration:

# cat /tmp/test.conf
server "default" {
listen on imnotlocal port 80
}
# httpd -dnvf /tmp/test.conf
Abort trap
# dmesg | tail -n1
httpd(18331): syscall 97 "dns"

The issue is that `imnotlocal' is not a hostname that can be looked
up without DNS requests. `localhost' and entries in /etc/hosts work
fine for example. The attached patch adds `dns' to the pledge list
in httpd.c.

-- 
Gregor

Index: httpd.c
===
RCS file: /mnt/media/cvs/src/usr.sbin/httpd/httpd.c,v
retrieving revision 1.50
diff -u -p -r1.50 httpd.c
--- httpd.c 23 Nov 2015 20:56:14 -  1.50
+++ httpd.c 2 Dec 2015 21:11:49 -
@@ -251,7 +251,8 @@ main(int argc, char *argv[])
setproctitle("parent");
log_procinit("parent");
 
-   if (pledge("stdio rpath wpath cpath inet proc ioctl sendfd",
+   /* dns is required for load_config */
+   if (pledge("stdio rpath wpath cpath inet proc ioctl dns sendfd",
NULL) == -1)
fatal("pledge");
 



IPsec: remove DES support

2015-12-02 Thread Christian Weisgerber
Quoth ipsec.conf(5):
Use of DES as an encryption algorithm is considered to be insecure since
brute force attacks are practical due its short key length.

The attached patch removes support for DES-CBC encryption in ESP
and in IKE main and quick mode from the kernel, iked(8), ipsecctl(8),
and isakmpd(8).

Note this is plain DES, *not* 3DES.

RFC2409 (November 1998) says that DES support is a "MUST" for IKEv1,
but I think we _must_ ignore this.


Next I intend to remove DES from the kernel crypto framework.


Index: sys/net/pfkeyv2.c
===
RCS file: /cvs/src/sys/net/pfkeyv2.c,v
retrieving revision 1.145
diff -u -p -r1.145 pfkeyv2.c
--- sys/net/pfkeyv2.c   17 Jul 2015 18:31:08 -  1.145
+++ sys/net/pfkeyv2.c   2 Dec 2015 22:13:21 -
@@ -103,7 +103,6 @@ static int npromisc = 0;
 
 static const struct sadb_alg ealgs[] = {
{ SADB_EALG_NULL, 0, 0, 0 },
-   { SADB_EALG_DESCBC, 64, 64, 64 },
{ SADB_EALG_3DESCBC, 64, 192, 192 },
{ SADB_X_EALG_BLF, 64, 40, BLF_MAXKEYLEN * 8},
{ SADB_X_EALG_CAST, 64, 40, 128},
@@ -1848,11 +1847,6 @@ pfkeyv2_acquire(struct ipsec_policy *ipo
sadb_comb->sadb_comb_encrypt = 
SADB_EALG_3DESCBC;
sadb_comb->sadb_comb_encrypt_minbits = 192;
sadb_comb->sadb_comb_encrypt_maxbits = 192;
-   } else if (!strncasecmp(ipsec_def_enc, "des",
-   sizeof("des"))) {
-   sadb_comb->sadb_comb_encrypt = SADB_EALG_DESCBC;
-   sadb_comb->sadb_comb_encrypt_minbits = 64;
-   sadb_comb->sadb_comb_encrypt_maxbits = 64;
} else if (!strncasecmp(ipsec_def_enc, "blowfish",
sizeof("blowfish"))) {
sadb_comb->sadb_comb_encrypt = SADB_X_EALG_BLF;
Index: sys/net/pfkeyv2.h
===
RCS file: /cvs/src/sys/net/pfkeyv2.h,v
retrieving revision 1.71
diff -u -p -r1.71 pfkeyv2.h
--- sys/net/pfkeyv2.h   2 Dec 2015 12:43:59 -   1.71
+++ sys/net/pfkeyv2.h   2 Dec 2015 22:11:46 -
@@ -296,7 +296,6 @@ struct sadb_x_tap {
 #define SADB_AALG_MAX12
 
 #define SADB_EALG_NONE0
-#define SADB_EALG_DESCBC  2
 #define SADB_EALG_3DESCBC 3
 #define SADB_X_EALG_CAST  6
 #define SADB_X_EALG_BLF   7
Index: sys/net/pfkeyv2_convert.c
===
RCS file: /cvs/src/sys/net/pfkeyv2_convert.c,v
retrieving revision 1.56
diff -u -p -r1.56 pfkeyv2_convert.c
--- sys/net/pfkeyv2_convert.c   3 Nov 2015 01:50:36 -   1.56
+++ sys/net/pfkeyv2_convert.c   2 Dec 2015 22:12:19 -
@@ -228,10 +228,6 @@ export_sa(void **p, struct tdb *tdb)
sadb_sa->sadb_sa_encrypt = SADB_EALG_NULL;
break;
 
-   case CRYPTO_DES_CBC:
-   sadb_sa->sadb_sa_encrypt = SADB_EALG_DESCBC;
-   break;
-
case CRYPTO_3DES_CBC:
sadb_sa->sadb_sa_encrypt = SADB_EALG_3DESCBC;
break;
Index: sys/netinet/ip_esp.c
===
RCS file: /cvs/src/sys/netinet/ip_esp.c,v
retrieving revision 1.135
diff -u -p -r1.135 ip_esp.c
--- sys/netinet/ip_esp.c3 Nov 2015 01:50:36 -   1.135
+++ sys/netinet/ip_esp.c2 Dec 2015 22:11:23 -
@@ -111,10 +111,6 @@ esp_init(struct tdb *tdbp, struct xforms
txform = _xform_null;
break;
 
-   case SADB_EALG_DESCBC:
-   txform = _xform_des;
-   break;
-
case SADB_EALG_3DESCBC:
txform = _xform_3des;
break;
Index: sbin/iked/iked.conf.5
===
RCS file: /cvs/src/sbin/iked/iked.conf.5,v
retrieving revision 1.43
diff -u -p -r1.43 iked.conf.5
--- sbin/iked/iked.conf.5   4 Nov 2015 12:40:49 -   1.43
+++ sbin/iked/iked.conf.5   2 Dec 2015 21:38:05 -
@@ -757,7 +757,6 @@ The following cipher types are permitted
 keyword:
 .Bl -column "chacha20-poly1305" "Key Length" "[ESP only]" -offset indent
 .It Em "Cipher" Ta Em "Key Length" Ta ""
-.It Li des Ta "56 bits" Ta "[ESP only]"
 .It Li 3des Ta "168 bits" Ta ""
 .It Li aes-128 Ta "128 bits" Ta ""
 .It Li aes-192 Ta "192 bits" Ta ""
@@ -782,11 +781,7 @@ not encryption:
 .It Li null Ta "" Ta "[ESP only]"
 .El
 .Pp
-Use of DES as an encryption algorithm is considered to be insecure
-since brute force attacks are practical due its short key length.
-.Pp
-DES requires 8 bytes to form a 56-bit key and 3DES requires 24 bytes
-to form its 168-bit key.
+3DES requires 24 bytes to form 

Re: more arp cleanup

2015-12-02 Thread Alexander Bluhm
On Wed, Dec 02, 2015 at 10:19:23PM +0100, Claudio Jeker wrote:
> Last but of rt_ifp cleanup. Since we want to print the interface names in
> those log messages we need to do the if_get/if_put dance there. Since this
> is only in 2 places which should not be super common that should be fine
> and with this arp should be MP save :)

OK bluhm@

> 
> -- 
> :wq Claudio
> 
> Index: if_ether.c
> ===
> RCS file: /cvs/src/sys/netinet/if_ether.c,v
> retrieving revision 1.196
> diff -u -p -r1.196 if_ether.c
> --- if_ether.c2 Dec 2015 21:09:06 -   1.196
> +++ if_ether.c2 Dec 2015 21:16:14 -
> @@ -565,14 +565,19 @@ in_arpinput(struct mbuf *m)
>   if (ifp->if_type != IFT_CARP)
>  #endif
>   {
> + struct ifnet *rifp = if_get(
> + rt->rt_ifidx);
> + if (rifp == NULL)
> + goto out;
>   inet_ntop(AF_INET, ,
>   addr, sizeof(addr));
>   log(LOG_WARNING, "arp: attempt"
>  " to overwrite entry for"
>  " %s on %s by %s on %s\n",
> -addr, rt->rt_ifp->if_xname,
> +addr, rifp->if_xname,
>  ether_sprintf(ea->arp_sha),
>  ifp->if_xname);
> + if_put(rifp);
>   }
>   goto out;
>   } else {
> @@ -587,13 +592,17 @@ in_arpinput(struct mbuf *m)
>   changed = 1;
>   }
>   } else if (!if_isconnected(ifp, rt->rt_ifidx)) {
> + struct ifnet *rifp = if_get(rt->rt_ifidx);
> + if (rifp == NULL)
> + goto out;
>   inet_ntop(AF_INET, , addr, sizeof(addr));
>   log(LOG_WARNING,
>   "arp: attempt to add entry for %s "
>   "on %s by %s on %s\n", addr,
> - rt->rt_ifp->if_xname,
> + rifp->if_xname,
>   ether_sprintf(ea->arp_sha),
>   ifp->if_xname);
> + if_put(rifp);
>   goto out;
>   }
>   sdl->sdl_alen = sizeof(ea->arp_sha);



Re: more arp cleanup

2015-12-02 Thread Martin Pieuchot
On 02/12/15(Wed) 22:19, Claudio Jeker wrote:
> Last but of rt_ifp cleanup. Since we want to print the interface names in
> those log messages we need to do the if_get/if_put dance there. Since this
> is only in 2 places which should not be super common that should be fine
> and with this arp should be MP save :)

ok mpi@

> 
> -- 
> :wq Claudio
> 
> Index: if_ether.c
> ===
> RCS file: /cvs/src/sys/netinet/if_ether.c,v
> retrieving revision 1.196
> diff -u -p -r1.196 if_ether.c
> --- if_ether.c2 Dec 2015 21:09:06 -   1.196
> +++ if_ether.c2 Dec 2015 21:16:14 -
> @@ -565,14 +565,19 @@ in_arpinput(struct mbuf *m)
>   if (ifp->if_type != IFT_CARP)
>  #endif
>   {
> + struct ifnet *rifp = if_get(
> + rt->rt_ifidx);
> + if (rifp == NULL)
> + goto out;
>   inet_ntop(AF_INET, ,
>   addr, sizeof(addr));
>   log(LOG_WARNING, "arp: attempt"
>  " to overwrite entry for"
>  " %s on %s by %s on %s\n",
> -addr, rt->rt_ifp->if_xname,
> +addr, rifp->if_xname,
>  ether_sprintf(ea->arp_sha),
>  ifp->if_xname);
> + if_put(rifp);
>   }
>   goto out;
>   } else {
> @@ -587,13 +592,17 @@ in_arpinput(struct mbuf *m)
>   changed = 1;
>   }
>   } else if (!if_isconnected(ifp, rt->rt_ifidx)) {
> + struct ifnet *rifp = if_get(rt->rt_ifidx);
> + if (rifp == NULL)
> + goto out;
>   inet_ntop(AF_INET, , addr, sizeof(addr));
>   log(LOG_WARNING,
>   "arp: attempt to add entry for %s "
>   "on %s by %s on %s\n", addr,
> - rt->rt_ifp->if_xname,
> + rifp->if_xname,
>   ether_sprintf(ea->arp_sha),
>   ifp->if_xname);
> + if_put(rifp);
>   goto out;
>   }
>   sdl->sdl_alen = sizeof(ea->arp_sha);
> 



preparing multitouch support - request for tests

2015-12-02 Thread Ulf Brosziewski

The diffs below contain a complete and extensive rewrite of the
input-processing parts of wsmouse and the interface it provides to
the hardware drivers. It prepares the support for various kinds of
multitouch input, as well as an extended support for touchpads by
wsmouse.

Tests for regression with all kinds of "pointing devices" would be
welcome. Only a small set of touchpads and USB mice is available to
me, which is a somewhat uncomfortable situation when you are working
on things like this.

Please note that the first diff is for the synaptics driver in
xenocara, the rest is for the kernel. Patching that driver will be
necessary if you test with touchpads (and compiling it requires
the modified version of wsconsio.h in /usr/include/dev/wscons/).

In most drivers I have made only short and trivial changes, the
Elantech-v4 part of pms is the only one that makes full use of the
new MT functions.

Unlike the basic input layer, which I hope is already fairly stable,
the in-kernel touchpad support is in a more experimental stage. If
you have a Synaptics, ALPS, or Elantech-v4 touchpad, you could test
it by adding this xorg.conf to /etc:

Section "InputClass"
Identifier "wstpad"
Driver "ws"
MatchIsTouchPad "true"
EndSection

Only a default configuration will be available with this. It enables
two-finger-scrolling and a lower soft-button area for clickpads, and
two-finger- or edge-scrolling for touchpads (support for tapping and
upper soft-button areas is implemented, but it won't be enabled by
the automatic configuration). If this works, it would also be
interesting for me to know whether the defaults for pointer speed
and acceleration are decent.

Of course I'm not only interested in tests. Questions, comments,
suggestions, and any kind of help would also be welcome.



Index: src/wsconscomm.c
===
RCS file: /cvs/xenocara/driver/xf86-input-synaptics/src/wsconscomm.c,v
retrieving revision 1.13
diff -u -p -r1.13 wsconscomm.c
--- src/wsconscomm.c29 Aug 2015 08:48:28 -  1.13
+++ src/wsconscomm.c1 Dec 2015 22:40:15 -
@@ -215,45 +215,29 @@ WSConsReadHwState(InputInfoPtr pInfo,
 hw->y = priv->maxy - event->value + priv->miny;
 hw->cumulative_dy = hw->y;
 break;
-case WSCONS_EVENT_MOUSE_ABSOLUTE_Z:
+case WSCONS_EVENT_TOUCH_PRESSURE:
 hw->z = event->value;
 break;
-case WSCONS_EVENT_MOUSE_ABSOLUTE_W:
-if (priv->model == MODEL_ELANTECH) {
-/* Elantech touchpads report number of fingers directly. */
-hw->fingerWidth = 5;
-hw->numFingers = event->value;
-break;
-}
-/* XXX magic number mapping which is mirrored in pms driver */
 -switch (event->value) {
-case 0:
-hw->fingerWidth = 5;
-hw->numFingers = 2;
-break;
-case 1:
+case WSCONS_EVENT_TOUCH_FINGERS:
+hw->numFingers = event->value;
+if (hw->numFingers == 0)
+hw->fingerWidth = 0;
+else if (hw->fingerWidth == 0)
 hw->fingerWidth = 5;
-hw->numFingers = 3;
-break;
-case 4 ... 5:
-hw->fingerWidth = event->value;
-hw->numFingers = 1;
-break;
-}
+break;
+case WSCONS_EVENT_TOUCH_WIDTH:
+hw->fingerWidth = event->value;
+break;
+case WSCONS_EVENT_TOUCH_UPDATE:
+/*
+ * The finger count or the active MT-slot has changed.
+ * Suppress pointer motion and two-finger scrolling.
+ */
+priv->count_packet_finger = 0;
+priv->vert_scroll_twofinger_on = FALSE;
+priv->horiz_scroll_twofinger_on = FALSE;
 break;
 case WSCONS_EVENT_SYNC:
-if (hw->z == 0) {
-hw->fingerWidth = 0;
-hw->numFingers = 0;
-} else if (hw->numFingers == 0) {
-/*
- * Because W may be 0 already, a two-finger touch on a
- * Synaptics touchpad doesn't necessarily produce an update
- * event for W.
- */
-hw->fingerWidth = 5;
-hw->numFingers = 2;
-}
 hw->millis = 1000 * event->time.tv_sec +
 event->time.tv_nsec / 100;
 SynapticsCopyHwState(hwRet, hw);


Index: arch/i386/isa/lms.c
===
RCS file: /cvs/src/sys/arch/i386/isa/lms.c,v
retrieving revision 1.20
diff -u -p -r1.20 lms.c
--- arch/i386/isa/lms.c 10 Apr 2007 22:37:17 -  1.20
+++ arch/i386/isa/lms.c 1 Dec 2015 22:17:41 -
@@ -36,6 +36,7 @@

 #include 
 #include 
+#include 

 #define

Re: pf unlink remove

2015-12-02 Thread Alexandr Nedvedicky
Hello,

OK

sasha



Re: unifdef(1) - in-place editing without backups

2015-12-02 Thread Michael McConville
Stuart Henderson wrote:
> On 2015/12/02 00:04, Michael McConville wrote:
> > unifdef's -M option is like sed's -i option, editing in-place and
> > saving a backup with the supplied extension.
> 
> There is an upstream for unifdef: http://dotat.at/prog/unifdef/
> Please talk to Tony Finch and see if he'll take the diff; it's helpful
> to not diverge too much.

Thanks for this.

I emailed Tony, who said he's planning on committing it tomorrow. For
unrelated reasons, though, he said there probably won't be another
release soon. Do you mind if I commit?



Re: bridge(4) never outputs packets

2015-12-02 Thread Reyk Floeter
On Wed, Dec 02, 2015 at 09:57:59AM +0100, Martin Pieuchot wrote:
> Make sure if_output() and if_start() will never be called for the
> bridge(4).
> 
> Concerns?
> 

You should clarify in the comment above the actual bridge_output()
function that this function is intended to be used by bridgeport /
member interfaces only and not the bridge itself.  "Send output from
the bridge." is a bit misleading.

Otherwise OK

Reyk

> Index: net/if_bridge.c
> ===
> RCS file: /cvs/src/sys/net/if_bridge.c,v
> retrieving revision 1.273
> diff -u -p -r1.273 if_bridge.c
> --- net/if_bridge.c   2 Dec 2015 08:04:12 -   1.273
> +++ net/if_bridge.c   2 Dec 2015 08:07:38 -
> @@ -111,7 +111,6 @@
>  void bridgeattach(int);
>  int  bridge_ioctl(struct ifnet *, u_long, caddr_t);
>  int  bridge_input(struct ifnet *, struct mbuf *, void *);
> -void bridge_start(struct ifnet *);
>  void bridge_process(struct ifnet *, struct mbuf *);
>  void bridgeintr_frame(struct bridge_softc *, struct ifnet *, struct mbuf *);
>  void bridge_broadcast(struct bridge_softc *, struct ifnet *,
> @@ -189,8 +188,8 @@ bridge_clone_create(struct if_clone *ifc
>   ifp->if_softc = sc;
>   ifp->if_mtu = ETHERMTU;
>   ifp->if_ioctl = bridge_ioctl;
> - ifp->if_output = bridge_output;
> - ifp->if_start = bridge_start;
> + ifp->if_output = NULL;
> + ifp->if_start = NULL;
>   ifp->if_type = IFT_BRIDGE;
>   ifp->if_hdrlen = ETHER_HDR_LEN;
>  
> @@ -830,14 +829,6 @@ sendunicast:
>   }
>   bridge_ifenqueue(sc, dst_if, m);
>   return (0);
> -}
> -
> -/*
> - * Start output on the bridge.  This function should never be called.
> - */
> -void
> -bridge_start(struct ifnet *ifp)
> -{
>  }
>  
>  /*
> 

-- 



Re: Dumb arplookup()

2015-12-02 Thread Stuart Henderson
On 2015/12/02 09:44, Martin Pieuchot wrote:
> If the kernel tries to create (cloned) an ARP entry and found an
> existing conflicting route, do not try to be clever and just bail.
> 
> I'm fine with rtalloc(9) taking the KERNEL_LOCK when cloning an entry
> but I'd prefer the ARP layer to not try to delete anything in the hot
> path.
> 
> If you entered a conflicting entry in your routing table, that's your
> problem, you deal with it.
> 
> Ok?

Just trying to think it through a bit:

Where are these conflicting routes going to come from, if you already have
a RTF_GATEWAY route it's not going to need to ARP for that address is it?
Is this something to do with ICMP redirects?

It would be nice to recreate the conditions that cause it to make sure that
this doesn't result in an ARP storm if the new entry can't be added and we
keep on trying to resolve it.


> Index: netinet/if_ether.c
> ===
> RCS file: /cvs/src/sys/netinet/if_ether.c,v
> retrieving revision 1.191
> diff -u -p -r1.191 if_ether.c
> --- netinet/if_ether.c1 Dec 2015 12:22:18 -   1.191
> +++ netinet/if_ether.c2 Dec 2015 08:40:13 -
> @@ -707,12 +707,9 @@ arplookup(u_int32_t addr, int create, in
>   flags = (create) ? (RT_REPORT|RT_RESOLVE) : 0;
>  
>   rt = rtalloc((struct sockaddr *), flags, tableid);
> - if (rt == NULL)
> - return (NULL);
> - if ((rt->rt_flags & RTF_GATEWAY) || (rt->rt_flags & RTF_LLINFO) == 0 ||
> + if (!rtisvalid(rt) || ISSET(rt->rt_flags, RTF_GATEWAY) ||
> + !ISSET(rt->rt_flags, RTF_LLINFO) ||
>   rt->rt_gateway->sa_family != AF_LINK) {
> - if (create && (rt->rt_flags & RTF_CLONED))
> - rtdeletemsg(rt, tableid);
>   rtfree(rt);
>   return (NULL);
>   }
> 



Re: Dumb arplookup()

2015-12-02 Thread Martin Pieuchot
On 02/12/15(Wed) 09:26, Stuart Henderson wrote:
> On 2015/12/02 09:44, Martin Pieuchot wrote:
> > If the kernel tries to create (cloned) an ARP entry and found an
> > existing conflicting route, do not try to be clever and just bail.
> > 
> > I'm fine with rtalloc(9) taking the KERNEL_LOCK when cloning an entry
> > but I'd prefer the ARP layer to not try to delete anything in the hot
> > path.
> > 
> > If you entered a conflicting entry in your routing table, that's your
> > problem, you deal with it.
> > 
> > Ok?
> 
> Just trying to think it through a bit:
> 
> Where are these conflicting routes going to come from, if you already have
> a RTF_GATEWAY route it's not going to need to ARP for that address is it?
> Is this something to do with ICMP redirects?
> 
> It would be nice to recreate the conditions that cause it to make sure that
> this doesn't result in an ARP storm if the new entry can't be added and we
> keep on trying to resolve it.

But the entry *is* added, just from a wrong RTF_CLONING route.

It's easy to reproduce, you can simply do:

# route add 192.168.0/24 -cloning -gateway 192.168.0.5 -priority 3

Assuming that 192.168.0/24 is already your cloning route.  After
cleaning your ARP cache you'll still get RTF_CLONED routes from
this higher priority route and this code below won't solve anything
because they're still being recreated.



doas password prompt

2015-12-02 Thread Ted Unangst
henning points out that if you are seven levels deep when doas asks for a
password, it can be hard to tell who is asking for what password.

modify the prompt to include the program name and user@host.

Index: doas.c
===
RCS file: /cvs/src/usr.bin/doas/doas.c,v
retrieving revision 1.45
diff -u -p -r1.45 doas.c
--- doas.c  24 Oct 2015 19:23:48 -  1.45
+++ doas.c  2 Dec 2015 09:36:05 -
@@ -21,6 +21,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -323,7 +324,7 @@ main(int argc, char **argv, char **envp)
char cwdpath[PATH_MAX];
const char *cwd;
 
-   if (pledge("stdio rpath getpw proc exec id", NULL) == -1)
+   if (pledge("stdio rpath getpw tty proc exec id", NULL) == -1)
err(1, "pledge");
 
closefrom(STDERR_FILENO + 1);
@@ -405,11 +406,27 @@ main(int argc, char **argv, char **envp)
}
 
if (!(rule->options & NOPASS)) {
+   char *challenge = NULL, *response, rbuf[1024], cbuf[128];
+   auth_session_t *as;
+
if (nflag)
errx(1, "Authorization required");
-   if (!auth_userokay(myname, NULL, "auth-doas", NULL)) {
+
+   if (!(as = auth_userchallenge(myname, NULL, "auth-doas",
+   )))
+   err(1, "auth challenge failed");
+   if (!challenge) {
+   char host[HOST_NAME_MAX + 1];
+   if (gethostname(host, sizeof(host)))
+   snprintf(host, sizeof(host), "?");
+   snprintf(cbuf, sizeof(cbuf),
+   "doas (%.32s@%.32s) password: ", myname, host);
+   challenge = cbuf;
+   }
+   response = readpassphrase(challenge, rbuf, sizeof(rbuf), 0);
+   if (!auth_userresponse(as, response, 0)) {
syslog(LOG_AUTHPRIV | LOG_NOTICE,
-   "failed password for %s", myname);
+   "failed auth for %s", myname);
errc(1, EPERM, NULL);
}
}



Re: Completely disable 2D acceleration on Broadwell

2015-12-02 Thread Jonathan Gray
On Wed, Dec 02, 2015 at 10:16:21AM +0100, Peter Hessler wrote:
> On 2015 Dec 02 (Wed) at 17:13:32 +1100 (+1100), Jonathan Gray wrote:
> :On Tue, Dec 01, 2015 at 04:44:39PM +0100, Mark Kettenis wrote:
> :> As tedu@ reported (and some pople on misc@ confirmed) partly disabling
> :> 2D acceleration on Broadwell made X unstable.  It really looks like
> :> the alternative BLT path isn't well tested and therefore buggy.  So
> :> here is a diff that disables 2D acceleration completely.  Those who
> :> don't care about suspend/resume can still enable it if they want.  3D
> :> acceleration should continue to work.
> :> 
> :> ok?
> :
> :chrome and mplayer seem basically unuseable with this.  Perhaps it
> :should be those who want to suspend/resume can run the modesetting
> :driver or disable acceleration via xorg.conf.
> :
> 
> mplayer with vo=gl or with vo=xv?

Both, no scaling with xv either.



Re: Dumb arplookup()

2015-12-02 Thread Claudio Jeker
On Wed, Dec 02, 2015 at 09:26:35AM +, Stuart Henderson wrote:
> On 2015/12/02 09:44, Martin Pieuchot wrote:
> > If the kernel tries to create (cloned) an ARP entry and found an
> > existing conflicting route, do not try to be clever and just bail.
> > 
> > I'm fine with rtalloc(9) taking the KERNEL_LOCK when cloning an entry
> > but I'd prefer the ARP layer to not try to delete anything in the hot
> > path.
> > 
> > If you entered a conflicting entry in your routing table, that's your
> > problem, you deal with it.
> > 
> > Ok?
> 
> Just trying to think it through a bit:
> 
> Where are these conflicting routes going to come from, if you already have
> a RTF_GATEWAY route it's not going to need to ARP for that address is it?
> Is this something to do with ICMP redirects?
> 
> It would be nice to recreate the conditions that cause it to make sure that
> this doesn't result in an ARP storm if the new entry can't be added and we
> keep on trying to resolve it.
> 

Mpi and I came to the conclusion that it should be impossible to get into
this case because you would need to clone this route from a route with a
gateway which is not really possible and so this feels a bit like belts
and suspenders here.

If you can manage to create this condition (cloned route with a gateway or
no llinfo connected) then I would like to know how :)

> 
> > Index: netinet/if_ether.c
> > ===
> > RCS file: /cvs/src/sys/netinet/if_ether.c,v
> > retrieving revision 1.191
> > diff -u -p -r1.191 if_ether.c
> > --- netinet/if_ether.c  1 Dec 2015 12:22:18 -   1.191
> > +++ netinet/if_ether.c  2 Dec 2015 08:40:13 -
> > @@ -707,12 +707,9 @@ arplookup(u_int32_t addr, int create, in
> > flags = (create) ? (RT_REPORT|RT_RESOLVE) : 0;
> >  
> > rt = rtalloc((struct sockaddr *), flags, tableid);
> > -   if (rt == NULL)
> > -   return (NULL);
> > -   if ((rt->rt_flags & RTF_GATEWAY) || (rt->rt_flags & RTF_LLINFO) == 0 ||
> > +   if (!rtisvalid(rt) || ISSET(rt->rt_flags, RTF_GATEWAY) ||
> > +   !ISSET(rt->rt_flags, RTF_LLINFO) ||
> > rt->rt_gateway->sa_family != AF_LINK) {
> > -   if (create && (rt->rt_flags & RTF_CLONED))
> > -   rtdeletemsg(rt, tableid);
> > rtfree(rt);
> > return (NULL);
> > }
> > 
> 

-- 
:wq Claudio



Re: bridge(4) never outputs packets

2015-12-02 Thread Martin Pieuchot
On 02/12/15(Wed) 10:25, Claudio Jeker wrote:
> On Wed, Dec 02, 2015 at 09:57:59AM +0100, Martin Pieuchot wrote:
> > Make sure if_output() and if_start() will never be called for the
> > bridge(4).
> > 
> > Concerns?
> 
> Why not use if_detached_start()? There is no if_detached_output() but we
> could add that as well. I would prefer that over NULL pointers that may
> get hit.

I'd like to get rid of if_detached_start(), hit the NULL pointers and
fix the bugs.



Re: serialise if_start calls

2015-12-02 Thread David Gwynne

> On 30 Nov 2015, at 9:55 PM, David Gwynne  wrote:
> 
> this tweaks the guts of if_start so it guarantees that there's only
> ever one call to ifp->if_start running in the system at a time.
> previously this was implicit because it could only be called with
> the KERNEL_LOCK held.
> 
> as we move forward it would be nice to run the queue without having
> to take the biglock. however, because we also want to dequeue the
> packets in order, it only makes sense to run a single instance of
> the function in the whole system.
> 
> also, if a driver is recovering from an oactive situation (ie, it's
> been able to free space on the tx ring) it should be able to start
> tx again from an mpsafe interrupt context.
> 
> because most of our drivers assume that theyre run under the
> KERNEL_LOCK, this diff uses a flag for the internals of the if_start
> call to differentiate between them. it defaults for kernel locked,
> but drivers can opt in to an mpsafe version that can call ifp->if_start
> without the mplock held.
> 
> the kernel locked code takes KERNEL_LOCK and splnet before calling
> ifp->if_start.
> 
> the mpsafe code uses the serialisation mechanism that the scsi
> midlayer and pool runqueue use, but implemented with atomics instead
> of operations under a mutex.
> 
> the semantic is that work will be queued onto a list protected by
> a mutex (ie, the guts of struct ifqueue), and then a cpu will try
> to enter a critical section that runs a function to service the
> queued work. the cpu that enters the critical section has to dequeue
> work in a loop, which is what all our drivers do.
> 
> if another cpu tries to enter the same critical section after
> queueing more work, it will return immediately rather than spin on
> the lock. the first cpu that is currently dequeueing work in the
> critical section will be told to spin again to guarantee that it
> will service the work the other cpu added.
> 
> so the network stack may be transmitting packets on cpu1, while an
> interrupts on cpu0 occurs which frees up tx descriprots. if cpu0
> calls if_start, it will return immediately because cpu1 will end
> up doing the work it wanted to do anyway.
> 
> if the start routine can run on multiple cpus, then it becomes
> necessary to know it is NOT running anymore when tearing a nic down.
> to that end i have added an if_start_barrier function. an mpsafe
> driver can call that when it's being brought down to guarantee that
> another cpu isnt fiddling with the tx ring before freeing it.
> 
> a driver opts in to the mpsafe if_start call by doing the following:
> 
> 1. set ifp->if_xflags = IFXF_MPSAFE.
> 2. calling if_start() instead of its own start routine (eg, myx_start).
> 3. clearing IFF_RUNNING before calling if_start_barrier() on its way down.
> 4. only using IFQ_DEQUEUE (not ifq_deq_begin/commit/rollback)
> 
> anyway, this is the diff i have come up with after playing with
> several ideas. it removes the IFXF_TXREADY semantics, ie, tx
> mitigation and reuses the flag bit for IFXF_MPSAFE.
> 
> the reason for that is juggling or deferring the start routine made
> if_start_barrier annoyingly complicated, and all my attmepts at it
> introduced a significant performance hit or were insanely complicated.
> 
> tx mitigation only ever gave me back 5 to 10% before it was badly
> tweaked, and we've made a lot of other performance improvements
> since then. while im sad to see it go, id rather move forward than
> dwell on it.
> 
> in the future i would like to try delegating the work to mpsafe
> taskqs, but in my attempts i lost something like 30% of my tx rate
> by doing that. id like to investigate that further in the future,
> just not right now.
> 
> finally, the last thing to consider is lock ordering problems.
> because contention on the ifq_serializer causes the second context
> to return imediately (that's true even if you call if_start from
> within a critical section), i think all the problems are avoided.
> i am more concerned with the ifq mutex than i am with the serialiser.
> 
> anyway, here's the diff to look at. happy to discuss further.
> 
> tests would be welcome too.

no tests? no opinions?



Re: bridge(4) never outputs packets

2015-12-02 Thread Claudio Jeker
On Wed, Dec 02, 2015 at 09:57:59AM +0100, Martin Pieuchot wrote:
> Make sure if_output() and if_start() will never be called for the
> bridge(4).
> 
> Concerns?

Why not use if_detached_start()? There is no if_detached_output() but we
could add that as well. I would prefer that over NULL pointers that may
get hit.
 
> Index: net/if_bridge.c
> ===
> RCS file: /cvs/src/sys/net/if_bridge.c,v
> retrieving revision 1.273
> diff -u -p -r1.273 if_bridge.c
> --- net/if_bridge.c   2 Dec 2015 08:04:12 -   1.273
> +++ net/if_bridge.c   2 Dec 2015 08:07:38 -
> @@ -111,7 +111,6 @@
>  void bridgeattach(int);
>  int  bridge_ioctl(struct ifnet *, u_long, caddr_t);
>  int  bridge_input(struct ifnet *, struct mbuf *, void *);
> -void bridge_start(struct ifnet *);
>  void bridge_process(struct ifnet *, struct mbuf *);
>  void bridgeintr_frame(struct bridge_softc *, struct ifnet *, struct mbuf *);
>  void bridge_broadcast(struct bridge_softc *, struct ifnet *,
> @@ -189,8 +188,8 @@ bridge_clone_create(struct if_clone *ifc
>   ifp->if_softc = sc;
>   ifp->if_mtu = ETHERMTU;
>   ifp->if_ioctl = bridge_ioctl;
> - ifp->if_output = bridge_output;
> - ifp->if_start = bridge_start;
> + ifp->if_output = NULL;
> + ifp->if_start = NULL;
>   ifp->if_type = IFT_BRIDGE;
>   ifp->if_hdrlen = ETHER_HDR_LEN;
>  
> @@ -830,14 +829,6 @@ sendunicast:
>   }
>   bridge_ifenqueue(sc, dst_if, m);
>   return (0);
> -}
> -
> -/*
> - * Start output on the bridge.  This function should never be called.
> - */
> -void
> -bridge_start(struct ifnet *ifp)
> -{
>  }
>  
>  /*
> 

-- 
:wq Claudio



Re: Completely disable 2D acceleration on Broadwell

2015-12-02 Thread Ted Unangst
Peter Hessler wrote:
> On 2015 Dec 02 (Wed) at 17:13:32 +1100 (+1100), Jonathan Gray wrote:
> :On Tue, Dec 01, 2015 at 04:44:39PM +0100, Mark Kettenis wrote:
> :> As tedu@ reported (and some pople on misc@ confirmed) partly disabling
> :> 2D acceleration on Broadwell made X unstable.  It really looks like
> :> the alternative BLT path isn't well tested and therefore buggy.  So
> :> here is a diff that disables 2D acceleration completely.  Those who
> :> don't care about suspend/resume can still enable it if they want.  3D
> :> acceleration should continue to work.
> :> 
> :> ok?
> :
> :chrome and mplayer seem basically unuseable with this.  Perhaps it
> :should be those who want to suspend/resume can run the modesetting
> :driver or disable acceleration via xorg.conf.
> :
> 
> mplayer with vo=gl or with vo=xv?

the previous diff that supposedly left 3d accel enabled actually made glxgears
and vo=gl hang immediately and display nothing for me.



Re: serialise if_start calls

2015-12-02 Thread Martin Pieuchot
On 02/12/15(Wed) 20:38, David Gwynne wrote:
> 
> > On 30 Nov 2015, at 9:55 PM, David Gwynne  wrote:
> > 
> > this tweaks the guts of if_start so it guarantees that there's only
> > ever one call to ifp->if_start running in the system at a time.
> > previously this was implicit because it could only be called with
> > the KERNEL_LOCK held.
> > 
> > as we move forward it would be nice to run the queue without having
> > to take the biglock. however, because we also want to dequeue the
> > packets in order, it only makes sense to run a single instance of
> > the function in the whole system.
> > 
> > also, if a driver is recovering from an oactive situation (ie, it's
> > been able to free space on the tx ring) it should be able to start
> > tx again from an mpsafe interrupt context.
> > 
> > because most of our drivers assume that theyre run under the
> > KERNEL_LOCK, this diff uses a flag for the internals of the if_start
> > call to differentiate between them. it defaults for kernel locked,
> > but drivers can opt in to an mpsafe version that can call ifp->if_start
> > without the mplock held.
> > 
> > the kernel locked code takes KERNEL_LOCK and splnet before calling
> > ifp->if_start.
> > 
> > the mpsafe code uses the serialisation mechanism that the scsi
> > midlayer and pool runqueue use, but implemented with atomics instead
> > of operations under a mutex.
> > 
> > the semantic is that work will be queued onto a list protected by
> > a mutex (ie, the guts of struct ifqueue), and then a cpu will try
> > to enter a critical section that runs a function to service the
> > queued work. the cpu that enters the critical section has to dequeue
> > work in a loop, which is what all our drivers do.
> > 
> > if another cpu tries to enter the same critical section after
> > queueing more work, it will return immediately rather than spin on
> > the lock. the first cpu that is currently dequeueing work in the
> > critical section will be told to spin again to guarantee that it
> > will service the work the other cpu added.
> > 
> > so the network stack may be transmitting packets on cpu1, while an
> > interrupts on cpu0 occurs which frees up tx descriprots. if cpu0
> > calls if_start, it will return immediately because cpu1 will end
> > up doing the work it wanted to do anyway.
> > 
> > if the start routine can run on multiple cpus, then it becomes
> > necessary to know it is NOT running anymore when tearing a nic down.
> > to that end i have added an if_start_barrier function. an mpsafe
> > driver can call that when it's being brought down to guarantee that
> > another cpu isnt fiddling with the tx ring before freeing it.
> > 
> > a driver opts in to the mpsafe if_start call by doing the following:
> > 
> > 1. set ifp->if_xflags = IFXF_MPSAFE.
> > 2. calling if_start() instead of its own start routine (eg, myx_start).
> > 3. clearing IFF_RUNNING before calling if_start_barrier() on its way down.
> > 4. only using IFQ_DEQUEUE (not ifq_deq_begin/commit/rollback)
> > 
> > anyway, this is the diff i have come up with after playing with
> > several ideas. it removes the IFXF_TXREADY semantics, ie, tx
> > mitigation and reuses the flag bit for IFXF_MPSAFE.
> > 
> > the reason for that is juggling or deferring the start routine made
> > if_start_barrier annoyingly complicated, and all my attmepts at it
> > introduced a significant performance hit or were insanely complicated.
> > 
> > tx mitigation only ever gave me back 5 to 10% before it was badly
> > tweaked, and we've made a lot of other performance improvements
> > since then. while im sad to see it go, id rather move forward than
> > dwell on it.
> > 
> > in the future i would like to try delegating the work to mpsafe
> > taskqs, but in my attempts i lost something like 30% of my tx rate
> > by doing that. id like to investigate that further in the future,
> > just not right now.
> > 
> > finally, the last thing to consider is lock ordering problems.
> > because contention on the ifq_serializer causes the second context
> > to return imediately (that's true even if you call if_start from
> > within a critical section), i think all the problems are avoided.
> > i am more concerned with the ifq mutex than i am with the serialiser.
> > 
> > anyway, here's the diff to look at. happy to discuss further.
> > 
> > tests would be welcome too.
> 
> no tests? no opinions?

put it in.



Re: bridge(4) never outputs packets

2015-12-02 Thread Claudio Jeker
On Wed, Dec 02, 2015 at 11:07:40AM +0100, Martin Pieuchot wrote:
> On 02/12/15(Wed) 10:25, Claudio Jeker wrote:
> > On Wed, Dec 02, 2015 at 09:57:59AM +0100, Martin Pieuchot wrote:
> > > Make sure if_output() and if_start() will never be called for the
> > > bridge(4).
> > > 
> > > Concerns?
> > 
> > Why not use if_detached_start()? There is no if_detached_output() but we
> > could add that as well. I would prefer that over NULL pointers that may
> > get hit.
> 
> I'd like to get rid of if_detached_start(), hit the NULL pointers and
> fix the bugs.
> 

Good luck. Esp. with alternate queuing disciplines and if flight packets.

-- 
:wq Claudio



Re: rm bge supported devices

2015-12-02 Thread Jason McIntyre
On Wed, Dec 02, 2015 at 06:37:19AM -0500, Ted Unangst wrote:
> There are many other product lists, but starting with the two big broadcom
> flavors here. I've had a dozen machines with bge, but none of them were listed
> in the man page. I don't think these product lists are helpful.
> 
> 1. If you have a device and want to know if it's supported, there's no reverse
> mapping from product to driver. How do I know what driver supports my NC320m
> nic? It's faster to plug it in and find out than to read every ethernet man
> page looking for it. (And then plugging it in anyway after I don't find it
> because these lists are perpetually out of date.)
> 
> 2. If you have picked a driver and are trying to find a device, these are very
> incomplete guides. Most of the devices aren't for sale anymore. Many of the
> rest are now revision B or revision C and may or may not work.
> 
> I think we are better off not maintaining such lists. We document the chip
> (family) supported by the driver. Consult the spec sheet if you want to know
> which chip is on your network card.
> 
> There may be exceptional circumstances for some drivers, so I'm not planning 
> to
> delete all the lists all at once, but deal with one family at a time.
> 

i disagree. it takes .2 of a second to grep the man pages. if nothing
shows up, so what. you're no worse off. but if you get a match, great.

why undo what's already there? we all know it's impossible to list
everything. it doesn;t mean we can;t list whatever it is we know works.

this diff will just make things more inconsistent, without any benefit
that i can see.

jmc

> Index: bge.4
> ===
> RCS file: /cvs/src/share/man/man4/bge.4,v
> retrieving revision 1.65
> diff -u -p -r1.65 bge.4
> --- bge.4 27 Jan 2015 01:38:53 -  1.65
> +++ bge.4 2 Dec 2015 11:25:17 -
> @@ -45,59 +45,7 @@ The
>  .Nm
>  driver provides support for various NICs based on the Broadcom BCM570x,
>  571x, 572x, 575x, 576x, 578x, 5776x and 5778x Gigabit Ethernet controller
> -chips and the 590x and 5779x Fast Ethernet controller chips,
> -including the following:
> -.Pp
> -.Bl -bullet -compact
> -.It
> -3Com 3c996-T (10/100/1000baseT)
> -.It
> -3Com 3c996-SX (1000baseSX)
> -.It
> -3Com 3c996B-T (10/100/1000baseT)
> -.It
> -Allied-Telesis AT-2972LX10/LC
> -.It
> -Fujitsu PW0G8GE1U (1000baseSX)
> -.It
> -Fujitsu PW0G8GE2U (10/100/1000baseT)
> -.It
> -Fujitsu PW008GE4 (1000baseSX)
> -.It
> -Fujitsu PW008GE5 (10/100/1000baseT)
> -.It
> -Fujitsu PW008QG1U (10/100/1000baseT)
> -.It
> -HP ProLiant NC320T PCI-E Gigabit NIC (10/100/1000baseT)
> -.It
> -HP ProLiant NC320m PCI-E Gigabit NIC (10/100/1000baseT)
> -.It
> -HP ProLiant NC370F PCI-X Gigabit NIC (1000baseSX)
> -.It
> -HP ProLiant NC370T PCI-X Gigabit NIC (10/100/1000baseT)
> -.It
> -HP ProLiant NC1020 PCI Gigabit NIC (10/100/1000baseT)
> -.It
> -HP ProLiant NC6770 PCI-X Gigabit NIC (1000baseSX)
> -.It
> -HP ProLiant NC7760 embedded PCI Gigabit NIC (10/100/1000baseT)
> -.It
> -HP ProLiant NC7770 PCI-X Gigabit NIC (10/100/1000baseT)
> -.It
> -HP ProLiant NC7771 PCI-X Gigabit NIC (10/100/1000baseT)
> -.It
> -HP ProLiant NC7780 embedded PCI-X Gigabit NIC (10/100/1000baseT)
> -.It
> -HP ProLiant NC7781 embedded PCI-X Gigabit NIC (10/100/1000baseT)
> -.It
> -HP ProLiant NC7782 embedded PCI-X Gigabit NIC (10/100/1000baseT)
> -.It
> -Netgear GA302T (10/100/1000baseT)
> -.It
> -SysKonnect SK-9D21 (10/100/1000baseT)
> -.It
> -SysKonnect SK-9D41 (1000baseSX)
> -.El
> +chips and the 590x and 5779x Fast Ethernet controller chips.
>  .Pp
>  The
>  .Nm
> Index: bnx.4
> ===
> RCS file: /cvs/src/share/man/man4/bnx.4,v
> retrieving revision 1.30
> diff -u -p -r1.30 bnx.4
> --- bnx.4 14 Sep 2014 00:17:09 -  1.30
> +++ bnx.4 2 Dec 2015 11:25:30 -
> @@ -44,28 +44,6 @@ The
>  .Nm
>  driver supports Broadcom's NetXtreme II product family which is made up of
>  the BCM5706, BCM5708, BCM5709, and BCM5716 Ethernet controller chips.
> -Products using these controller chips include:
> -.Pp
> -.Bl -bullet -compact
> -.It
> -HP NC370F PCI-X Multifunction Gigabit server adapter (1000baseSX)
> -.It
> -HP NC370T PCI-X Multifunction Gigabit server adapter (10/100/1000baseT)
> -.It
> -HP Dual NC370i Multifunction Gigabit embedded server adapter 
> (10/100/1000baseT)
> -.It
> -HP NC373F PCI Express Multifunction Gigabit server adapter (1000baseSX)
> -.It
> -HP NC373i PCI Express Multifunction Gigabit embedded server adapter 
> (10/100/1000baseT)
> -.It
> -HP NC374m PCI Express Multifunction Gigabit embedded server adapter 
> (10/100/1000baseT)
> -.It
> -HP NC373T PCI Express Multifunction Gigabit server adapter (10/100/1000baseT)
> -.It
> -HP NC380T PCI Express Dual Port Multifunction Gigabit server adapter 
> (10/100/1000baseT)
> -.It
> -HP NC382T PCI Express Dual Port server adapter (10/100/1000baseT)
> -.El
>  .Pp
>  The NetXtreme II 

Kill RTM_MISS & RT_REPORT

2015-12-02 Thread Martin Pieuchot
As suggested by claudio@, RTM_MISS is no longer useful and it makes
rt_match() complicated with the upcoming KERNEL_LOCK dance.

This simplifies rtalloc(9) as RT_REPORT can also die.  I'll update
the manuals if this is ok. 

Index: net/if_mpe.c
===
RCS file: /cvs/src/sys/net/if_mpe.c,v
retrieving revision 1.50
diff -u -p -r1.50 if_mpe.c
--- net/if_mpe.c6 Nov 2015 11:45:42 -   1.50
+++ net/if_mpe.c2 Dec 2015 11:13:40 -
@@ -172,7 +172,7 @@ mpestart(struct ifnet *ifp0)
continue;
}
 
-   rt = rtalloc(sa, RT_REPORT|RT_RESOLVE, 0);
+   rt = rtalloc(sa, RT_RESOLVE, 0);
if (!rtisvalid(rt)) {
m_freem(m);
rtfree(rt);
Index: net/if_mpw.c
===
RCS file: /cvs/src/sys/net/if_mpw.c,v
retrieving revision 1.10
diff -u -p -r1.10 if_mpw.c
--- net/if_mpw.c6 Nov 2015 11:45:04 -   1.10
+++ net/if_mpw.c2 Dec 2015 11:13:40 -
@@ -500,8 +500,7 @@ mpw_start(struct ifnet *ifp0)
struct shim_hdr *shim;
struct sockaddr_storage ss;
 
-   rt = rtalloc((struct sockaddr *) >sc_nexthop,
-   RT_REPORT | RT_RESOLVE, 0);
+   rt = rtalloc((struct sockaddr *)>sc_nexthop, RT_RESOLVE, 0);
if (!rtisvalid(rt)) {
rtfree(rt);
return;
Index: net/pf.c
===
RCS file: /cvs/src/sys/net/pf.c,v
retrieving revision 1.952
diff -u -p -r1.952 pf.c
--- net/pf.c21 Nov 2015 11:29:40 -  1.952
+++ net/pf.c2 Dec 2015 11:13:41 -
@@ -2934,7 +2934,7 @@ pf_calc_mss(struct pf_addr *addr, sa_fam
dst->sin_family = AF_INET;
dst->sin_len = sizeof(*dst);
dst->sin_addr = addr->v4;
-   rt = rtalloc(sintosa(dst), RT_REPORT, rtableid);
+   rt = rtalloc(sintosa(dst), 0, rtableid);
break;
 #ifdef INET6
case AF_INET6:
@@ -2943,7 +2943,7 @@ pf_calc_mss(struct pf_addr *addr, sa_fam
dst6->sin6_family = AF_INET6;
dst6->sin6_len = sizeof(*dst6);
dst6->sin6_addr = addr->v6;
-   rt = rtalloc(sin6tosa(dst6), RT_REPORT, rtableid);
+   rt = rtalloc(sin6tosa(dst6), 0, rtableid);
break;
 #endif /* INET6 */
}
@@ -5384,7 +5384,7 @@ pf_routable(struct pf_addr *addr, sa_fam
if (kif != NULL && kif->pfik_ifp->if_type == IFT_ENC)
goto out;
 
-   rt0 = rtalloc((struct sockaddr *), RT_REPORT, rtableid);
+   rt0 = rtalloc((struct sockaddr *), 0, rtableid);
if (rt0 != NULL) {
/* No interface given, this is a no-route check */
if (kif == NULL)
@@ -5456,7 +5456,7 @@ pf_rtlabel_match(struct pf_addr *addr, s
 #endif /* INET6 */
}
 
-   rt = rtalloc((struct sockaddr *), RT_REPORT|RT_RESOLVE, rtableid);
+   rt = rtalloc((struct sockaddr *), RT_RESOLVE, rtableid);
if (rt != NULL) {
if (rt->rt_labelid == aw->v.rtlabel)
ret = 1;
@@ -5515,7 +5515,7 @@ pf_route(struct mbuf **m, struct pf_rule
rtableid = m0->m_pkthdr.ph_rtableid;
 
if (!r->rt) {
-   rt = rtalloc(sintosa(dst), RT_REPORT|RT_RESOLVE, rtableid);
+   rt = rtalloc(sintosa(dst), RT_RESOLVE, rtableid);
if (rt == NULL) {
ipstat.ips_noroute++;
goto bad;
Index: net/route.c
===
RCS file: /cvs/src/sys/net/route.c,v
retrieving revision 1.280
diff -u -p -r1.280 route.c
--- net/route.c 2 Dec 2015 10:33:15 -   1.280
+++ net/route.c 2 Dec 2015 11:13:41 -
@@ -223,10 +223,6 @@ rtisvalid(struct rtentry *rt)
  * "RT_RESOLVE" means that a corresponding L2 entry should
  *   be added to the routing table and resolved (via ARP or
  *   NDP), if it does not exist.
- *
- * "RT_REPORT" indicates that a message should be sent to
- *   userland if no matching route has been found or if an
- *   error occured while adding a L2 entry.
  */
 struct rtentry *
 rt_match(struct sockaddr *dst, uint32_t *src, int flags, unsigned int tableid)
@@ -246,20 +242,15 @@ rt_match(struct sockaddr *dst, uint32_t 
rt0 = rt;
error = rtrequest(RTM_RESOLVE, , RTP_DEFAULT,
, tableid);
-   if (error) {
-   rt0->rt_use++;
-   goto miss;
+   if (error == 0) {
+   /* Inform listeners of the new route */
+   rt_sendmsg(rt, RTM_ADD, tableid);
+   rtfree(rt0);
}
-   

kill RT_REPORT since it is useless

2015-12-02 Thread Claudio Jeker
The time where route miss messages on rtalloc() where useful are long
gone. In modern times this just produces a lot of noise with no benefit.
Nothing in userland is using this information anyway. Because of this
reti^Wtedu RT_REPORT.

OK?
-- 
:wq Claudio

Index: net/if_mpe.c
===
RCS file: /cvs/src/sys/net/if_mpe.c,v
retrieving revision 1.50
diff -u -p -r1.50 if_mpe.c
--- net/if_mpe.c6 Nov 2015 11:45:42 -   1.50
+++ net/if_mpe.c2 Dec 2015 11:28:50 -
@@ -172,7 +172,7 @@ mpestart(struct ifnet *ifp0)
continue;
}
 
-   rt = rtalloc(sa, RT_REPORT|RT_RESOLVE, 0);
+   rt = rtalloc(sa, RT_RESOLVE, 0);
if (!rtisvalid(rt)) {
m_freem(m);
rtfree(rt);
Index: net/if_mpw.c
===
RCS file: /cvs/src/sys/net/if_mpw.c,v
retrieving revision 1.10
diff -u -p -r1.10 if_mpw.c
--- net/if_mpw.c6 Nov 2015 11:45:04 -   1.10
+++ net/if_mpw.c2 Dec 2015 11:28:50 -
@@ -500,8 +500,7 @@ mpw_start(struct ifnet *ifp0)
struct shim_hdr *shim;
struct sockaddr_storage ss;
 
-   rt = rtalloc((struct sockaddr *) >sc_nexthop,
-   RT_REPORT | RT_RESOLVE, 0);
+   rt = rtalloc((struct sockaddr *) >sc_nexthop, RT_RESOLVE, 0);
if (!rtisvalid(rt)) {
rtfree(rt);
return;
Index: net/pf.c
===
RCS file: /cvs/src/sys/net/pf.c,v
retrieving revision 1.952
diff -u -p -r1.952 pf.c
--- net/pf.c21 Nov 2015 11:29:40 -  1.952
+++ net/pf.c2 Dec 2015 11:28:50 -
@@ -2934,7 +2934,7 @@ pf_calc_mss(struct pf_addr *addr, sa_fam
dst->sin_family = AF_INET;
dst->sin_len = sizeof(*dst);
dst->sin_addr = addr->v4;
-   rt = rtalloc(sintosa(dst), RT_REPORT, rtableid);
+   rt = rtalloc(sintosa(dst), 0, rtableid);
break;
 #ifdef INET6
case AF_INET6:
@@ -2943,7 +2943,7 @@ pf_calc_mss(struct pf_addr *addr, sa_fam
dst6->sin6_family = AF_INET6;
dst6->sin6_len = sizeof(*dst6);
dst6->sin6_addr = addr->v6;
-   rt = rtalloc(sin6tosa(dst6), RT_REPORT, rtableid);
+   rt = rtalloc(sin6tosa(dst6), 0, rtableid);
break;
 #endif /* INET6 */
}
@@ -5384,7 +5384,7 @@ pf_routable(struct pf_addr *addr, sa_fam
if (kif != NULL && kif->pfik_ifp->if_type == IFT_ENC)
goto out;
 
-   rt0 = rtalloc((struct sockaddr *), RT_REPORT, rtableid);
+   rt0 = rtalloc((struct sockaddr *), 0, rtableid);
if (rt0 != NULL) {
/* No interface given, this is a no-route check */
if (kif == NULL)
@@ -5456,7 +5456,7 @@ pf_rtlabel_match(struct pf_addr *addr, s
 #endif /* INET6 */
}
 
-   rt = rtalloc((struct sockaddr *), RT_REPORT|RT_RESOLVE, rtableid);
+   rt = rtalloc((struct sockaddr *), RT_RESOLVE, rtableid);
if (rt != NULL) {
if (rt->rt_labelid == aw->v.rtlabel)
ret = 1;
@@ -5515,7 +5515,7 @@ pf_route(struct mbuf **m, struct pf_rule
rtableid = m0->m_pkthdr.ph_rtableid;
 
if (!r->rt) {
-   rt = rtalloc(sintosa(dst), RT_REPORT|RT_RESOLVE, rtableid);
+   rt = rtalloc(sintosa(dst), RT_RESOLVE, rtableid);
if (rt == NULL) {
ipstat.ips_noroute++;
goto bad;
Index: net/route.c
===
RCS file: /cvs/src/sys/net/route.c,v
retrieving revision 1.280
diff -u -p -r1.280 route.c
--- net/route.c 2 Dec 2015 10:33:15 -   1.280
+++ net/route.c 2 Dec 2015 11:28:50 -
@@ -223,10 +223,6 @@ rtisvalid(struct rtentry *rt)
  * "RT_RESOLVE" means that a corresponding L2 entry should
  *   be added to the routing table and resolved (via ARP or
  *   NDP), if it does not exist.
- *
- * "RT_REPORT" indicates that a message should be sent to
- *   userland if no matching route has been found or if an
- *   error occured while adding a L2 entry.
  */
 struct rtentry *
 rt_match(struct sockaddr *dst, uint32_t *src, int flags, unsigned int tableid)
@@ -248,19 +244,17 @@ rt_match(struct sockaddr *dst, uint32_t 
, tableid);
if (error) {
rt0->rt_use++;
-   goto miss;
+   rt_missmsg(RTM_MISS, , 0, 0, error,
+   tableid);
+   } else {
+   /* Inform listeners of the new route */
+   rt_sendmsg(rt, RTM_ADD, tableid);
+   rtfree(rt0);

rm bge supported devices

2015-12-02 Thread Ted Unangst
There are many other product lists, but starting with the two big broadcom
flavors here. I've had a dozen machines with bge, but none of them were listed
in the man page. I don't think these product lists are helpful.

1. If you have a device and want to know if it's supported, there's no reverse
mapping from product to driver. How do I know what driver supports my NC320m
nic? It's faster to plug it in and find out than to read every ethernet man
page looking for it. (And then plugging it in anyway after I don't find it
because these lists are perpetually out of date.)

2. If you have picked a driver and are trying to find a device, these are very
incomplete guides. Most of the devices aren't for sale anymore. Many of the
rest are now revision B or revision C and may or may not work.

I think we are better off not maintaining such lists. We document the chip
(family) supported by the driver. Consult the spec sheet if you want to know
which chip is on your network card.

There may be exceptional circumstances for some drivers, so I'm not planning to
delete all the lists all at once, but deal with one family at a time.

Index: bge.4
===
RCS file: /cvs/src/share/man/man4/bge.4,v
retrieving revision 1.65
diff -u -p -r1.65 bge.4
--- bge.4   27 Jan 2015 01:38:53 -  1.65
+++ bge.4   2 Dec 2015 11:25:17 -
@@ -45,59 +45,7 @@ The
 .Nm
 driver provides support for various NICs based on the Broadcom BCM570x,
 571x, 572x, 575x, 576x, 578x, 5776x and 5778x Gigabit Ethernet controller
-chips and the 590x and 5779x Fast Ethernet controller chips,
-including the following:
-.Pp
-.Bl -bullet -compact
-.It
-3Com 3c996-T (10/100/1000baseT)
-.It
-3Com 3c996-SX (1000baseSX)
-.It
-3Com 3c996B-T (10/100/1000baseT)
-.It
-Allied-Telesis AT-2972LX10/LC
-.It
-Fujitsu PW0G8GE1U (1000baseSX)
-.It
-Fujitsu PW0G8GE2U (10/100/1000baseT)
-.It
-Fujitsu PW008GE4 (1000baseSX)
-.It
-Fujitsu PW008GE5 (10/100/1000baseT)
-.It
-Fujitsu PW008QG1U (10/100/1000baseT)
-.It
-HP ProLiant NC320T PCI-E Gigabit NIC (10/100/1000baseT)
-.It
-HP ProLiant NC320m PCI-E Gigabit NIC (10/100/1000baseT)
-.It
-HP ProLiant NC370F PCI-X Gigabit NIC (1000baseSX)
-.It
-HP ProLiant NC370T PCI-X Gigabit NIC (10/100/1000baseT)
-.It
-HP ProLiant NC1020 PCI Gigabit NIC (10/100/1000baseT)
-.It
-HP ProLiant NC6770 PCI-X Gigabit NIC (1000baseSX)
-.It
-HP ProLiant NC7760 embedded PCI Gigabit NIC (10/100/1000baseT)
-.It
-HP ProLiant NC7770 PCI-X Gigabit NIC (10/100/1000baseT)
-.It
-HP ProLiant NC7771 PCI-X Gigabit NIC (10/100/1000baseT)
-.It
-HP ProLiant NC7780 embedded PCI-X Gigabit NIC (10/100/1000baseT)
-.It
-HP ProLiant NC7781 embedded PCI-X Gigabit NIC (10/100/1000baseT)
-.It
-HP ProLiant NC7782 embedded PCI-X Gigabit NIC (10/100/1000baseT)
-.It
-Netgear GA302T (10/100/1000baseT)
-.It
-SysKonnect SK-9D21 (10/100/1000baseT)
-.It
-SysKonnect SK-9D41 (1000baseSX)
-.El
+chips and the 590x and 5779x Fast Ethernet controller chips.
 .Pp
 The
 .Nm
Index: bnx.4
===
RCS file: /cvs/src/share/man/man4/bnx.4,v
retrieving revision 1.30
diff -u -p -r1.30 bnx.4
--- bnx.4   14 Sep 2014 00:17:09 -  1.30
+++ bnx.4   2 Dec 2015 11:25:30 -
@@ -44,28 +44,6 @@ The
 .Nm
 driver supports Broadcom's NetXtreme II product family which is made up of
 the BCM5706, BCM5708, BCM5709, and BCM5716 Ethernet controller chips.
-Products using these controller chips include:
-.Pp
-.Bl -bullet -compact
-.It
-HP NC370F PCI-X Multifunction Gigabit server adapter (1000baseSX)
-.It
-HP NC370T PCI-X Multifunction Gigabit server adapter (10/100/1000baseT)
-.It
-HP Dual NC370i Multifunction Gigabit embedded server adapter (10/100/1000baseT)
-.It
-HP NC373F PCI Express Multifunction Gigabit server adapter (1000baseSX)
-.It
-HP NC373i PCI Express Multifunction Gigabit embedded server adapter 
(10/100/1000baseT)
-.It
-HP NC374m PCI Express Multifunction Gigabit embedded server adapter 
(10/100/1000baseT)
-.It
-HP NC373T PCI Express Multifunction Gigabit server adapter (10/100/1000baseT)
-.It
-HP NC380T PCI Express Dual Port Multifunction Gigabit server adapter 
(10/100/1000baseT)
-.It
-HP NC382T PCI Express Dual Port server adapter (10/100/1000baseT)
-.El
 .Pp
 The NetXtreme II product family is composed of various Converged NIC (or CNIC)
 Ethernet controllers which support a TCP Offload Engine (TOE),



Re: bridge(4) never outputs packets

2015-12-02 Thread David Gwynne

> On 2 Dec 2015, at 8:49 PM, Claudio Jeker  wrote:
> 
> On Wed, Dec 02, 2015 at 11:07:40AM +0100, Martin Pieuchot wrote:
>> On 02/12/15(Wed) 10:25, Claudio Jeker wrote:
>>> On Wed, Dec 02, 2015 at 09:57:59AM +0100, Martin Pieuchot wrote:
 Make sure if_output() and if_start() will never be called for the
 bridge(4).
 
 Concerns?
>>> 
>>> Why not use if_detached_start()? There is no if_detached_output() but we
>>> could add that as well. I would prefer that over NULL pointers that may
>>> get hit.
>> 
>> I'd like to get rid of if_detached_start(), hit the NULL pointers and
>> fix the bugs.
>> 
> 
> Good luck. Esp. with alternate queuing disciplines and if flight packets.

if you IFQ_PURGE(>if_snd) first then there's no in flight packets anymore.



Re: rm bge supported devices

2015-12-02 Thread Mark Kettenis
> Date: Wed, 2 Dec 2015 12:32:52 +
> From: Stuart Henderson 
> 
> On 2015/12/02 12:09, jus...@postgresql.org wrote:
> > On 2015-12-02 11:37, Ted Unangst wrote:
> > >2. If you have picked a driver and are trying to find a device, these
> > >are very incomplete guides. Most of the devices aren't for sale anymore.
> > >Many of the rest are now revision B or revision C and may or may not work.
> 
> For those of us whose hardware procurement policy typically involves
> ebay, they can be quite useful, they are incomplete but there are loads
> of e.g. the HP nics available, and there are a lot fewer junk results if
> you can search for NC380T/NC382T than "dual port pci express gigabit"
> and have to sift through all the PCI-X ones that have been miscategorised.

Given what sthen@ says here, I'm on the fence.  While the list isn't
complete, I do think it is listing a significant fraction of the
available hardware.  Yes there is a lot of bge(4) hardware out there
that isn't listed, but most of that is unlisted because it is onboard.



Few nitpicks on games

2015-12-02 Thread Ricardo Mestre
Hi tech@

Few nitpicks on games:

Change home var to const char* both on canfield(6)/cfscores(6), and on the
latter also remove unused var name.

Additionaly on snake(6) one of the getenv("HOME") missed a safe checking for
NULL.

Index: games/canfield/canfield/canfield.c
===
RCS file: /cvs/src/games/canfield/canfield/canfield.c,v
retrieving revision 1.21
diff -u -p -u -r1.21 canfield.c
--- games/canfield/canfield/canfield.c  30 Nov 2015 08:38:13 -  1.21
+++ games/canfield/canfield/canfield.c  2 Dec 2015 12:59:05 -
@@ -1627,7 +1627,7 @@ initall(void)
 {
int i, ret;
char scorepath[PATH_MAX];
-   char *home;
+   const char *home;
 
time();
initdeck(deck);
Index: games/canfield/cfscores/cfscores.c
===
RCS file: /cvs/src/games/canfield/cfscores/cfscores.c,v
retrieving revision 1.20
diff -u -p -u -r1.20 cfscores.c
--- games/canfield/cfscores/cfscores.c  30 Nov 2015 08:38:13 -  1.20
+++ games/canfield/cfscores/cfscores.c  2 Dec 2015 12:59:18 -
@@ -59,7 +59,7 @@ void  printuser(void);
 int
 main(int argc, char *argv[])
 {
-   char *home, *name;
+   const char *home;
int ret;
 
if (pledge("stdio rpath", NULL) == -1)
Index: games/snake/snake.c
===
RCS file: /cvs/src/games/snake/snake.c,v
retrieving revision 1.18
diff -u -p -u -r1.18 snake.c
--- games/snake/snake.c 29 Nov 2015 14:31:01 -  1.18
+++ games/snake/snake.c 2 Dec 2015 12:59:58 -
@@ -148,7 +148,13 @@ main(int argc, char *argv[])
err(1, "pledge");
 
 #ifdef LOGGING
-   snprintf(logpath, sizeof(logpath), "%s/%s", getenv("HOME"),
+   const   char* home;
+
+   home = getenv("HOME");
+   if (home == NULL || *home == '\0')
+   err(1, "getenv");
+
+   snprintf(logpath, sizeof(logpath), "%s/%s", home,
".snake.log");
logfile = fopen(logpath, "a");
 #endiF



malloc canaries and validation

2015-12-02 Thread Ted Unangst
This is a variant of the diffs sent by Daniel Micay, and then assembled by
Theo Buehler. I've looked it over and made a few tweaks.

One: validate the junk in malloc hasn't been touched. I've tweaked this to
always be on if junk is on, but to only check the first 32 bytes. (Without the
atexit() handler, since I do not trust installing such by default.) I think
this is a decent compromise between checking and performance and complexity
and whatnot.

Two: add chunk canaries at the end of allocations. I would like to do
something more interesting here (and by default, of course) but growing the
size of every allocation isn't free. Many userland applications already aim
for power of two sizing, so expanding by 4/8 bytes is far from free. However,
this is an ineresting feature, it's not that intrusive, and maybe we can build
from it. Include it as well.

Hurray or nay?

Index: stdlib/malloc.c
===
RCS file: /cvs/src/lib/libc/stdlib/malloc.c,v
retrieving revision 1.176
diff -u -p -r1.176 malloc.c
--- stdlib/malloc.c 13 Sep 2015 20:29:23 -  1.176
+++ stdlib/malloc.c 2 Dec 2015 11:59:19 -
@@ -185,12 +185,14 @@ struct malloc_readonly {
int malloc_move;/* move allocations to end of page? */
int malloc_realloc; /* always realloc? */
int malloc_xmalloc; /* xmalloc behaviour? */
+   size_t  malloc_canaries;/* use canaries after chunks? */
size_t  malloc_guard;   /* use guard pages after allocations? */
u_int   malloc_cache;   /* free pages we cache */
 #ifdef MALLOC_STATS
int malloc_stats;   /* dump statistics at end */
 #endif
u_int32_t malloc_canary;/* Matched against ones in malloc_pool 
*/
+   uintptr_t malloc_chunk_canary;
 };
 
 /* This object is mapped PROT_READ after initialisation to prevent tampering */
@@ -526,6 +528,12 @@ omalloc_init(struct dir_info **dp)
case 'A':
mopts.malloc_abort = 1;
break;
+   case 'c':
+   mopts.malloc_canaries = 0;
+   break;
+   case 'C':
+   mopts.malloc_canaries = sizeof(void *);
+   break;
 #ifdef MALLOC_STATS
case 'd':
mopts.malloc_stats = 0;
@@ -619,6 +627,9 @@ omalloc_init(struct dir_info **dp)
while ((mopts.malloc_canary = arc4random()) == 0)
;
 
+   arc4random_buf(_chunk_canary,
+   sizeof(mopts.malloc_chunk_canary));
+
/*
 * Allocate dir_info with a guard page on either side. Also
 * randomise offset inside the page at which the dir_info
@@ -984,8 +995,15 @@ malloc_bytes(struct dir_info *d, size_t 
k += (lp - bp->bits) * MALLOC_BITS;
k <<= bp->shift;
 
+   if (mopts.malloc_canaries && bp->size > 0) {
+   char *end = (char *)bp->page + k + bp->size;
+   uintptr_t *canary = (uintptr_t *)(end - mopts.malloc_canaries);
+   *canary = mopts.malloc_chunk_canary ^ hash(canary);
+   }
+
if (mopts.malloc_junk == 2 && bp->size > 0)
-   memset((char *)bp->page + k, SOME_JUNK, bp->size);
+   memset((char *)bp->page + k, SOME_JUNK,
+   bp->size - mopts.malloc_canaries);
return ((char *)bp->page + k);
 }
 
@@ -999,6 +1017,13 @@ find_chunknum(struct dir_info *d, struct
if (info->canary != d->canary1)
wrterror("chunk info corrupted", NULL);
 
+   if (mopts.malloc_canaries && info->size > 0) {
+   char *end = (char *)ptr + info->size;
+   uintptr_t *canary = (uintptr_t *)(end - mopts.malloc_canaries);
+   if (*canary != (mopts.malloc_chunk_canary ^ hash(canary)))
+   wrterror("chunk canary corrupted", ptr);
+   }
+
/* Find the chunk number on the page */
chunknum = ((uintptr_t)ptr & MALLOC_PAGEMASK) >> info->shift;
 
@@ -1121,7 +1146,7 @@ omalloc(size_t sz, int zero_fill, void *
/* takes care of SOME_JUNK */
p = malloc_bytes(pool, sz, f);
if (zero_fill && p != NULL && sz > 0)
-   memset(p, 0, sz);
+   memset(p, 0, sz - mopts.malloc_canaries);
}
 
return p;
@@ -1176,6 +1201,8 @@ malloc(size_t size)
malloc_recurse();
return NULL;
}
+   if (size > 0 && size <= MALLOC_MAXCHUNK)
+   size += mopts.malloc_canaries;
r = omalloc(size, 0, CALLER);
malloc_active--;
_MALLOC_UNLOCK();
@@ -1190,6 +1217,30 @@ malloc(size_t size)
 /*DEF_STRONG(malloc);*/
 
 static void
+validate_junk(void *p) {
+   struct region_info *r;
+   

Re: rm bge supported devices

2015-12-02 Thread Reyk Floeter
On Wed, Dec 02, 2015 at 06:37:19AM -0500, Ted Unangst wrote:
> There are many other product lists, but starting with the two big broadcom
> flavors here. I've had a dozen machines with bge, but none of them were listed
> in the man page. I don't think these product lists are helpful.
> 
> 1. If you have a device and want to know if it's supported, there's no reverse
> mapping from product to driver. How do I know what driver supports my NC320m
> nic? It's faster to plug it in and find out than to read every ethernet man
> page looking for it. (And then plugging it in anyway after I don't find it
> because these lists are perpetually out of date.)
> 
> 2. If you have picked a driver and are trying to find a device, these are very
> incomplete guides. Most of the devices aren't for sale anymore. Many of the
> rest are now revision B or revision C and may or may not work.
> 
> I think we are better off not maintaining such lists. We document the chip
> (family) supported by the driver. Consult the spec sheet if you want to know
> which chip is on your network card.
> 
> There may be exceptional circumstances for some drivers, so I'm not planning 
> to
> delete all the lists all at once, but deal with one family at a time.
> 

The last time I used it was when I looked up if the "Intel X540-T2" is
an ix(4) - before I ordered it online.  It is listed in the manpage,
so I didn't bother asking other people or looking up the chipset.  And
it worked, of course.  I think it is convenient for the most common
devices and doesn't have to be a comprehensive list.

Reyk

> Index: bge.4
> ===
> RCS file: /cvs/src/share/man/man4/bge.4,v
> retrieving revision 1.65
> diff -u -p -r1.65 bge.4
> --- bge.4 27 Jan 2015 01:38:53 -  1.65
> +++ bge.4 2 Dec 2015 11:25:17 -
> @@ -45,59 +45,7 @@ The
>  .Nm
>  driver provides support for various NICs based on the Broadcom BCM570x,
>  571x, 572x, 575x, 576x, 578x, 5776x and 5778x Gigabit Ethernet controller
> -chips and the 590x and 5779x Fast Ethernet controller chips,
> -including the following:
> -.Pp
> -.Bl -bullet -compact
> -.It
> -3Com 3c996-T (10/100/1000baseT)
> -.It
> -3Com 3c996-SX (1000baseSX)
> -.It
> -3Com 3c996B-T (10/100/1000baseT)
> -.It
> -Allied-Telesis AT-2972LX10/LC
> -.It
> -Fujitsu PW0G8GE1U (1000baseSX)
> -.It
> -Fujitsu PW0G8GE2U (10/100/1000baseT)
> -.It
> -Fujitsu PW008GE4 (1000baseSX)
> -.It
> -Fujitsu PW008GE5 (10/100/1000baseT)
> -.It
> -Fujitsu PW008QG1U (10/100/1000baseT)
> -.It
> -HP ProLiant NC320T PCI-E Gigabit NIC (10/100/1000baseT)
> -.It
> -HP ProLiant NC320m PCI-E Gigabit NIC (10/100/1000baseT)
> -.It
> -HP ProLiant NC370F PCI-X Gigabit NIC (1000baseSX)
> -.It
> -HP ProLiant NC370T PCI-X Gigabit NIC (10/100/1000baseT)
> -.It
> -HP ProLiant NC1020 PCI Gigabit NIC (10/100/1000baseT)
> -.It
> -HP ProLiant NC6770 PCI-X Gigabit NIC (1000baseSX)
> -.It
> -HP ProLiant NC7760 embedded PCI Gigabit NIC (10/100/1000baseT)
> -.It
> -HP ProLiant NC7770 PCI-X Gigabit NIC (10/100/1000baseT)
> -.It
> -HP ProLiant NC7771 PCI-X Gigabit NIC (10/100/1000baseT)
> -.It
> -HP ProLiant NC7780 embedded PCI-X Gigabit NIC (10/100/1000baseT)
> -.It
> -HP ProLiant NC7781 embedded PCI-X Gigabit NIC (10/100/1000baseT)
> -.It
> -HP ProLiant NC7782 embedded PCI-X Gigabit NIC (10/100/1000baseT)
> -.It
> -Netgear GA302T (10/100/1000baseT)
> -.It
> -SysKonnect SK-9D21 (10/100/1000baseT)
> -.It
> -SysKonnect SK-9D41 (1000baseSX)
> -.El
> +chips and the 590x and 5779x Fast Ethernet controller chips.
>  .Pp
>  The
>  .Nm
> Index: bnx.4
> ===
> RCS file: /cvs/src/share/man/man4/bnx.4,v
> retrieving revision 1.30
> diff -u -p -r1.30 bnx.4
> --- bnx.4 14 Sep 2014 00:17:09 -  1.30
> +++ bnx.4 2 Dec 2015 11:25:30 -
> @@ -44,28 +44,6 @@ The
>  .Nm
>  driver supports Broadcom's NetXtreme II product family which is made up of
>  the BCM5706, BCM5708, BCM5709, and BCM5716 Ethernet controller chips.
> -Products using these controller chips include:
> -.Pp
> -.Bl -bullet -compact
> -.It
> -HP NC370F PCI-X Multifunction Gigabit server adapter (1000baseSX)
> -.It
> -HP NC370T PCI-X Multifunction Gigabit server adapter (10/100/1000baseT)
> -.It
> -HP Dual NC370i Multifunction Gigabit embedded server adapter 
> (10/100/1000baseT)
> -.It
> -HP NC373F PCI Express Multifunction Gigabit server adapter (1000baseSX)
> -.It
> -HP NC373i PCI Express Multifunction Gigabit embedded server adapter 
> (10/100/1000baseT)
> -.It
> -HP NC374m PCI Express Multifunction Gigabit embedded server adapter 
> (10/100/1000baseT)
> -.It
> -HP NC373T PCI Express Multifunction Gigabit server adapter (10/100/1000baseT)
> -.It
> -HP NC380T PCI Express Dual Port Multifunction Gigabit server adapter 
> (10/100/1000baseT)
> -.It
> -HP NC382T PCI Express Dual Port server adapter (10/100/1000baseT)
> -.El
>  .Pp
>  The NetXtreme II product family is composed of various