add intel 6235 support to iwn(4)

2012-11-10 Thread joshua stein
Add support for Intel 6235 WiFi:

iwn0 at pci2 dev 0 function 0 "Intel Centrino Advanced-N 6235" rev 0x24: msi, 
MIMO 2T2R, AGN, address c4:85:08:35:55:f7

Requires newer iwn-6030 firmware that I recently added to the
iwn-firmware package.  Trying to configure Bluetooth coexistence
kills the device (unrecoverable firmware error) and I couldn't
understand all of the voodoo that the Linux driver does to deal with
this, so I just disabled it.  I don't think our Bluetooth stuff
works anyway.


Index: dev/pci/if_iwn.c
===
RCS file: /cvs/src/sys/dev/pci/if_iwn.c,v
retrieving revision 1.114
diff -u -p -u -p -r1.114 if_iwn.c
--- dev/pci/if_iwn.c12 Oct 2012 19:53:24 -  1.114
+++ dev/pci/if_iwn.c11 Nov 2012 04:31:39 -
@@ -90,7 +90,8 @@ static const struct pci_matchid iwn_devi
{ PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_WL_1030_1 },
{ PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_WL_1030_2 },
{ PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_WL_100_1 },
-   { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_WL_100_2 }
+   { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_WL_100_2 },
+   { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_WL_6235_1 },
 };
 
 intiwn_match(struct device *, void *, void *);
@@ -638,7 +639,11 @@ iwn5000_attach(struct iwn_softc *sc, pci
break;
case IWN_HW_REV_TYPE_6005:
sc->limits = &iwn6000_sensitivity_limits;
-   sc->fwname = "iwn-6005";
+   if (pid == PCI_PRODUCT_INTEL_WL_6235_1) {
+   sc->fwname = "iwn-6030";
+   sc->sc_flags |= IWN_FLAG_NO_BT_COEX;
+   } else
+   sc->fwname = "iwn-6005";
break;
default:
printf(": adapter type %d not supported\n", sc->hw_type);
@@ -4191,12 +4196,14 @@ iwn_config(struct iwn_softc *sc)
}
}
 
-   /* Configure bluetooth coexistence. */
-   error = iwn_send_btcoex(sc);
-   if (error != 0) {
-   printf("%s: could not configure bluetooth coexistence\n",
-   sc->sc_dev.dv_xname);
-   return error;
+   if (!(sc->sc_flags & IWN_FLAG_NO_BT_COEX)) {
+   /* Configure bluetooth coexistence. */
+   error = iwn_send_btcoex(sc);
+   if (error != 0) {
+   printf("%s: could not configure bluetooth 
coexistence\n",
+   sc->sc_dev.dv_xname);
+   return error;
+   }
}
 
/* Set mode, channel, RX filter and enable RX. */
Index: dev/pci/if_iwnvar.h
===
RCS file: /cvs/src/sys/dev/pci/if_iwnvar.h,v
retrieving revision 1.22
diff -u -p -u -p -r1.22 if_iwnvar.h
--- dev/pci/if_iwnvar.h 9 Jan 2011 15:45:37 -   1.22
+++ dev/pci/if_iwnvar.h 11 Nov 2012 04:31:39 -
@@ -201,6 +201,7 @@ struct iwn_softc {
 #define IWN_FLAG_BUSY  (1 << 5)
 #define IWN_FLAG_HAS_11N   (1 << 6)
 #define IWN_FLAG_ENH_SENS  (1 << 7)
+#define IWN_FLAG_NO_BT_COEX(1 << 8)
 
uint8_t hw_type;
 



OpenBSD 5.2-current (GENERIC.MP) #60: Sat Nov 10 22:29:29 CST 2012
j...@zen.superblock.net:/usr/src/sys/arch/amd64/compile/GENERIC.MP
real mem = 4173500416 (3980MB)
avail mem = 4040249344 (3853MB)
mainbus0 at root
bios0 at mainbus0: SMBIOS rev. 2.7 @ 0xeba60 (23 entries)
bios0: vendor American Megatrends Inc. version "UX21A.209" date 06/06/2012
bios0: ASUSTeK COMPUTER INC. UX21A
acpi0 at bios0: rev 2
acpi0: sleep states S0 S3 S4 S5
acpi0: tables DSDT FACP APIC FPDT ECDT MCFG SSDT SSDT SSDT SSDT SLIC HPET SSDT 
SSDT DMAR
acpi0: wakeup devices P0P1(S4) PEG0(S4) PEG1(S4) PEG2(S4) PEG3(S4) USB1(S3) 
USB2(S3) USB3(S3) USB4(S3) EHC2(S3) USB5(S3) USB6(S3) USB7(S3) HDEF(S4) 
RP01(S4) RP02(S4) WLAN(S3) RP03(S4) RP04(S4) RP05(S4) RP06(S4) RP07(S4) 
RP08(S4) EHC1(S3) XHC1(S3) XHC_(S4) SLPB(S4)
acpitimer0 at acpi0: 3579545 Hz, 24 bits
acpimadt0 at acpi0 addr 0xfee0: PC-AT compat
cpu0 at mainbus0: apid 0 (boot processor)
cpu0: Intel(R) Core(TM) i5-3317U CPU @ 1.70GHz, 1596.59 MHz
cpu0: 
FPU,VME,DE,PSE,TSC,MSR,PAE,MCE,CX8,APIC,SEP,MTRR,PGE,MCA,CMOV,PAT,PSE36,CFLUSH,DS,ACPI,MMX,FXSR,SSE,SSE2,SS,HTT,TM,PBE,SSE3,PCLMUL,DTES64,MWAIT,DS-CPL,VMX,EST,TM2,SSSE3,CX16,xTPR,PDCM,PCID,SSE4.1,SSE4.2,x2APIC,POPCNT,DEADLINE,AES,XSAVE,AVX,F16C,RDRAND,NXE,LONG,LAHF,PERF,ITSC,FSGSBASE,SMEP,ERMS
cpu0: 256KB 64b/line 8-way L2 cache
cpu0: apic clock running at 99MHz
cpu1 at mainbus0: apid 2 (application processor)
cpu1: Intel(R) Core(TM) i5-3317U CPU @ 1.70GHz, 1596.38 MHz
cpu1: 
FPU,VME,DE,PSE,TSC,MSR,PAE,MCE,CX8,APIC,SEP,MTRR,PGE,MCA,CMOV,PAT,PSE36,CFLUSH,DS,ACPI,MMX,FXSR,SSE,SSE2,SS,HTT,TM,PBE,SSE3,PCLMUL,DTES64,MWAIT,DS-CPL,VMX,EST,TM2,SSSE3,CX16,xTPR,PDCM,PCID,SSE4.1,SSE4.2,x2APIC,POPCNT,DEADLINE,AES,XSAVE,AVX,F16C,RDRAND,NXE,LONG,LAHF,PERF,ITSC,FSGSBASE,SMEP,ERMS
cpu1: 256KB 64b/line 8-

Re: Small memcpy optimization

2012-11-10 Thread Mark Kettenis
> Date: Sat, 10 Nov 2012 18:10:53 +0100 (CET)
> From: Stefan Fritsch 
> 
> On Thu, 8 Nov 2012, Mark Kettenis wrote:
> >> On Tuesday 21 August 2012, Stefan Fritsch wrote:
> >>> On x86, the xchg operation between reg and mem has an implicit lock
> >>> prefix, i.e. it is a relatively expensive atomic operation. This is
> >>> not needed here.
> >>
> >> OKs, anyone?
> >
> > What you say makes sense, although it might matter only on MP
> > (capable) systems.
> 
> True, but MP is the norm nowadays.
> 
> > If you really want to make things faster, I
> > suppose you could change the code into something like
> >
> >pushl   %esi
> >pushl   %edi
> >movl12(%esp),%edi
> >movl16(%esp),%esi
> 
> That's true. Like this (suggestions for a better label name are 
> welcome):

What about doocpy?  And I would put the label on a line of its own,
such that it stands out more.

> --- locore.s
> +++ locore.s
> @@ -789,7 +789,7 @@ ENTRY(bcopy)
>   pushl   %edi
>   movl12(%esp),%esi
>   movl16(%esp),%edi
> - movl20(%esp),%ecx
> +bcopy2:  movl20(%esp),%ecx
>   movl%edi,%eax
>   subl%esi,%eax
>   cmpl%ecx,%eax   # overlapping?
> @@ -827,13 +827,15 @@ ENTRY(bcopy)
>   ret
> 
>   /*
> - * Emulate memcpy() by swapping the first two arguments and calling bcopy()
> + * Emulate memcpy() by loading the first two arguments in reverse order
> + * and jumping into bcopy()
>*/
>   ENTRY(memcpy)
> - movl4(%esp),%ecx
> - xchg8(%esp),%ecx
> - movl%ecx,4(%esp)
> - jmp _C_LABEL(bcopy)
> + pushl   %esi
> + pushl   %edi
> + movl12(%esp),%edi
> + movl16(%esp),%esi
> + jmp bcopy2
> 
>   
> /*/



Re: Allow bgpd to filter on the nexthop attribute

2012-11-10 Thread Claudio Jeker
On Sat, Nov 10, 2012 at 06:52:17PM +0100, Claudio Jeker wrote:
> On Sat, Nov 10, 2012 at 03:38:15PM +0100, Claudio Jeker wrote:
> > In some cases it helps to be able to restrict nexthops from pathes
> > received. E.g. at IXP where only routes originating from the neighbor
> > should be accepted.
> > 
> > This diff implements this for bgpd.
> 
> Updated diff that fixes a missing break. Found by Florian.

Another bug found by Florian Obser. This time the "netxhop neighbor"
feature crashed the rde because the asp passed around in the filter is not
linked and therefor asp->peer is NULL. Oups.
Since rde_filter() already carries the from peer just pass that info down.

-- 
:wq Claudio

Index: bgpd.conf.5
===
RCS file: /cvs/src/usr.sbin/bgpd/bgpd.conf.5,v
retrieving revision 1.121
diff -u -p -r1.121 bgpd.conf.5
--- bgpd.conf.5 24 Aug 2012 17:04:06 -  1.121
+++ bgpd.conf.5 28 Oct 2012 13:38:06 -
@@ -1175,6 +1175,17 @@ is repeated more than
 .Ar len
 times.
 .Pp
+.It Ic nexthop Ar address
+This rule applies only to
+.Em UPDATES
+where the nexthop is equal to
+.Ar address.
+The
+.Ar address
+can be set to
+.Em neighbor
+in which case the nexthop is compared against the address of the neighbor.
+.Pp
 .It Xo
 .Ic prefix
 .Ar address Ns Li / Ns Ar len
Index: bgpd.h
===
RCS file: /cvs/src/usr.sbin/bgpd/bgpd.h,v
retrieving revision 1.273
diff -u -p -r1.273 bgpd.h
--- bgpd.h  18 Sep 2012 10:10:00 -  1.273
+++ bgpd.h  28 Oct 2012 13:00:03 -
@@ -749,6 +749,13 @@ struct filter_prefix {
u_int8_tlen;
 };
 
+struct filter_nexthop {
+   struct bgpd_addraddr;
+   u_int8_tflags;
+#define FILTER_NEXTHOP_ADDR1
+#define FILTER_NEXTHOP_NEIGHBOR2
+};
+
 struct filter_prefixlen {
enum comp_ops   op;
u_int8_taid;
@@ -759,6 +766,7 @@ struct filter_prefixlen {
 struct filter_match {
struct filter_prefixprefix;
struct filter_prefixlen prefixlen;
+   struct filter_nexthop   nexthop;
struct filter_asas;
struct filter_aslen aslen;
struct filter_community community;
Index: parse.y
===
RCS file: /cvs/src/usr.sbin/bgpd/parse.y,v
retrieving revision 1.264
diff -u -p -r1.264 parse.y
--- parse.y 23 Sep 2012 09:39:17 -  1.264
+++ parse.y 28 Oct 2012 13:29:16 -
@@ -1700,6 +1700,26 @@ filter_elm   : filter_prefix_h   {
}
fmopts.aid = AID_INET6;
}
+   | NEXTHOP address   {
+   if (fmopts.m.nexthop.flags) {
+   yyerror("nexthop already specified");
+   YYERROR;
+   }
+   if (fmopts.aid && fmopts.aid != $2.aid) {
+   yyerror("nexthop address family doesn't match "
+   "rule address family");
+   YYERROR;
+   }
+   fmopts.m.nexthop.addr = $2;
+   fmopts.m.nexthop.flags = FILTER_NEXTHOP_ADDR;
+   }
+   | NEXTHOP NEIGHBOR  {
+   if (fmopts.m.nexthop.flags) {
+   yyerror("nexthop already specified");
+   YYERROR;
+   }
+   fmopts.m.nexthop.flags = FILTER_NEXTHOP_NEIGHBOR;
+   }
;
 
 prefixlenop: unaryop NUMBER{
Index: printconf.c
===
RCS file: /cvs/src/usr.sbin/bgpd/printconf.c,v
retrieving revision 1.88
diff -u -p -r1.88 printconf.c
--- printconf.c 23 Sep 2012 09:39:18 -  1.88
+++ printconf.c 28 Oct 2012 13:33:58 -
@@ -561,6 +561,13 @@ print_rule(struct peer *peer_l, struct f
}
}
 
+   if (r->match.nexthop.flags) {
+   if (r->match.nexthop.flags == FILTER_NEXTHOP_NEIGHBOR)
+   printf("nexthop neighbor ");
+   else
+   printf("nexthop %s ", log_addr(&r->match.nexthop.addr));
+   }
+
if (r->match.as.type) {
if (r->match.as.type == AS_ALL)
printf("AS %s ", log_as(r->match.as.as));
Index: rde_filter.c
===
RCS file: /cvs/src/usr.sbin/bgpd/rde_filter.c,v
retrieving revision 1.67
diff -u -p -r1.67 rde_filter.c
--- rde_filter.c20 Sep 2011 21:19:06 -  1.67
+++ rde_filter.c10 Nov 2012 20:56:14 -
@@ -26,7 +26,7 @@
 #include "rde.h"
 
 intrde_filter_match(struct filter_rule *

Re: Allow bgpd to filter on the nexthop attribute

2012-11-10 Thread Claudio Jeker
On Sat, Nov 10, 2012 at 03:38:15PM +0100, Claudio Jeker wrote:
> In some cases it helps to be able to restrict nexthops from pathes
> received. E.g. at IXP where only routes originating from the neighbor
> should be accepted.
> 
> This diff implements this for bgpd.

Updated diff that fixes a missing break. Found by Florian.

-- 
:wq Claudio

Index: bgpd.conf.5
===
RCS file: /cvs/src/usr.sbin/bgpd/bgpd.conf.5,v
retrieving revision 1.121
diff -u -p -r1.121 bgpd.conf.5
--- bgpd.conf.5 24 Aug 2012 17:04:06 -  1.121
+++ bgpd.conf.5 28 Oct 2012 13:38:06 -
@@ -1175,6 +1175,17 @@ is repeated more than
 .Ar len
 times.
 .Pp
+.It Ic nexthop Ar address
+This rule applies only to
+.Em UPDATES
+where the nexthop is equal to
+.Ar address.
+The
+.Ar address
+can be set to
+.Em neighbor
+in which case the nexthop is compared against the address of the neighbor.
+.Pp
 .It Xo
 .Ic prefix
 .Ar address Ns Li / Ns Ar len
Index: bgpd.h
===
RCS file: /cvs/src/usr.sbin/bgpd/bgpd.h,v
retrieving revision 1.273
diff -u -p -r1.273 bgpd.h
--- bgpd.h  18 Sep 2012 10:10:00 -  1.273
+++ bgpd.h  28 Oct 2012 13:00:03 -
@@ -749,6 +749,13 @@ struct filter_prefix {
u_int8_tlen;
 };
 
+struct filter_nexthop {
+   struct bgpd_addraddr;
+   u_int8_tflags;
+#define FILTER_NEXTHOP_ADDR1
+#define FILTER_NEXTHOP_NEIGHBOR2
+};
+
 struct filter_prefixlen {
enum comp_ops   op;
u_int8_taid;
@@ -759,6 +766,7 @@ struct filter_prefixlen {
 struct filter_match {
struct filter_prefixprefix;
struct filter_prefixlen prefixlen;
+   struct filter_nexthop   nexthop;
struct filter_asas;
struct filter_aslen aslen;
struct filter_community community;
Index: parse.y
===
RCS file: /cvs/src/usr.sbin/bgpd/parse.y,v
retrieving revision 1.264
diff -u -p -r1.264 parse.y
--- parse.y 23 Sep 2012 09:39:17 -  1.264
+++ parse.y 28 Oct 2012 13:29:16 -
@@ -1700,6 +1700,26 @@ filter_elm   : filter_prefix_h   {
}
fmopts.aid = AID_INET6;
}
+   | NEXTHOP address   {
+   if (fmopts.m.nexthop.flags) {
+   yyerror("nexthop already specified");
+   YYERROR;
+   }
+   if (fmopts.aid && fmopts.aid != $2.aid) {
+   yyerror("nexthop address family doesn't match "
+   "rule address family");
+   YYERROR;
+   }
+   fmopts.m.nexthop.addr = $2;
+   fmopts.m.nexthop.flags = FILTER_NEXTHOP_ADDR;
+   }
+   | NEXTHOP NEIGHBOR  {
+   if (fmopts.m.nexthop.flags) {
+   yyerror("nexthop already specified");
+   YYERROR;
+   }
+   fmopts.m.nexthop.flags = FILTER_NEXTHOP_NEIGHBOR;
+   }
;
 
 prefixlenop: unaryop NUMBER{
Index: printconf.c
===
RCS file: /cvs/src/usr.sbin/bgpd/printconf.c,v
retrieving revision 1.88
diff -u -p -r1.88 printconf.c
--- printconf.c 23 Sep 2012 09:39:18 -  1.88
+++ printconf.c 28 Oct 2012 13:33:58 -
@@ -561,6 +561,13 @@ print_rule(struct peer *peer_l, struct f
}
}
 
+   if (r->match.nexthop.flags) {
+   if (r->match.nexthop.flags == FILTER_NEXTHOP_NEIGHBOR)
+   printf("nexthop neighbor ");
+   else
+   printf("nexthop %s ", log_addr(&r->match.nexthop.addr));
+   }
+
if (r->match.as.type) {
if (r->match.as.type == AS_ALL)
printf("AS %s ", log_as(r->match.as.as));
Index: rde_filter.c
===
RCS file: /cvs/src/usr.sbin/bgpd/rde_filter.c,v
retrieving revision 1.67
diff -u -p -r1.67 rde_filter.c
--- rde_filter.c20 Sep 2011 21:19:06 -  1.67
+++ rde_filter.c10 Nov 2012 17:50:31 -
@@ -384,6 +384,34 @@ rde_filter_match(struct filter_rule *f, 
}
/* NOTREACHED */
}
+   if (f->match.nexthop.flags != 0) {
+   struct bgpd_addr *nexthop, *cmpaddr;
+   if (asp->nexthop == NULL)
+   /* no nexthop, skip */
+   return (0);
+   nexthop = &asp->nexthop->exit_nexthop;
+   if (f->match

Re: Small memcpy optimization

2012-11-10 Thread Stefan Fritsch

On Thu, 8 Nov 2012, Mark Kettenis wrote:

On Tuesday 21 August 2012, Stefan Fritsch wrote:

On x86, the xchg operation between reg and mem has an implicit lock
prefix, i.e. it is a relatively expensive atomic operation. This is
not needed here.


OKs, anyone?


What you say makes sense, although it might matter only on MP
(capable) systems.


True, but MP is the norm nowadays.


If you really want to make things faster, I
suppose you could change the code into something like

   pushl   %esi
   pushl   %edi
   movl12(%esp),%edi
   movl16(%esp),%esi


That's true. Like this (suggestions for a better label name are 
welcome):


--- locore.s
+++ locore.s
@@ -789,7 +789,7 @@ ENTRY(bcopy)
pushl   %edi
movl12(%esp),%esi
movl16(%esp),%edi
-   movl20(%esp),%ecx
+bcopy2:movl20(%esp),%ecx
movl%edi,%eax
subl%esi,%eax
cmpl%ecx,%eax   # overlapping?
@@ -827,13 +827,15 @@ ENTRY(bcopy)
ret

 /*
- * Emulate memcpy() by swapping the first two arguments and calling bcopy()
+ * Emulate memcpy() by loading the first two arguments in reverse order
+ * and jumping into bcopy()
  */
 ENTRY(memcpy)
-   movl4(%esp),%ecx
-   xchg8(%esp),%ecx
-   movl%ecx,4(%esp)
-   jmp _C_LABEL(bcopy)
+   pushl   %esi
+   pushl   %edi
+   movl12(%esp),%edi
+   movl16(%esp),%esi
+   jmp bcopy2

 /*/



Re: Small memcpy optimization

2012-11-10 Thread Stefan Fritsch
On Thursday 08 November 2012, Ted Unangst wrote:
> On Thu, Nov 01, 2012 at 22:43, Stefan Fritsch wrote:
> > On Tuesday 21 August 2012, Stefan Fritsch wrote:
> >> On x86, the xchg operation between reg and mem has an implicit
> >> lock prefix, i.e. it is a relatively expensive atomic
> >> operation. This is not needed here.
> > 
> > OKs, anyone?
> 
> What do other implementations do?  Benchmarks?  I'm sure
> someone somewhere has spent a lot of effort making the world's
> fastest memcpy.  Taking that work seems better than home grown
> fiddling.

Other implementations don't call bcopy, so that's not really 
applicable here. To make bcopy faster, one would probably use 
different implementations depending on CPU features (SSE3, ...). Or 
maybe use gcc's __builtin_memcpy(), but one would need to check if 
there are any caveats when using that in kernel space.



Allow bgpd to filter on the nexthop attribute

2012-11-10 Thread Claudio Jeker
In some cases it helps to be able to restrict nexthops from pathes
received. E.g. at IXP where only routes originating from the neighbor
should be accepted.

This diff implements this for bgpd.
OK?
-- 
:wq Claudio

Index: bgpd.conf.5
===
RCS file: /cvs/src/usr.sbin/bgpd/bgpd.conf.5,v
retrieving revision 1.121
diff -u -p -r1.121 bgpd.conf.5
--- bgpd.conf.5 24 Aug 2012 17:04:06 -  1.121
+++ bgpd.conf.5 28 Oct 2012 13:38:06 -
@@ -1175,6 +1175,17 @@ is repeated more than
 .Ar len
 times.
 .Pp
+.It Ic nexthop Ar address
+This rule applies only to
+.Em UPDATES
+where the nexthop is equal to
+.Ar address.
+The
+.Ar address
+can be set to
+.Em neighbor
+in which case the nexthop is compared against the address of the neighbor.
+.Pp
 .It Xo
 .Ic prefix
 .Ar address Ns Li / Ns Ar len
Index: bgpd.h
===
RCS file: /cvs/src/usr.sbin/bgpd/bgpd.h,v
retrieving revision 1.273
diff -u -p -r1.273 bgpd.h
--- bgpd.h  18 Sep 2012 10:10:00 -  1.273
+++ bgpd.h  28 Oct 2012 13:00:03 -
@@ -749,6 +749,13 @@ struct filter_prefix {
u_int8_tlen;
 };
 
+struct filter_nexthop {
+   struct bgpd_addraddr;
+   u_int8_tflags;
+#define FILTER_NEXTHOP_ADDR1
+#define FILTER_NEXTHOP_NEIGHBOR2
+};
+
 struct filter_prefixlen {
enum comp_ops   op;
u_int8_taid;
@@ -759,6 +766,7 @@ struct filter_prefixlen {
 struct filter_match {
struct filter_prefixprefix;
struct filter_prefixlen prefixlen;
+   struct filter_nexthop   nexthop;
struct filter_asas;
struct filter_aslen aslen;
struct filter_community community;
Index: parse.y
===
RCS file: /cvs/src/usr.sbin/bgpd/parse.y,v
retrieving revision 1.264
diff -u -p -r1.264 parse.y
--- parse.y 23 Sep 2012 09:39:17 -  1.264
+++ parse.y 28 Oct 2012 13:29:16 -
@@ -1700,6 +1700,26 @@ filter_elm   : filter_prefix_h   {
}
fmopts.aid = AID_INET6;
}
+   | NEXTHOP address   {
+   if (fmopts.m.nexthop.flags) {
+   yyerror("nexthop already specified");
+   YYERROR;
+   }
+   if (fmopts.aid && fmopts.aid != $2.aid) {
+   yyerror("nexthop address family doesn't match "
+   "rule address family");
+   YYERROR;
+   }
+   fmopts.m.nexthop.addr = $2;
+   fmopts.m.nexthop.flags = FILTER_NEXTHOP_ADDR;
+   }
+   | NEXTHOP NEIGHBOR  {
+   if (fmopts.m.nexthop.flags) {
+   yyerror("nexthop already specified");
+   YYERROR;
+   }
+   fmopts.m.nexthop.flags = FILTER_NEXTHOP_NEIGHBOR;
+   }
;
 
 prefixlenop: unaryop NUMBER{
Index: printconf.c
===
RCS file: /cvs/src/usr.sbin/bgpd/printconf.c,v
retrieving revision 1.88
diff -u -p -r1.88 printconf.c
--- printconf.c 23 Sep 2012 09:39:18 -  1.88
+++ printconf.c 28 Oct 2012 13:33:58 -
@@ -561,6 +561,13 @@ print_rule(struct peer *peer_l, struct f
}
}
 
+   if (r->match.nexthop.flags) {
+   if (r->match.nexthop.flags == FILTER_NEXTHOP_NEIGHBOR)
+   printf("nexthop neighbor ");
+   else
+   printf("nexthop %s ", log_addr(&r->match.nexthop.addr));
+   }
+
if (r->match.as.type) {
if (r->match.as.type == AS_ALL)
printf("AS %s ", log_as(r->match.as.as));
Index: rde_filter.c
===
RCS file: /cvs/src/usr.sbin/bgpd/rde_filter.c,v
retrieving revision 1.67
diff -u -p -r1.67 rde_filter.c
--- rde_filter.c20 Sep 2011 21:19:06 -  1.67
+++ rde_filter.c29 Oct 2012 06:55:06 -
@@ -384,6 +384,33 @@ rde_filter_match(struct filter_rule *f, 
}
/* NOTREACHED */
}
+   if (f->match.nexthop.flags != 0) {
+   struct bgpd_addr *nexthop, *cmpaddr;
+   if (asp->nexthop == NULL)
+   /* no nexthop, skip */
+   return (0);
+   nexthop = &asp->nexthop->exit_nexthop;
+   if (f->match.nexthop.flags == FILTER_NEXTHOP_ADDR)
+   cmpaddr = &f->match.nexthop.addr;
+   else
+   

cwm rename iter to i (consistency)

2012-11-10 Thread Thomas Pfaff
Since we all seem to be playing with cwm these days, here's a patch
that renames iter to i used in for-loops.  conf.c used both, while
the rest of the code used i so I chose to use i.

Index: conf.c
===
RCS file: /cvs/xenocara/app/cwm/conf.c,v
retrieving revision 1.108
diff -u -p -r1.108 conf.c
--- conf.c  9 Nov 2012 03:52:02 -   1.108
+++ conf.c  10 Nov 2012 13:39:12 -
@@ -446,16 +446,15 @@ conf_bindname(struct conf *c, char *name
 {
struct keybinding   *current_binding;
char*substring, *tmp;
-   int  iter;
+   int  i;
 
current_binding = xcalloc(1, sizeof(*current_binding));
 
if ((substring = strchr(name, '-')) != NULL) {
-   for (iter = 0; iter < nitems(bind_mods); iter++) {
-   if ((tmp = strchr(name, bind_mods[iter].chr)) !=
+   for (i = 0; i < nitems(bind_mods); i++) {
+   if ((tmp = strchr(name, bind_mods[i].chr)) !=
NULL && tmp < substring) {
-   current_binding->modmask |=
-   bind_mods[iter].mask;
+   current_binding->modmask |= bind_mods[i].mask;
}
}
 
@@ -487,13 +486,13 @@ conf_bindname(struct conf *c, char *name
return;
}
 
-   for (iter = 0; iter < nitems(name_to_kbfunc); iter++) {
-   if (strcmp(name_to_kbfunc[iter].tag, binding) != 0)
+   for (i = 0; i < nitems(name_to_kbfunc); i++) {
+   if (strcmp(name_to_kbfunc[i].tag, binding) != 0)
continue;
 
-   current_binding->callback = name_to_kbfunc[iter].handler;
-   current_binding->flags = name_to_kbfunc[iter].flags;
-   current_binding->argument = name_to_kbfunc[iter].argument;
+   current_binding->callback = name_to_kbfunc[i].handler;
+   current_binding->flags = name_to_kbfunc[i].flags;
+   current_binding->argument = name_to_kbfunc[i].argument;
conf_grab(c, current_binding);
TAILQ_INSERT_TAIL(&c->keybindingq, current_binding, entry);
return;
@@ -548,16 +547,15 @@ conf_mousebind(struct conf *c, char *nam
struct mousebinding *current_binding;
char*substring, *tmp;
const char  *errstr;
-   int  iter;
+   int  i;
 
current_binding = xcalloc(1, sizeof(*current_binding));
 
if ((substring = strchr(name, '-')) != NULL) {
-   for (iter = 0; iter < nitems(bind_mods); iter++) {
-   if ((tmp = strchr(name, bind_mods[iter].chr)) !=
+   for (i = 0; i < nitems(bind_mods); i++) {
+   if ((tmp = strchr(name, bind_mods[i].chr)) !=
NULL && tmp < substring) {
-   current_binding->modmask |=
-   bind_mods[iter].mask;
+   current_binding->modmask |= bind_mods[i].mask;
}
}
 
@@ -578,12 +576,12 @@ conf_mousebind(struct conf *c, char *nam
return;
}
 
-   for (iter = 0; iter < nitems(name_to_mousefunc); iter++) {
-   if (strcmp(name_to_mousefunc[iter].tag, binding) != 0)
+   for (i = 0; i < nitems(name_to_mousefunc); i++) {
+   if (strcmp(name_to_mousefunc[i].tag, binding) != 0)
continue;
 
-   current_binding->context = name_to_mousefunc[iter].context;
-   current_binding->callback = name_to_mousefunc[iter].handler;
+   current_binding->context = name_to_mousefunc[i].context;
+   current_binding->callback = name_to_mousefunc[i].handler;
TAILQ_INSERT_TAIL(&c->mousebindingq, current_binding, entry);
return;
}



Re: athn@usb: fixup detach panic

2012-11-10 Thread Stefan Sperling
On Sat, Nov 10, 2012 at 03:52:37AM +0100, Mike Belopuhov wrote:
> On Tue, Nov 06, 2012 at 12:15 +0100, Stefan Sperling wrote:
> > It seems more appropriate to handle this problem entirely within
> > the USB-specific layer of the driver, rather than within dev/ic/athn.c.
> > 
> > If loading the firmware fails, athn_usb_attachhook() doesn't even
> > call athn_attach(). This is what your fix is compensating for. I believe
> > athn_usb_detach() shouldn't be calling athn_detach() unconditionally.
> > 
> > I fixed a similar problem for acx(4) cardbus cards once, where ejecting
> > a card that had failed to attach half way through paniced the kernel.
> > This was in r1.12 of dev/cardbus/if_acx_cardbus.c, which looked like this:
> > 
> 
> works for me. ok?

Yes!
 
> Index: dev/usb/if_athn_usb.c
> ===
> RCS file: /home/cvs/src/sys/dev/usb/if_athn_usb.c,v
> retrieving revision 1.8
> diff -u -p -r1.8 if_athn_usb.c
> --- dev/usb/if_athn_usb.c 3 Jul 2011 15:47:17 -   1.8
> +++ dev/usb/if_athn_usb.c 10 Nov 2012 02:04:12 -
> @@ -289,7 +289,8 @@ athn_usb_detach(struct device *self, int
>   struct athn_usb_softc *usc = (struct athn_usb_softc *)self;
>   struct athn_softc *sc = &usc->sc_sc;
>  
> - athn_detach(sc);
> + if (usc->sc_athn_attached)
> + athn_detach(sc);
>  
>   /* Wait for all async commands to complete. */
>   athn_usb_wait_async(usc);
> @@ -347,6 +348,7 @@ athn_usb_attachhook(void *xsc)
>   splx(s);
>   return;
>   }
> + usc->sc_athn_attached = 1;
>   /* Override some operations for USB. */
>   ifp->if_ioctl = athn_usb_ioctl;
>   ifp->if_start = athn_usb_start;
> Index: dev/usb/if_athn_usb.h
> ===
> RCS file: /home/cvs/src/sys/dev/usb/if_athn_usb.h,v
> retrieving revision 1.2
> diff -u -p -r1.2 if_athn_usb.h
> --- dev/usb/if_athn_usb.h 8 Jan 2011 15:18:01 -   1.2
> +++ dev/usb/if_athn_usb.h 10 Nov 2012 02:04:33 -
> @@ -417,6 +417,7 @@ struct athn_usb_host_cmd_ring {
>  struct athn_usb_softc {
>   struct athn_softc   sc_sc;
>  #define usb_dev  sc_sc.sc_dev
> + int sc_athn_attached;
>  
>   /* USB specific goo. */
>   usbd_device_handle  sc_udev;