Re: Patches for improving npppd with rdomain support

2016-03-01 Thread David Gwynne

> On 2 Mar 2016, at 02:32, Claer  wrote:
> 
> Hello dear developers,
> 
> I asked a friend, Mathieu Papineau, to help me with an issue I have with 
> npppd.
> For a project here, I thought building multitenancy firewall with rdomain
> support. For remote access, I wanted to use npppd to be able to authenticate
> users in different domains in their respective domains using RADIUS.
> 
> After some infructuous tests, it appears that npppd wasn't designed to support
> rdomains. Mathieu developed the following patches to support the
> functionnality I wished. Actually, due to the current limitation, it only
> works with tun devices. The pppx driver does not support rdomain ioctls yet.
> 
> The serie contains 12 patches, I'll try to post one per mail for easier 
> review.
> 
> Thanks for review!
> 
> Claer

hey claer,

i had a quick look at the changes here and have a bit of feedback.

firstly, i am concerned about setting the rdomain associated with the kernel 
interface in a separate ioctl. doing it that way allows for a race between when 
the interface is configured and when the rdomain is set. it is possible packets 
could move in an rdomain theyre not supposed to in that window, no matter how 
small it is.

instead i would look at setting the rdomain when the session is created as part 
of struct pipex_session_req (see src/sys/net/pipex.h). in fact there is already 
a pr_rdomain member waiting to be uncommented and used.

unfortunately that would invalidate a large chunk of the changes in the diffs 
you provided, and would require changes to the kernel to make pipex (and 
hopefully pppx) respect the rdomain userland provides. overall i think it will 
be simpler though.

lastly, i really like the idea you're proposing. it would be very cool to see 
working.

cheers,
dlg


bump the max_linkhdr size from 16 bytes to 64

2016-03-01 Thread David Gwynne
the max_link hdr is basically how much space to reserve before an
ip packet for link headers, eg, ethernet.

16 bytes was a good choice when everything was just ip inside
ethernet, but now we deal with a bunch of encapsulations which blow
that out of the water. 16 bytes isnt even enough if we have to
inject a vlan tag ourselves.

im suggesting 64 because it will comfortably allow you to encap an
ethernet header inside of an ip protocol. i think it is even enough
to accomodate vxlan overhead.

the caveat to this is that it changes the watermark for what is the
smallest packet that can go into an mbuf. currently the space in
an mbuf with headers is about 184 bytes. with a max_linkhdr of 16
that would allow a 168 byte ip packet. after this you can put a 120
byte packet in.

however, most ip packets are either small (think keystrokes over
ssh, ACKs, or dns lookups) or full sized (always greater than MHLEN
anyway). this change therefore has minimal impact on the majority
of traffic, except to make prepending encap headers a lot cheaper.

ok?

Index: uipc_domain.c
===
RCS file: /cvs/src/sys/kern/uipc_domain.c,v
retrieving revision 1.43
diff -u -p -r1.43 uipc_domain.c
--- uipc_domain.c   4 Sep 2015 08:43:39 -   1.43
+++ uipc_domain.c   2 Mar 2016 03:49:33 -
@@ -89,8 +89,8 @@ domaininit(void)
(*pr->pr_init)();
}
 
-   if (max_linkhdr < 16)   /* XXX */
-   max_linkhdr = 16;
+   if (max_linkhdr < 64)   /* XXX */
+   max_linkhdr = 64;
max_hdr = max_linkhdr + max_protohdr;
timeout_set(_timeout, pffasttimo, _timeout);
timeout_set(_timeout, pfslowtimo, _timeout);



mpw(4) vlan handling

2016-03-01 Thread David Gwynne
ive got a large reworking of vlan(4) to make vlan tx mpsafe, which
affected mpw(4).

the biggest effect was that it was no longer safe to traverse the
interface parent hierarchy looking for vlan interfaces. however,
from what i could tell from the rfc, such traversal is unecessary.

this refactors the code so it only reinject vlan headers in tagged
mode for vlan interfaces in the same bridge as it. in raw mode it
just sends the packet as is. this is based on my interpretation of
4.4.1 in rfc4448.

this also has the benefit that you can assign local addresses on
mpw interfaces in raw mode and talk over them without making the
machine panic. it should also be possible to assign addresses on
tagged interfaces too.

to be clear, not traversing the vlan interface parents is necessary
for making vlan itself mpsafe. i am confident we're still within
spec without that functionality, and actually get simplifications
and semantic improvements out of it this way.

this diff relies on the vlan_input() code i sent to tech@

ok?

Index: if_mpw.c
===
RCS file: /cvs/src/sys/net/if_mpw.c,v
retrieving revision 1.12
diff -u -p -r1.12 if_mpw.c
--- if_mpw.c5 Dec 2015 10:07:55 -   1.12
+++ if_mpw.c2 Mar 2016 01:36:49 -
@@ -351,164 +351,51 @@ extern void vlan_start(struct ifnet *ifp
 struct mbuf *
 mpw_vlan_handle(struct mbuf *m, struct mpw_softc *sc)
 {
-   int needsdummy = 0;
-   int fakeifv = 0;
-   struct ifvlan *ifv = NULL;
-   struct ether_vlan_header *evh;
-   struct ifnet *ifp, *ifp0;
-   int nvlan, moff;
-   struct ether_header eh;
-   struct ifvlan fifv;
-   struct vlan_shim {
-   uint16_tvs_tpid;
-   uint16_tvs_tci;
-   } vs;
-
-   ifp = ifp0 = if_get(m->m_pkthdr.ph_ifidx);
-   KASSERT(ifp != NULL);
-   if (ifp->if_start == vlan_start)
-   ifv = ifp->if_softc;
-
-   /* If we were relying on VLAN HW support, fake an ifv */
-   if (ifv == NULL && (m->m_flags & M_VLANTAG) == M_VLANTAG) {
-   memset(, 0, sizeof(fifv));
-   fifv.ifv_tag = EVL_VLANOFTAG(m->m_pkthdr.ether_vtag);
-   fifv.ifv_prio = EVL_PRIOFTAG(m->m_pkthdr.ether_vtag);
-   ifv = 
-   fakeifv = 1;
-   }
-
-   /*
-* Always remove VLAN flag as we are inserting them here. Also we
-* might get a tagged packet with no VLAN interface, in this case
-* we can't do anything.
-*/
-   m->m_flags &= ~M_VLANTAG;
-
-   /*
-* Do VLAN managing.
-*
-* Case ethernet (raw):
-*  No VLAN: just pass it.
-*  One or more VLANs: insert VLAN tag back.
-*
-* NOTE: In case of raw access mode, the if_vlan will do the job
-* of dropping non tagged packets for us.
-*/
-   if (sc->sc_type == IMR_TYPE_ETHERNET && ifv == NULL) {
-   if_put(ifp0);
-   return (m);
-   }
-
-   /*
-* Case ethernet-tagged:
-*  0 VLAN: Drop packet
-*  1 VLAN: Tag packet with dummy VLAN
-*  >1 VLAN: Nothing
-*/
-   if (sc->sc_type == IMR_TYPE_ETHERNET_TAGGED && ifv == NULL) {
-   m_freem(m);
-   if_put(ifp0);
-   return (NULL);
-   }
-
-   /* Copy and remove ethernet header */
-   m_copydata(m, 0, sizeof(eh), (caddr_t) );
-   if (ntohs(eh.ether_type) == ETHERTYPE_VLAN ||
-   ntohs(eh.ether_type) == ETHERTYPE_QINQ)
-   m_adj(m, sizeof(*evh));
-   else
-   m_adj(m, sizeof(eh));
-
-   /* Count VLAN stack size */
-   nvlan = 0;
-   while ((ifp = ifv->ifv_p) != NULL && ifp->if_start == vlan_start) {
-   ifv = ifp->if_softc;
-   nvlan++;
-   }
-   moff = sizeof(*evh) + (nvlan * EVL_ENCAPLEN);
-
-   /* The mode ethernet tagged always need at least 2 VLANs */
-   if (sc->sc_type == IMR_TYPE_ETHERNET_TAGGED && nvlan == 0) {
-   needsdummy = 1;
-   moff += EVL_ENCAPLEN;
-   }
-
-   /* Add VLAN to the beginning of the packet */
-   M_PREPEND(m, moff, M_NOWAIT);
-   if (m == NULL) {
-   if_put(ifp0);
-   return (NULL);
-   }
-
-   /* Copy original ethernet type */
-   moff -= sizeof(eh.ether_type);
-   m_copyback(m, moff, sizeof(eh.ether_type), _type, M_NOWAIT);
-
-   /* Fill inner VLAN values */
-   ifv = ifp0->if_softc;
-   while (nvlan-- > 0) {
-   vs.vs_tci = htons((ifv->ifv_prio << EVL_PRIO_BITS) +
-   ifv->ifv_tag);
-   vs.vs_tpid = htons(ifv->ifv_type);
-
-   moff -= sizeof(vs);
-   m_copyback(m, moff, sizeof(vs), , M_NOWAIT);
-
-   ifp = ifv->ifv_p;
-   ifv = ifp->if_softc;
-   }
-
-   /* Copy ethernet header back */
-   evh = mtod(m, struct 

Re: zaurus: disentangle zboot from compat/linux

2016-03-01 Thread Jonathan Gray
On Sun, Feb 28, 2016 at 05:25:06PM +0100, Christian Weisgerber wrote:
> This disentangles the zaurus bootstrap from compat/linux.
> 
> We only need a small subset of syscall numbers and constants, so
> this moves the definitions directly into zboot/compat_linux.h.
> Compared to compat/linux/*.h, I skipped various intermediate typedefs
> and defines.
> 
> It's silly to have half of the termios defines prefixed by LINUX_
> and the other half not, so I've unified the usage without the prefix.
> 
> THIS DIFF SHOULD NOT CAUSE ANY BINARY CHANGES.
> 
> (I don't have access to an arm machine.  I compiled the .c files
> on a different platform, and there were no code changes, although
> in two instances a local bss symbol changed its name suffix.)
> 
> This could use some double checking and verification that unixsys.o
> doesn't change.

After changing the Makefile to make it build on armv7, it looks like the
diff causes the checksums on the following to change:

(MD5) diskprobe.o: FAILED
(MD5) exit.o: FAILED
(MD5) unixsys.o: FAILED
(MD5) zboot: FAILED

In the case of unixsys.o the diff in the .s looks like:

@@ -53,7 +50,7 @@
 .text; .align 0; .globl uselect; .type uselect,#function; uselect:;
  str r4, [sp, #-4]!
  ldr r4, [sp, #4]
- swi (0x90 +142)
+ swi (0x90 +82)
  ldr r4, [sp], #4
  cmn r0, #4096
  movcc pc, lr

You've used the wrong number for select, should be:

linux/linux_syscall.h:#define   LINUX_SYS_select142

diskprobe diff:

@@ -344,7 +344,7 @@ bios_getdiskinfo:
 .L66:
.align  2
 .L65:
-   .word   path.2502
+   .word   path.2337
.word   .LC3
.word   .LC0
.size   bios_getdiskinfo, .-bios_getdiskinfo
@@ -387,8 +387,8 @@ diskprobe:
strbr2, [r5, #2]
strbr2, [r5, #3]
strbr5, [r5, #4]
-   mov r9, r2
str r2, [fp, #-52]
+   mov r9, r2
mov r7, r2
 .L68:
mov r0, #452
@@ -551,7 +551,7 @@ diskprobe:
 .L86:
.align  2
 .L85:
-   .word   C.0.2450
+   .word   C.0.2285
.word   disklist
.word   .LC4
.word   -1610612224
@@ -565,13 +565,13 @@ diskprobe:
.size   timeout, 4
 timeout:
.word   10
-   .local  path.2502
-   .comm   path.2502,1024,1
+   .local  path.2337
+   .comm   path.2337,1024,1
.section.rodata
.align  2
-   .type   C.0.2450, %object
-   .size   C.0.2450, 8
-C.0.2450:
+   .type   C.0.2285, %object
+   .size   C.0.2285, 8
+C.0.2285:
.word   128
.word   130
.comm   disklist,8,1

exit diff:

@@ -67,8 +67,8 @@ panic:
 .L15:
.align  2
 .L14:
-   .word   paniced.1926
+   .word   paniced.1761
.word   .LC0
.size   panic, .-panic
-   .local  paniced.1926
-   .comm   paniced.1926,4,4
+   .local  paniced.1761
+   .comm   paniced.1761,4,4

> 
> 
> Index: compat_linux.h
> ===
> RCS file: /cvs/src/sys/arch/zaurus/stand/zboot/compat_linux.h,v
> retrieving revision 1.9
> diff -u -p -r1.9 compat_linux.h
> --- compat_linux.h28 Feb 2016 15:36:25 -  1.9
> +++ compat_linux.h28 Feb 2016 16:11:39 -
> @@ -20,12 +20,6 @@
>  
>  #ifndef _LOCORE
>  
> -#include 
> -#include 
> -#include 
> -struct proc;
> -#include 
> -
>  #define  INT_LIMIT(x)(~((x)1 << (sizeof(x)*8 - 1)))
>  #define  OFFSET_MAX  INT_LIMIT(long long)
>  #define  OFFT_OFFSET_MAX INT_LIMIT(long)
> @@ -36,43 +30,97 @@ struct proc;
>  #undef   SEEK_SET
>  #undef   SEEK_CUR
>  
> -#define O_RDONLY LINUX_O_RDONLY
> -#define O_WRONLY LINUX_O_WRONLY
> -#define O_RDWR   LINUX_O_RDWR
> +#define O_RDONLY 0x
> +#define O_WRONLY 0x0001
> +#define O_RDWR   0x0002
>  #define SEEK_SET 0
>  #define SEEK_CUR 1
>  
>  #define  LINUX_EOVERFLOW 75
>  
> -#define termios  linux_termios
> -
> -#define IMAXBEL  LINUX_IMAXBEL
> -#define IGNBRK   LINUX_IGNBRK
> -#define BRKINT   LINUX_BRKINT
> -#define PARMRK   LINUX_PARMRK
> -#define ISTRIP   LINUX_ISTRIP
> -#define INLCRLINUX_INLCR
> -#define IGNCRLINUX_IGNCR
> -#define ICRNLLINUX_ICRNL
> -#define IXON LINUX_IXON
> -#define OPOSTLINUX_OPOST
> -#define ECHO LINUX_ECHO
> -#define ECHONL   LINUX_ECHONL
> -#define ICANON   LINUX_ICANON
> -#define ISIG LINUX_ISIG
> -#define IEXTEN   LINUX_IEXTEN
> -#define CSIZELINUX_CSIZE
> -#define PARENB   LINUX_PARENB
> -#define CS8  LINUX_CS8
> -
> 

factor out vlan header injection

2016-03-01 Thread David Gwynne
this factors out the vlan shim header injection as vlan_inject()

i intend to use this code in mpw in an upcoming diff.

ok?

Index: if_vlan.c
===
RCS file: /cvs/src/sys/net/if_vlan.c,v
retrieving revision 1.151
diff -u -p -r1.151 if_vlan.c
--- if_vlan.c   13 Jan 2016 03:18:26 -  1.151
+++ if_vlan.c   2 Mar 2016 01:16:26 -
@@ -274,21 +274,12 @@ vlan_start(struct ifnet *ifp)
(prio << EVL_PRIO_BITS);
m->m_flags |= M_VLANTAG;
} else {
-   struct ether_vlan_header evh;
-
-   m_copydata(m, 0, ETHER_HDR_LEN, (caddr_t));
-   evh.evl_proto = evh.evl_encap_proto;
-   evh.evl_encap_proto = htons(ifv->ifv_type);
-   evh.evl_tag = htons(ifv->ifv_tag +
-   (prio << EVL_PRIO_BITS));
-   m_adj(m, ETHER_HDR_LEN);
-   M_PREPEND(m, sizeof(evh), M_DONTWAIT);
+   m = vlan_inject(m, ifv->ifv_type, ifv->ifv_tag |
+(prio << EVL_PRIO_BITS));
if (m == NULL) {
ifp->if_oerrors++;
continue;
}
-   m_copyback(m, 0, sizeof(evh), , M_NOWAIT);
-   m->m_flags &= ~M_VLANTAG;
}
 
if (if_enqueue(p, m)) {
@@ -298,6 +289,26 @@ vlan_start(struct ifnet *ifp)
ifp->if_opackets++;
}
 }
+
+struct mbuf *
+vlan_inject(struct mbuf *m, uint16_t type, uint16_t tag)
+{
+   struct ether_vlan_header evh;
+
+   m_copydata(m, 0, ETHER_HDR_LEN, (caddr_t));
+   evh.evl_proto = evh.evl_encap_proto;
+   evh.evl_encap_proto = htons(type);
+   evh.evl_tag = htons(tag);
+   m_adj(m, ETHER_HDR_LEN);
+   M_PREPEND(m, sizeof(evh), M_DONTWAIT);
+   if (m == NULL)
+   return (NULL);
+
+   m_copyback(m, 0, sizeof(evh), , M_NOWAIT);
+   CLR(m->m_flags, M_VLANTAG);
+
+   return (m);
+ }
 
 /*
  * vlan_input() returns 1 if it has consumed the packet, 0 otherwise.
Index: if_vlan_var.h
===
RCS file: /cvs/src/sys/net/if_vlan_var.h,v
retrieving revision 1.31
diff -u -p -r1.31 if_vlan_var.h
--- if_vlan_var.h   3 Dec 2015 16:27:32 -   1.31
+++ if_vlan_var.h   2 Mar 2016 01:16:26 -
@@ -98,6 +98,8 @@ structifvlan {
 #defineifv_prioifv_mib.ifvm_prio
 #defineifv_typeifv_mib.ifvm_type
 #defineIFVF_PROMISC0x01
+
+struct mbuf*vlan_inject(struct mbuf *, uint16_t, uint16_t);
 #endif /* _KERNEL */
 
 #endif /* _NET_IF_VLAN_VAR_H_ */



Re: ddb/x86: backtrace with bpt on 'syscall'

2016-03-01 Thread Mike Larkin
On Tue, Mar 01, 2016 at 11:50:28PM +0100, Martin Pieuchot wrote:
> Trying to get a backtrace after setting a breakpoint on the ``syscall''
> symbol on ddb(4) does not work well.  On am64 it faults:
> 
>   Breakpoint at   syscall:pushq   %rbp
>   ddb{0}> tr
>   syscall() at syscall
>   Xsyscall() at Xsyscall+0xcb
>   uvm_fault(0xff000f6c3100, 0x1008, 0, 1) -> e
>   kernel: page fault trap, code=0
>   Faulted in DDB; continuing...
> 
> This is simply because the logic in db_stack_trace_print()/db_nextframe()
> is rather simple and assume the first frame is completely in kernel.
> 
> The diff below improves the situation, but is not completely correct
> since we cannot really compare the frame pointers.
> 
>   Breakpoint at   syscall:pushq   %rbp
>   ddb{0}> tr
>   syscall() at syscall
>   --- syscall (number 74) ---
>   Bad user frame pointer: 0x1000
>   end trace frame: 0x1000, count: -1
>   0x70116b2845a:
> 
> I'm interested in any input as I'm facing the same problem when I'm
> instrumenting any kernel entry point.  But if you think the approach
> below is still a step forward I'll happily commit it.

The diff below seems to improve things, so I would say go for it.

-ml

> 
> 
> Index: arch/amd64/amd64/db_trace.c
> ===
> RCS file: /cvs/src/sys/arch/amd64/amd64/db_trace.c,v
> retrieving revision 1.16
> diff -u -p -r1.16 db_trace.c
> --- arch/amd64/amd64/db_trace.c   1 Mar 2016 21:35:13 -   1.16
> +++ arch/amd64/amd64/db_trace.c   1 Mar 2016 22:49:10 -
> @@ -176,7 +176,7 @@ db_stack_trace_print(db_expr_t addr, boo
>  char *modif, int (*pr)(const char *, ...))
>  {
>   struct callframe *frame, *lastframe;
> - long*argp;
> + long*argp, *arg0;
>   db_addr_t   callpc;
>   int is_trap = 0;
>   boolean_t   kernel_only = TRUE;
> @@ -235,7 +235,7 @@ db_stack_trace_print(db_expr_t addr, boo
>   offset = 0;
>   }
>   }
> - if (INKERNEL(frame) && name) {
> + if (INKERNEL(callpc) && name) {
>   if (!strcmp(name, "trap")) {
>   is_trap = TRAP;
>   } else if (!strcmp(name, "ast")) {
> @@ -265,14 +265,15 @@ db_stack_trace_print(db_expr_t addr, boo
>   if (lastframe == 0 && offset == 0 && !have_addr) {
>   /*
>* We have a breakpoint before the frame is set up
> -  * Use %esp instead
> +  * Use %rsp instead
>*/
> - argp = &((struct callframe 
> *)(ddb_regs.tf_rsp-8))->f_arg0;
> + arg0 =
> + &((struct callframe *)(ddb_regs.tf_rsp-8))->f_arg0;
>   } else {
> - argp = >f_arg0;
> + arg0 = >f_arg0;
>   }
>  
> - while (narg) {
> + for (argp = arg0; narg > 0; ) {
>   (*pr)("%lx", db_get_value((db_addr_t)argp, 8, FALSE));
>   argp++;
>   if (--narg != 0)
> @@ -282,7 +283,7 @@ db_stack_trace_print(db_expr_t addr, boo
>   db_printsym(callpc, DB_STGY_PROC, pr);
>   (*pr)("\n");
>  
> - if (lastframe == 0 && offset == 0 && !have_addr) {
> + if (lastframe == 0 && offset == 0 && !have_addr && !is_trap) {
>   /* Frame really belongs to next callpc */
>   lastframe = (struct callframe *)(ddb_regs.tf_rsp-8);
>   callpc = (db_addr_t)
> @@ -299,9 +300,11 @@ db_stack_trace_print(db_expr_t addr, boo
>* trapframe as with syscalls and traps.
>*/
>   frame = (struct callframe *)>f_retaddr;
> + arg0 = >f_arg0;
>   }
> +
>   lastframe = frame;
> - db_nextframe(, , >f_arg0, is_trap, pr);
> + db_nextframe(, , arg0, is_trap, pr);
>  
>   if (frame == 0) {
>   /* end of chain */
> Index: arch/i386/i386/db_trace.c
> ===
> RCS file: /cvs/src/sys/arch/i386/i386/db_trace.c,v
> retrieving revision 1.18
> diff -u -p -r1.18 db_trace.c
> --- arch/i386/i386/db_trace.c 1 Mar 2016 21:35:13 -   1.18
> +++ arch/i386/i386/db_trace.c 1 Mar 2016 22:32:08 -
> @@ -158,7 +158,7 @@ db_stack_trace_print(db_expr_t addr, boo
>  char *modif, int (*pr)(const char *, ...))
>  {
>   struct callframe *frame, *lastframe;
> - int *argp;
> + int *argp, *arg0;
>   db_addr_t   callpc;
>   int is_trap = 0;
>   boolean_t   kernel_only = TRUE;
> @@ -224,7 +224,7 @@ db_stack_trace_print(db_expr_t addr, boo
> 

Re: ddb: show regs with address

2016-03-01 Thread Mike Larkin
On Tue, Mar 01, 2016 at 11:58:57PM +0100, Martin Pieuchot wrote:
> As explained previously I'm implementing an instrumentation system based
> on ddb(4) and relying on breakpoints to execute kernel probes.
> 
> For debugging purposes I need a way to dump the content of the registers
> when a breakpoint-not-for-ddb(4) fired.  So I hacked the "show regs" to
> dump the registers at a specified address if one was given.
> 
> I'd like to put this in, any objection?  Comment?
> 
> While here I merged db_print.c into db_command.c, I'm making some room
> before adding new files ;)
> 
> If I get any ok I'll update the manual.
> 

Can you give an example of how this would be used and what the output
would look like?

-ml

> Index: ddb/db_command.c
> ===
> RCS file: /cvs/src/sys/ddb/db_command.c,v
> retrieving revision 1.68
> diff -u -p -r1.68 db_command.c
> --- ddb/db_command.c  25 Jan 2016 14:30:30 -  1.68
> +++ ddb/db_command.c  1 Mar 2016 22:28:26 -
> @@ -43,12 +43,14 @@
>  #include 
>  #include   /* type definitions */
>  
> +#include 
>  #include 
>  #include 
>  #include 
>  #include 
>  #include 
>  #include 
> +#include 
>  #include 
>  #include 
>  #include 
> @@ -788,4 +790,41 @@ db_stack_trace_cmd(db_expr_t addr, boole
>  char *modif)
>  {
>   db_stack_trace_print(addr, have_addr, count, modif, db_printf);
> +}
> +
> +void
> +db_show_regs(db_expr_t addr, int have_addr, db_expr_t count, char *modif)
> +{
> + struct db_variable *regp;
> + db_regs_t   *regs;
> + db_expr_t   value, offset;
> + char*name;
> + charfmt[28];
> +
> + if (have_addr)
> + regs = (db_regs_t *)addr;
> + else
> + regs = _regs;
> +
> + for (regp = db_regs; regp < db_eregs; regp++) {
> + if (have_addr) {
> + value = db_get_value(addr, sizeof(long), 0);
> + addr += sizeof(long);
> + } else {
> + db_read_variable(regp, );
> + }
> +
> + db_printf("%-12s%s", regp->name, db_format(fmt, sizeof(fmt),
> + (long)value, DB_FORMAT_N, 1, sizeof(long) * 3));
> + db_find_xtrn_sym_and_offset((db_addr_t)value, , );
> + if (name != NULL && offset <= db_maxoff && offset != value) {
> + db_printf("\t%s", name);
> + if (offset != 0) {
> + db_printf("+%s", db_format(fmt, sizeof(fmt),
> +   (long)offset, DB_FORMAT_R, 1, 0));
> + }
> + }
> + db_printf("\n");
> + }
> + db_print_loc_and_inst(PC_REGS(regs));
>  }
> Index: ddb/db_print.c
> ===
> RCS file: /cvs/src/sys/ddb/db_print.c,v
> retrieving revision 1.16
> diff -u -p -r1.16 db_print.c
> --- ddb/db_print.c25 Jan 2016 14:30:30 -  1.16
> +++ ddb/db_print.c1 Mar 2016 22:23:06 -
> @@ -1,69 +0,0 @@
> -/*   $OpenBSD: db_print.c,v 1.16 2016/01/25 14:30:30 mpi Exp $   */
> -/*   $NetBSD: db_print.c,v 1.5 1996/02/05 01:57:11 christos Exp $*/
> -
> -/*
> - * Mach Operating System
> - * Copyright (c) 1993,1992,1991,1990 Carnegie Mellon University
> - * All Rights Reserved.
> - *
> - * Permission to use, copy, modify and distribute this software and its
> - * documentation is hereby granted, provided that both the copyright
> - * notice and this permission notice appear in all copies of the
> - * software, derivative works or modified versions, and any portions
> - * thereof, and that both notices appear in supporting documentation.
> - *
> - * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
> - * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
> - * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
> - *
> - * Carnegie Mellon requests users of this software to return to
> - *
> - *  Software Distribution Coordinator  or  software.distribut...@cs.cmu.edu
> - *  School of Computer Science
> - *  Carnegie Mellon University
> - *  Pittsburgh PA 15213-3890
> - *
> - * any improvements or extensions that they make and grant Carnegie Mellon
> - * the rights to redistribute these changes.
> - *
> - *   Author: David B. Golub, Carnegie Mellon University
> - *   Date:   7/90
> - */
> -
> -/*
> - * Miscellaneous printing.
> - */
> -#include 
> -#include 
> -
> -#include 
> -
> -#include 
> -#include 
> -#include 
> -#include 
> -
> -/*ARGSUSED*/
> -void
> -db_show_regs(db_expr_t addr, int have_addr, db_expr_t count, char *modif)
> -{
> - struct db_variable *regp;
> - db_expr_t   value, offset;
> - char *  name;
> - chartmpfmt[28];
> -
> - for (regp = db_regs; regp < db_eregs; regp++) {
> - db_read_variable(regp, );
> - db_printf("%-12s%s", regp->name, db_format(tmpfmt, 

ddb: show regs with address

2016-03-01 Thread Martin Pieuchot
As explained previously I'm implementing an instrumentation system based
on ddb(4) and relying on breakpoints to execute kernel probes.

For debugging purposes I need a way to dump the content of the registers
when a breakpoint-not-for-ddb(4) fired.  So I hacked the "show regs" to
dump the registers at a specified address if one was given.

I'd like to put this in, any objection?  Comment?

While here I merged db_print.c into db_command.c, I'm making some room
before adding new files ;)

If I get any ok I'll update the manual.

Index: ddb/db_command.c
===
RCS file: /cvs/src/sys/ddb/db_command.c,v
retrieving revision 1.68
diff -u -p -r1.68 db_command.c
--- ddb/db_command.c25 Jan 2016 14:30:30 -  1.68
+++ ddb/db_command.c1 Mar 2016 22:28:26 -
@@ -43,12 +43,14 @@
 #include 
 #include /* type definitions */
 
+#include 
 #include 
 #include 
 #include 
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -788,4 +790,41 @@ db_stack_trace_cmd(db_expr_t addr, boole
 char *modif)
 {
db_stack_trace_print(addr, have_addr, count, modif, db_printf);
+}
+
+void
+db_show_regs(db_expr_t addr, int have_addr, db_expr_t count, char *modif)
+{
+   struct db_variable *regp;
+   db_regs_t   *regs;
+   db_expr_t   value, offset;
+   char*name;
+   charfmt[28];
+
+   if (have_addr)
+   regs = (db_regs_t *)addr;
+   else
+   regs = _regs;
+
+   for (regp = db_regs; regp < db_eregs; regp++) {
+   if (have_addr) {
+   value = db_get_value(addr, sizeof(long), 0);
+   addr += sizeof(long);
+   } else {
+   db_read_variable(regp, );
+   }
+
+   db_printf("%-12s%s", regp->name, db_format(fmt, sizeof(fmt),
+   (long)value, DB_FORMAT_N, 1, sizeof(long) * 3));
+   db_find_xtrn_sym_and_offset((db_addr_t)value, , );
+   if (name != NULL && offset <= db_maxoff && offset != value) {
+   db_printf("\t%s", name);
+   if (offset != 0) {
+   db_printf("+%s", db_format(fmt, sizeof(fmt),
+ (long)offset, DB_FORMAT_R, 1, 0));
+   }
+   }
+   db_printf("\n");
+   }
+   db_print_loc_and_inst(PC_REGS(regs));
 }
Index: ddb/db_print.c
===
RCS file: /cvs/src/sys/ddb/db_print.c,v
retrieving revision 1.16
diff -u -p -r1.16 db_print.c
--- ddb/db_print.c  25 Jan 2016 14:30:30 -  1.16
+++ ddb/db_print.c  1 Mar 2016 22:23:06 -
@@ -1,69 +0,0 @@
-/* $OpenBSD: db_print.c,v 1.16 2016/01/25 14:30:30 mpi Exp $   */
-/* $NetBSD: db_print.c,v 1.5 1996/02/05 01:57:11 christos Exp $*/
-
-/*
- * Mach Operating System
- * Copyright (c) 1993,1992,1991,1990 Carnegie Mellon University
- * All Rights Reserved.
- *
- * Permission to use, copy, modify and distribute this software and its
- * documentation is hereby granted, provided that both the copyright
- * notice and this permission notice appear in all copies of the
- * software, derivative works or modified versions, and any portions
- * thereof, and that both notices appear in supporting documentation.
- *
- * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
- * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
- * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
- *
- * Carnegie Mellon requests users of this software to return to
- *
- *  Software Distribution Coordinator  or  software.distribut...@cs.cmu.edu
- *  School of Computer Science
- *  Carnegie Mellon University
- *  Pittsburgh PA 15213-3890
- *
- * any improvements or extensions that they make and grant Carnegie Mellon
- * the rights to redistribute these changes.
- *
- * Author: David B. Golub, Carnegie Mellon University
- * Date:   7/90
- */
-
-/*
- * Miscellaneous printing.
- */
-#include 
-#include 
-
-#include 
-
-#include 
-#include 
-#include 
-#include 
-
-/*ARGSUSED*/
-void
-db_show_regs(db_expr_t addr, int have_addr, db_expr_t count, char *modif)
-{
-   struct db_variable *regp;
-   db_expr_t   value, offset;
-   char *  name;
-   chartmpfmt[28];
-
-   for (regp = db_regs; regp < db_eregs; regp++) {
-   db_read_variable(regp, );
-   db_printf("%-12s%s", regp->name, db_format(tmpfmt, sizeof tmpfmt,
- (long)value, DB_FORMAT_N, 1, sizeof(long) * 3));
-   db_find_xtrn_sym_and_offset((db_addr_t)value, , );
-   if (name != 0 && offset <= db_maxoff && offset != value) {
-   db_printf("\t%s", name);
-   if (offset != 0)
-   db_printf("+%s", db_format(tmpfmt, sizeof 

ddb/x86: backtrace with bpt on 'syscall'

2016-03-01 Thread Martin Pieuchot
Trying to get a backtrace after setting a breakpoint on the ``syscall''
symbol on ddb(4) does not work well.  On am64 it faults:

  Breakpoint at   syscall:pushq   %rbp
  ddb{0}> tr
  syscall() at syscall
  Xsyscall() at Xsyscall+0xcb
  uvm_fault(0xff000f6c3100, 0x1008, 0, 1) -> e
  kernel: page fault trap, code=0
  Faulted in DDB; continuing...

This is simply because the logic in db_stack_trace_print()/db_nextframe()
is rather simple and assume the first frame is completely in kernel.

The diff below improves the situation, but is not completely correct
since we cannot really compare the frame pointers.

  Breakpoint at   syscall:pushq   %rbp
  ddb{0}> tr
  syscall() at syscall
  --- syscall (number 74) ---
  Bad user frame pointer: 0x1000
  end trace frame: 0x1000, count: -1
  0x70116b2845a:

I'm interested in any input as I'm facing the same problem when I'm
instrumenting any kernel entry point.  But if you think the approach
below is still a step forward I'll happily commit it.


Index: arch/amd64/amd64/db_trace.c
===
RCS file: /cvs/src/sys/arch/amd64/amd64/db_trace.c,v
retrieving revision 1.16
diff -u -p -r1.16 db_trace.c
--- arch/amd64/amd64/db_trace.c 1 Mar 2016 21:35:13 -   1.16
+++ arch/amd64/amd64/db_trace.c 1 Mar 2016 22:49:10 -
@@ -176,7 +176,7 @@ db_stack_trace_print(db_expr_t addr, boo
 char *modif, int (*pr)(const char *, ...))
 {
struct callframe *frame, *lastframe;
-   long*argp;
+   long*argp, *arg0;
db_addr_t   callpc;
int is_trap = 0;
boolean_t   kernel_only = TRUE;
@@ -235,7 +235,7 @@ db_stack_trace_print(db_expr_t addr, boo
offset = 0;
}
}
-   if (INKERNEL(frame) && name) {
+   if (INKERNEL(callpc) && name) {
if (!strcmp(name, "trap")) {
is_trap = TRAP;
} else if (!strcmp(name, "ast")) {
@@ -265,14 +265,15 @@ db_stack_trace_print(db_expr_t addr, boo
if (lastframe == 0 && offset == 0 && !have_addr) {
/*
 * We have a breakpoint before the frame is set up
-* Use %esp instead
+* Use %rsp instead
 */
-   argp = &((struct callframe 
*)(ddb_regs.tf_rsp-8))->f_arg0;
+   arg0 =
+   &((struct callframe *)(ddb_regs.tf_rsp-8))->f_arg0;
} else {
-   argp = >f_arg0;
+   arg0 = >f_arg0;
}
 
-   while (narg) {
+   for (argp = arg0; narg > 0; ) {
(*pr)("%lx", db_get_value((db_addr_t)argp, 8, FALSE));
argp++;
if (--narg != 0)
@@ -282,7 +283,7 @@ db_stack_trace_print(db_expr_t addr, boo
db_printsym(callpc, DB_STGY_PROC, pr);
(*pr)("\n");
 
-   if (lastframe == 0 && offset == 0 && !have_addr) {
+   if (lastframe == 0 && offset == 0 && !have_addr && !is_trap) {
/* Frame really belongs to next callpc */
lastframe = (struct callframe *)(ddb_regs.tf_rsp-8);
callpc = (db_addr_t)
@@ -299,9 +300,11 @@ db_stack_trace_print(db_expr_t addr, boo
 * trapframe as with syscalls and traps.
 */
frame = (struct callframe *)>f_retaddr;
+   arg0 = >f_arg0;
}
+
lastframe = frame;
-   db_nextframe(, , >f_arg0, is_trap, pr);
+   db_nextframe(, , arg0, is_trap, pr);
 
if (frame == 0) {
/* end of chain */
Index: arch/i386/i386/db_trace.c
===
RCS file: /cvs/src/sys/arch/i386/i386/db_trace.c,v
retrieving revision 1.18
diff -u -p -r1.18 db_trace.c
--- arch/i386/i386/db_trace.c   1 Mar 2016 21:35:13 -   1.18
+++ arch/i386/i386/db_trace.c   1 Mar 2016 22:32:08 -
@@ -158,7 +158,7 @@ db_stack_trace_print(db_expr_t addr, boo
 char *modif, int (*pr)(const char *, ...))
 {
struct callframe *frame, *lastframe;
-   int *argp;
+   int *argp, *arg0;
db_addr_t   callpc;
int is_trap = 0;
boolean_t   kernel_only = TRUE;
@@ -224,7 +224,7 @@ db_stack_trace_print(db_expr_t addr, boo
offset = 0;
}
}
-   if (INKERNEL((int)frame) && name) {
+   if (INKERNEL(callpc) && name) {
if (!strcmp(name, "trap")) {
is_trap = 

Re: [patch] Fix carp(4) with balancing ip / ip-stealth

2016-03-01 Thread Martin Pieuchot
On 18/02/16(Thu) 16:46, Florian Riehm wrote:
> On 02/16/16 11:23, Martin Pieuchot wrote:
> > On 12/02/16(Fri) 16:33, Florian Riehm wrote:
> >> Hi Tech,
> >>
> >> I have noticed that CARP IP-Balancing is broken, so I am testing and
> >> fixing it.
> >>
> >> The first problem came in with this commit:
> >> http://cvsweb.openbsd.org/cgi-bin/cvsweb/src/sys/net/if_ethersubr.c.diff?r1=1.176=1.177
> >> It enforces that outgoing packets use the src mac of the carp interface 
> >> instead
> >> the mac of its carpdev. That's a good idea for failover carp but it breaks
> >> balancing ip(-stealth), because the same source MAC is seen by multiple
> >> switchports now. That leads to continues MAC flapping at switches.
> >> My attached patch fixes the problem. Thanks Martin's refactoring, we can
> >> enforce the right MAC on a central place in carp_start() now.
> > 
> > Can't you completely get rid of the else chunk then?  It looks like a
> > bad refactoring.
> 
> I was also thinking about deleting the else chunk. At the end I decided to 
> keep
> it, because I wasn't sure about its purpose.
> My intention was:
> Fix the more or less obviously broken balancing case and don't change the
> behavior of other CARP modes.
> I will remove the else chunk and do some more testing to determine if it's
> really unnecessary.
> 
> > I'm also wondering can't we use "sc_realmac" here?
> 
> I have not know "sc_realmac" until now. As far as I understand the intention 
> of
> the sc_realmac flag is, to indicate that the user has overwritten the mac
> address of the carp interface with the mac of its parent. I have never had a
> use case to do this. Without overwriting the mac by hand sc_realmac is 0 for
> carp with balancing ip/ip-stealth AND carp without balancing.
> 
> I don't see how sc_realmac could help us by this problem?!
> Can you give me a hint please?

It was an open question, if that does not make any sense, then don't do
it ;)

> >> A second problem was introduced two weeks ago. Since we always check the
> >> destination MAC address of received unicast packets, not only when in
> >> promiscuous mode, carp balancing ip is always broken, not only when in
> >> promiscuous mode. The new check collides with "Clear mcast if received on a
> >> carp IP balanced address." in carp_input().
> > 
> > Could you describe the problem?  Which Destination MAC the packet
> > contains and why it doesn't match the interface?  I still don't grok why
> > a carp(4) interface in balancing mode cannot have the right MAC
> > configured...  Do you know?  But if what you want is the parent's MAC,
> > then I'd rather go with the symmetric of your other change:  modify
> > carp_input() to overwrite ``ether_dhost''.
> 
> If using carp balancing, incoming packets contain the destination mac address
> of the carp interface, let's say: 01:00:5e:00:01:01.
> The MCAST-Bit is set here!
> 
> carp_input() removes the MCAST-Bit:
>   /*
>* Clear mcast if received on a carp IP balanced address.
>*/
>   if (sc->sc_balancing == CARP_BAL_IP &&
>   ETHER_IS_MULTICAST(eh->ether_dhost))
>   *(eh->ether_dhost) &= ~0x01;
> 
> Then we run into ether_input() and 
> memcmp(ac->ac_enaddr, eh->ether_dhost, ETHER_ADDR_LEN)
> evaluates to false because 
> ac->ac_enaddr (01:00:5e:00:01:01) != eh->ether_dhost (00:00:5e:00:01:01)

Taking a step back why do you want to clear the MULTICAST bit?

If it is just to differentiate between advertisement and normal traffic
couldn't we use a mbuf_tag(9) for CARP advertisement instead?  The tag
could be set in carp_input() and checked in carp_lsdrop() in the input
path.  It could also be used in the output path to get rid of the
horrible ``cur_vhe'' hack.



Re: x86 BPTTRAP

2016-03-01 Thread Martin Pieuchot
On 28/02/16(Sun) 17:34, Martin Pieuchot wrote:
> On 28/02/16(Sun) 17:02, Mike Belopuhov wrote:
> > On 28 February 2016 at 14:38, Martin Pieuchot  wrote:
> > > In order to dynamically instrument kernel functions, I plan to add
> > > breakpoints where a probe needs to be executed.  Trap handlers will
> > > be modified to check if the address of the trapping instruction
> > > correspond to a registered probe, and if that's the case, the kernel
> > > will execute the associated code.
> > >
> > > While implementing such mechanism for amd64 and i386, I discovered
> > > some differences in the existing code that only history seems to justify.
> > >
> > > So the diff below get rids of the BPTTRAP() and other small differences
> > > around 'calltrap' for these architectures.  In particular interrupts
> > > are now enabled unconditionally on i386 before entering trap().  Any
> > > counter indication for doing so?
> > >
> > 
> > That 'sti' that you're adding might have side effects, but I can't think of 
> > any
> > bad ones.  You'll get some funny 'sti', 'sti' sequences though since some
> > of the callers do 'sti' themselves (e.g resume_iret).
> > 
> > > I wonder if I should split i386's locore.s to match amd64's vector.S...
> > >
> > 
> > Technically i386 has apicvec.s which is what vectror.S on amd64
> > since the arch is specified to always have an APIC. Splitting it into
> > trap.S is another possibility, but I'm not sure it's worth it.  Possibly
> > moving actual APIC vector stubs to C is a better plan and then
> > vector.s will be up for the grabs.
> > 
> > > Comments, ok?
> > >
> > 
> > Honestly, I'd like the alltraps/sti bit to be handled separately even
> > if it's just for the purpose of sync'ing up two implementations.
> 
> Something like that first?

Any ok so we can start with the "interesting" part?  Or are you guys
hesitating because you want a trap.S first?

> Index: amd64/amd64/vector.S
> ===
> RCS file: /cvs/src/sys/arch/amd64/amd64/vector.S,v
> retrieving revision 1.44
> diff -u -p -r1.44 vector.S
> --- amd64/amd64/vector.S  8 Dec 2015 19:45:55 -   1.44
> +++ amd64/amd64/vector.S  28 Feb 2016 13:12:56 -
> @@ -96,24 +96,22 @@
>   * (possibly the next clock tick).  Thus, we disable interrupt before 
> checking,
>   * and only enable them again on the final `iret' or before calling the AST
>   * handler.
> - */ 
> + */
>  
>  
> /*/
>  
>  #define  TRAP(a) pushq $(a) ; jmp _C_LABEL(alltraps)
>  #define  ZTRAP(a)pushq $0 ; TRAP(a)
>  
> -#define  BPTTRAP(a)  ZTRAP(a)
> -
>   .text
>  IDTVEC(trap00)
>   ZTRAP(T_DIVIDE)
>  IDTVEC(trap01)
> - BPTTRAP(T_TRCTRAP)
> + ZTRAP(T_TRCTRAP)
>  IDTVEC(trap02)
>   ZTRAP(T_NMI)
>  IDTVEC(trap03)
> - BPTTRAP(T_BPTFLT)
> + ZTRAP(T_BPTFLT)
>  IDTVEC(trap04)
>   ZTRAP(T_OFLOW)
>  IDTVEC(trap05)
> @@ -245,7 +243,6 @@ NENTRY(resume_iret)
>  NENTRY(alltraps)
>   INTRENTRY
>   sti
> - .globl  calltrap
>  calltrap:
>   cld
>  #ifdef DIAGNOSTIC
> Index: i386/i386/locore.s
> ===
> RCS file: /cvs/src/sys/arch/i386/i386/locore.s,v
> retrieving revision 1.163
> diff -u -p -r1.163 locore.s
> --- i386/i386/locore.s26 Feb 2016 02:25:09 -  1.163
> +++ i386/i386/locore.s28 Feb 2016 16:25:34 -
> @@ -1308,14 +1308,14 @@ ENTRY(savectx)
>   * handler.
>   *
>   * XXX - debugger traps are now interrupt gates so at least bdb doesn't lose
> - * control.  The sti's give the standard losing behaviour for ddb and kgdb.
> + * control. STI give the standard losing behaviour for ddb and kgdb.
>   */
>  #define  IDTVEC(name)ALIGN_TEXT; .globl X##name; X##name:
>  
>  #define  TRAP(a) pushl $(a) ; jmp _C_LABEL(alltraps)
>  #define  ZTRAP(a)pushl $0 ; TRAP(a)
> -#define  BPTTRAP(a)  testb $(PSL_I>>8),13(%esp) ; jz 1f ; sti ; 1: ; 
> \
> - TRAP(a)
> +#define STI  testb $(PSL_I>>8),13(%esp) ; jz 1f ; sti ; 1: ;
> +
>  
>   .text
>  IDTVEC(div)
> @@ -1328,12 +1328,13 @@ IDTVEC(dbg)
>   andb$~0xf,%al
>   movl%eax,%dr6
>   popl%eax
> - BPTTRAP(T_TRCTRAP)
> + STI
> + TRAP(T_TRCTRAP)
>  IDTVEC(nmi)
>   ZTRAP(T_NMI)
>  IDTVEC(bpt)
> - pushl   $0
> - BPTTRAP(T_BPTFLT)
> + STI
> + ZTRAP(T_BPTFLT)
>  IDTVEC(ofl)
>   ZTRAP(T_OFLOW)
>  IDTVEC(bnd)
> @@ -1447,6 +1448,10 @@ NENTRY(resume_pop_fs)
>   sti
>   jmp calltrap
>  
> +/*
> + * All traps go through here. Call the generic trap handler, and
> + * check for ASTs afterwards.
> + */
>  NENTRY(alltraps)
>   INTRENTRY
>  calltrap:
> 



Delete compat/* mentions from man pages

2016-03-01 Thread Christian Weisgerber
sys/compat/* is unhooked from the rest of the kernel and will go
away shortly.  This removes the remaining man page mentions I could
find.

Note: syscall.9 also mentions COMPAT_XX.  That appears to be a
generic feature in makesyscalls.sh (one not used by Linux compat),
so I'll leave it alone.


Index: share/man/man5/files.conf.5
===
RCS file: /cvs/src/share/man/man5/files.conf.5,v
retrieving revision 1.22
diff -u -p -r1.22 files.conf.5
--- share/man/man5/files.conf.5 1 Oct 2015 20:44:49 -   1.22
+++ share/man/man5/files.conf.5 1 Mar 2016 18:37:16 -
@@ -348,10 +348,6 @@ in the kernel configuration file does no
 Rules for architecture-dependent files, for the
 .Dq machine
 architecture.
-.It Pa sys/compat/emul/files.emul
-Rules for the
-.Dq emul
-operating system or subsystem emulation.
 .It Pa sys/dev/class/files.class
 Rules for the
 .Dq class
Index: share/man/man9/syscall.9
===
RCS file: /cvs/src/share/man/man9/syscall.9,v
retrieving revision 1.11
diff -u -p -r1.11 syscall.9
--- share/man/man9/syscall.915 Nov 2014 14:41:03 -  1.11
+++ share/man/man9/syscall.91 Mar 2016 18:46:29 -
@@ -229,17 +229,17 @@ to a value desired.
 a
 .Xr sh 1
 script for generating C files out of the syscall master file;
-.It Pa sys/{kern,compat/*}/syscalls.conf
+.It Pa sys/kern/syscalls.conf
 a configuration file for the shell script above;
-.It Pa sys/{kern,compat/*}/syscalls.master
+.It Pa sys/kern/syscalls.master
 master files describing names and numbers for the system calls;
-.It Pa sys/{kern/,compat/*/*_}syscalls.c
+.It Pa sys/kern/syscalls.c
 system call names lists;
-.It Pa sys/{kern/init,compat/*/*}_sysent.c
+.It Pa sys/kern/init_sysent.c
 system call switch tables;
-.It Pa sys/{sys/,compat/*/*_}syscallargs.h
+.It Pa sys/sys/syscallargs.h
 system call argument lists;
-.It Pa sys/{sys/,compat/*/*_}syscall.h
+.It Pa sys/sys/syscall.h
 system call numbers;
 .It Pa sys/sys/syscall_mi.h
 Machine-independent syscall entry end return handling.
-- 
Christian "naddy" Weisgerber  na...@mips.inka.de



Re: cpu.h: parens in macros

2016-03-01 Thread Michael McConville
Michal Mazurek wrote:
> I noticed these macros, I think they should have more parenthesis. I
> don't know how to test this though.

tentative ok mmcc@

> Index: sys/arch/alpha/include/cpu.h
> ===
> RCS file: /cvs/src/sys/arch/alpha/include/cpu.h,v
> retrieving revision 1.55
> diff -u -p -r1.55 cpu.h
> --- sys/arch/alpha/include/cpu.h  2 Jul 2015 01:33:59 -   1.55
> +++ sys/arch/alpha/include/cpu.h  1 Mar 2016 18:57:50 -
> @@ -320,7 +320,7 @@ do {  
> \
>  #define signotify(p) aston(p)
>  #endif
>  
> -#define  aston(p)(p)->p_md.md_astpending = 1
> +#define  aston(p)((p)->p_md.md_astpending = 1)
>  #endif /* _KERNEL */
>  
>  /*
> Index: sys/arch/mips64/include/cpu.h
> ===
> RCS file: /cvs/src/sys/arch/mips64/include/cpu.h,v
> retrieving revision 1.108
> diff -u -p -r1.108 cpu.h
> --- sys/arch/mips64/include/cpu.h 5 Jan 2016 05:27:54 -   1.108
> +++ sys/arch/mips64/include/cpu.h 1 Mar 2016 18:57:50 -
> @@ -318,12 +318,12 @@ voidcp0_calibrate(struct cpu_info *);
>   * process as soon as possible.
>   */
>  #ifdef MULTIPROCESSOR
> -#define  signotify(p)(aston(p), cpu_unidle(p->p_cpu))
> +#define  signotify(p)(aston(p), cpu_unidle((p)->p_cpu))
>  #else
>  #define  signotify(p)aston(p)
>  #endif
>  
> -#define  aston(p)p->p_md.md_astpending = 1
> +#define  aston(p)((p)->p_md.md_astpending = 1)
>  
>  #ifdef CPU_R8000
>  #define  mips_sync() __asm__ volatile ("lw $0, 0(%0)" :: \
> 
> -- 
> Michal Mazurek
> 



cpu.h: parens in macros

2016-03-01 Thread Michal Mazurek
I noticed these macros, I think they should have more parenthesis. I
don't know how to test this though.

Index: sys/arch/alpha/include/cpu.h
===
RCS file: /cvs/src/sys/arch/alpha/include/cpu.h,v
retrieving revision 1.55
diff -u -p -r1.55 cpu.h
--- sys/arch/alpha/include/cpu.h2 Jul 2015 01:33:59 -   1.55
+++ sys/arch/alpha/include/cpu.h1 Mar 2016 18:57:50 -
@@ -320,7 +320,7 @@ do {
\
 #define signotify(p)   aston(p)
 #endif
 
-#defineaston(p)(p)->p_md.md_astpending = 1
+#defineaston(p)((p)->p_md.md_astpending = 1)
 #endif /* _KERNEL */
 
 /*
Index: sys/arch/mips64/include/cpu.h
===
RCS file: /cvs/src/sys/arch/mips64/include/cpu.h,v
retrieving revision 1.108
diff -u -p -r1.108 cpu.h
--- sys/arch/mips64/include/cpu.h   5 Jan 2016 05:27:54 -   1.108
+++ sys/arch/mips64/include/cpu.h   1 Mar 2016 18:57:50 -
@@ -318,12 +318,12 @@ void  cp0_calibrate(struct cpu_info *);
  * process as soon as possible.
  */
 #ifdef MULTIPROCESSOR
-#definesignotify(p)(aston(p), cpu_unidle(p->p_cpu))
+#definesignotify(p)(aston(p), cpu_unidle((p)->p_cpu))
 #else
 #definesignotify(p)aston(p)
 #endif
 
-#defineaston(p)p->p_md.md_astpending = 1
+#defineaston(p)((p)->p_md.md_astpending = 1)
 
 #ifdef CPU_R8000
 #definemips_sync() __asm__ volatile ("lw $0, 0(%0)" :: \

-- 
Michal Mazurek



Re: df(1): remove unneeded includes

2016-03-01 Thread Michael McConville
Theo Buehler wrote:
> On Tue, Mar 01, 2016 at 12:37:17PM +0100, Theo Buehler wrote:
> > Wasn't this the part of your previous header cleanup that mmcc
> > decided not to commit for some reason? 
> 
> if mmcc no longer objects, this once more ok tb@

Right, I misunderstood which file this was removing unistd.h and
stdlib.h from. I'll commit.



Patches for improving npppd with rdomain support [11-12/12]

2016-03-01 Thread Claer
Hello,

Patches 11 & 12.


# HG changeset patch
# User MJP
# Date 1452862954 -3600
#  Fri Jan 15 14:02:34 2016 +0100
# Node ID 5c95b08cdd4fa9db47ced3b8b1a331dbdab41ec6
# Parent  842c1c22848e171f174cc45ba7b961883fc3c184
Feature: Configure interface with the specified rdomain.

diff -r 842c1c22848e -r 5c95b08cdd4f usr.sbin/npppd/npppd/npppd_iface.c
--- usr.sbin/npppd/npppd/npppd_iface.c  Fri Jan 15 14:02:34 2016 +0100
+++ usr.sbin/npppd/npppd/npppd_iface.c  Fri Jan 15 14:02:34 2016 +0100
@@ -87,6 +87,7 @@
 #endif
 
 static void  npppd_iface_network_input(npppd_iface *, u_char *, int);
+static int   npppd_iface_setup_rdomain(npppd_iface *);
 static int   npppd_iface_setup_ip(npppd_iface *);
 static void  npppd_iface_io_event_handler (int, short, void *);
 static int   npppd_iface_log (npppd_iface *, int, const char *, ...)
@@ -111,15 +112,28 @@
_this->using_pppx = iface->is_pppx;
_this->set_ip4addr = 1;
_this->ip4addr = iface->ip4addr;
+   _this->rdomain = iface->rdomain;
_this->ipcpconf = iface->ipcpconf;
_this->devf = -1;
_this->initialized = 1;
 }
 
 static int
+npppd_iface_setup_rdomain(npppd_iface *_this)
+{
+   if (priv_set_if_rdomain(_this->ifname, _this->rdomain) != 0) {
+   npppd_iface_log(_this, LOG_ERR,
+   "setting rdomain on %s failed: %m", _this->ifname);
+   return 1;
+   }
+
+   return 0;
+}
+
+static int
 npppd_iface_setup_ip(npppd_iface *_this)
 {
-   int sock, if_flags, changed;
+   int sock, if_flags, changed, old_rdomain;
struct in_addr gw, assigned;
struct sockaddr_in *sin0;
struct ifreq ifr;
@@ -152,6 +166,17 @@
if (assigned.s_addr != _this->ip4addr.s_addr)
changed = 1;
 
+   /* get rdomain which was assigned to interface */
+   if (priv_get_if_rdomain(_this->ifname, _rdomain) != 0) {
+   log_printf(LOG_ERR, "ioctl(,SIOCGIFRDOMAIN) failed: %m", 
__func__);
+   goto fail;
+   }
+   if (_this->rdomain != old_rdomain) {
+   changed = 1;
+   if (npppd_iface_setup_rdomain(_this) != 0)
+   goto fail;
+   }
+
if (priv_get_if_flags(_this->ifname, _flags) != 0) {
npppd_iface_log(_this, LOG_ERR,
"ioctl(,SIOCGIFFLAGS) failed: %m");
@@ -195,7 +220,7 @@
/* erase old route */
if (assigned.s_addr != 0) {
gw.s_addr = htonl(INADDR_LOOPBACK);
-   in_host_route_delete(, , _this->rdomain);
+   in_host_route_delete(, , old_rdomain);
}
 
assigned.s_addr = _this->ip4addr.s_addr;
@@ -252,9 +277,15 @@
_this->ipcpconf = iface->ipcpconf;
backup = _this->ip4addr;
_this->ip4addr = iface->ip4addr;
+   _this->rdomain = iface->rdomain;
 
-   if (_this->using_pppx)
+   if (_this->using_pppx) {
+   /* ifconfig tun1 rdomain X */
+   if (npppd_iface_setup_rdomain(_this) != 0)
+   return 1;
+
return 0;
+   }
if ((rval = npppd_iface_setup_ip(_this)) != 0)
return rval;
 
@@ -312,6 +343,9 @@
if (_this->using_pppx == 0) {
if (npppd_iface_setup_ip(_this) != 0)
goto fail;
+   } else {
+   if (npppd_iface_setup_rdomain(_this) != 0)
+   goto fail;
}
 
 #ifdef USE_NPPPD_PIPEX


# HG changeset patch
# User MJP
# Date 1452862954 -3600
#  Fri Jan 15 14:02:34 2016 +0100
# Node ID 51e9ae42d8660dcf396d3781b01e70e837f57107
# Parent  5c95b08cdd4fa9db47ced3b8b1a331dbdab41ec6
Documentation: Update the manual page (interface [rdomain]).

diff -r 5c95b08cdd4f -r 51e9ae42d866 usr.sbin/npppd/npppd/npppd.conf.5
--- usr.sbin/npppd/npppd/npppd.conf.5   Fri Jan 15 14:02:34 2016 +0100
+++ usr.sbin/npppd/npppd/npppd.conf.5   Fri Jan 15 14:02:34 2016 +0100
@@ -520,7 +520,7 @@
 .Ic interface
 setting is described below:
 .Pp
-.Ic interface Ar ifname Ic address Ar address Ic ipcp Ar ipcp
+.Ic interface Ar ifname Ic address Ar address Ic ipcp Ar ipcp Op Ic rdomain Ar 
rdomainid
 .Pp
 Use
 .Xr tun 4



Patches for improving npppd with rdomain support [8/12]

2016-03-01 Thread Claer
Hello,

Patch 8


# HG changeset patch
# User MJP
# Date 1452862954 -3600
#  Fri Jan 15 14:02:34 2016 +0100
# Node ID 55eeedfb0cb54ed0d91c7de080b507fc79f64c30
# Parent  8d76f9f8cc873602c8593b896133648cdedb6afd
Add: Introduce priv_get_if_rdomain() to get the rdomain of a device.

diff -r 8d76f9f8cc87 -r 55eeedfb0cb5 usr.sbin/npppd/npppd/privsep.c
--- usr.sbin/npppd/npppd/privsep.c  Fri Jan 15 14:02:34 2016 +0100
+++ usr.sbin/npppd/npppd/privsep.c  Fri Jan 15 14:02:34 2016 +0100
@@ -54,7 +54,8 @@
PRIVSEP_SET_IF_ADDR,
PRIVSEP_DEL_IF_ADDR,
PRIVSEP_GET_IF_FLAGS,
-   PRIVSEP_SET_IF_FLAGS
+   PRIVSEP_SET_IF_FLAGS,
+   PRIVSEP_GET_IF_RDOMAIN
 };
 
 struct PRIVSEP_OPEN_ARG {
@@ -126,6 +127,17 @@
int  flags;
 };
 
+struct PRIVSEP_GET_IF_RDOMAIN_ARG {
+   char ifname[IFNAMSIZ];
+   u_intrdomain;
+};
+
+struct PRIVSEP_GET_IF_RDOMAIN_RESP {
+   int  retval;
+   int  rerrno;
+   u_intrdomain;
+};
+
 struct PRIVSEP_COMMON_RESP {
int  retval;
int  rerrno;
@@ -164,6 +176,8 @@
struct PRIVSEP_GET_IF_FLAGS_ARG *);
 static int  privsep_npppd_check_set_if_flags (
struct PRIVSEP_SET_IF_FLAGS_ARG *);
+static int   privsep_npppd_check_get_if_rdomain (
+   struct PRIVSEP_GET_IF_RDOMAIN_ARG *);
 
 static int  privsep_sock = -1;
 static struct imsgbuf   privsep_ibuf;
@@ -512,6 +526,37 @@
return (privsep_common_resp());
 }
 
+int
+priv_get_if_rdomain(const char *ifname, int *prdomain)
+{
+   struct PRIVSEP_GET_IF_RDOMAIN_ARGa;
+   struct PRIVSEP_GET_IF_RDOMAIN_RESP  *r;
+   struct imsg  imsg;
+   int  retval = -1;
+
+   strlcpy(a.ifname, ifname, sizeof(a.ifname));
+   a.rdomain = 0;
+
+   (void)imsg_compose(_ibuf, PRIVSEP_GET_IF_RDOMAIN, 0, 0, -1,
+   , sizeof(a));
+   imsg_flush(_ibuf);
+
+   if (imsg_read_and_get(_ibuf, ) == -1)
+   return (-1);
+   if (imsg.hdr.len != IMSG_HEADER_SIZE + sizeof(*r))
+   errno = EACCES;
+   else {
+   r = imsg.data;
+   *prdomain = r->rdomain;
+   if (r->retval != 0)
+   errno = r->rerrno;
+   retval = r->retval;
+   }
+   imsg_free();
+
+   return (retval);
+}
+
 static int
 privsep_recvfd(void)
 {
@@ -946,6 +991,41 @@
imsg_flush(ibuf);
}
break;
+   case PRIVSEP_GET_IF_RDOMAIN: {
+   int s;
+   struct ifreqifr;
+   struct PRIVSEP_GET_IF_RDOMAIN_ARG  *a = imsg.data;
+   struct PRIVSEP_GET_IF_RDOMAIN_RESP  r;
+
+   memset(, 0, sizeof(r));
+   r.retval = -1;
+
+   if (imsg.hdr.len != IMSG_HEADER_SIZE + sizeof(*a))
+   r.rerrno = EINVAL;
+   else if (privsep_npppd_check_get_if_rdomain(a)) {
+   r.rerrno = EACCES;
+   } else {
+   memset(, 0, sizeof(ifr));
+   strlcpy(ifr.ifr_name, a->ifname,
+   sizeof(ifr.ifr_name));
+   if ((s = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
+   r.retval = -1;
+   r.rerrno = errno;
+   } else {
+   r.retval = 0;
+   if (ioctl(s, SIOCGIFRDOMAIN, ) == 
-1)
+   r.rdomain = 0;
+   else
+   r.rdomain = ifr.ifr_rdomainid;
+   }
+   if (s >= 0)
+   close(s);
+   }
+   (void)imsg_compose(ibuf, PRIVSEP_OK, 0, 0, -1,
+   , sizeof(r));
+   imsg_flush(ibuf);
+   }
+   break;
}
imsg_free();
}
@@ -1114,3 +1194,12 @@
 
return (1);
 }
+
+static int
+privsep_npppd_check_get_if_rdomain(struct PRIVSEP_GET_IF_RDOMAIN_ARG *arg)
+{
+   if (startswith(arg->ifname, "tun") || startswith(arg->ifname, "pppx") 
|| startswith(arg->ifname, "lo"))
+   return (0);
+
+   return (1);
+}
diff -r 8d76f9f8cc87 -r 55eeedfb0cb5 usr.sbin/npppd/npppd/privsep.h
--- usr.sbin/npppd/npppd/privsep.h  Fri Jan 15 14:02:34 2016 +0100
+++ 

Patches for improving npppd with rdomain support [9/12]

2016-03-01 Thread Claer
Hello,

Patch 9


# HG changeset patch
# User MJP
# Date 1452862954 -3600
#  Fri Jan 15 14:02:34 2016 +0100
# Node ID 97146d7e9ebbb07f93d734dbdd7afe942f5cc557
# Parent  55eeedfb0cb54ed0d91c7de080b507fc79f64c30
Add: Introduce priv_set_if_rdomain() to set the rdomain of a device.

diff -r 55eeedfb0cb5 -r 97146d7e9ebb usr.sbin/npppd/npppd/privsep.c
--- usr.sbin/npppd/npppd/privsep.c  Fri Jan 15 14:02:34 2016 +0100
+++ usr.sbin/npppd/npppd/privsep.c  Fri Jan 15 14:02:34 2016 +0100
@@ -55,7 +55,8 @@
PRIVSEP_DEL_IF_ADDR,
PRIVSEP_GET_IF_FLAGS,
PRIVSEP_SET_IF_FLAGS,
-   PRIVSEP_GET_IF_RDOMAIN
+   PRIVSEP_GET_IF_RDOMAIN,
+   PRIVSEP_SET_IF_RDOMAIN
 };
 
 struct PRIVSEP_OPEN_ARG {
@@ -138,6 +139,11 @@
u_intrdomain;
 };
 
+struct PRIVSEP_SET_IF_RDOMAIN_ARG {
+   char ifname[IFNAMSIZ];
+   u_intrdomain;
+};
+
 struct PRIVSEP_COMMON_RESP {
int  retval;
int  rerrno;
@@ -178,6 +184,8 @@
struct PRIVSEP_SET_IF_FLAGS_ARG *);
 static int   privsep_npppd_check_get_if_rdomain (
struct PRIVSEP_GET_IF_RDOMAIN_ARG *);
+static int   privsep_npppd_check_set_if_rdomain (
+   struct PRIVSEP_SET_IF_RDOMAIN_ARG *);
 
 static int  privsep_sock = -1;
 static struct imsgbuf   privsep_ibuf;
@@ -557,6 +565,21 @@
return (retval);
 }
 
+int
+priv_set_if_rdomain(const char *ifname, int rdomain)
+{
+   struct PRIVSEP_SET_IF_RDOMAIN_ARGa;
+
+   strlcpy(a.ifname, ifname, sizeof(a.ifname));
+   a.rdomain = rdomain;
+
+   (void)imsg_compose(_ibuf, PRIVSEP_SET_IF_RDOMAIN, 0, 0, -1,
+   , sizeof(a));
+   imsg_flush(_ibuf);
+
+   return (privsep_common_resp());
+}
+
 static int
 privsep_recvfd(void)
 {
@@ -1026,6 +1049,35 @@
imsg_flush(ibuf);
}
break;
+   case PRIVSEP_SET_IF_RDOMAIN: {
+   int   s;
+   struct ifreq  ifr;
+   struct PRIVSEP_SET_IF_RDOMAIN_ARG *a = imsg.data;
+   struct PRIVSEP_COMMON_RESPr = { -1, 0 };
+
+   if (imsg.hdr.len != IMSG_HEADER_SIZE + sizeof(*a))
+   r.rerrno = EINVAL;
+   else if (privsep_npppd_check_set_if_rdomain(a))
+   r.rerrno = EACCES;
+   else {
+   memset(, 0, sizeof(ifr));
+   strlcpy(ifr.ifr_name, a->ifname,
+   sizeof(ifr.ifr_name));
+   ifr.ifr_rdomainid = a->rdomain;
+   if ((s = socket(AF_INET, SOCK_DGRAM, 0)) < 0 ||
+   ioctl(s, SIOCSIFRDOMAIN, ) != 0) {
+   r.retval = -1;
+   r.rerrno = errno;
+   } else
+   r.retval = 0;
+   if (s >= 0)
+   close(s);
+   }
+   (void)imsg_compose(ibuf, PRIVSEP_OK, 0, 0, -1,
+   , sizeof(r));
+   imsg_flush(ibuf);
+   }
+   break;
}
imsg_free();
}
@@ -1203,3 +1255,12 @@
 
return (1);
 }
+
+static int
+privsep_npppd_check_set_if_rdomain(struct PRIVSEP_SET_IF_RDOMAIN_ARG *arg)
+{
+   if (startswith(arg->ifname, "tun") || startswith(arg->ifname, "pppx"))
+   return (0);
+
+   return (1);
+}
diff -r 55eeedfb0cb5 -r 97146d7e9ebb usr.sbin/npppd/npppd/privsep.h
--- usr.sbin/npppd/npppd/privsep.h  Fri Jan 15 14:02:34 2016 +0100
+++ usr.sbin/npppd/npppd/privsep.h  Fri Jan 15 14:02:34 2016 +0100
@@ -45,6 +45,7 @@
 int   priv_delete_if_addr(const char *);
 int   priv_set_if_flags(const char *, int);
 int   priv_get_if_flags(const char *, int *);
+int   priv_set_if_rdomain(const char *, int);
 int   priv_get_if_rdomain(const char *, int *);
 
 #ifdef __cplusplus



Patches for improving npppd with rdomain support [10/12]

2016-03-01 Thread Claer
Hello,

patch 10


# HG changeset patch
# User MJP
# Date 1452862954 -3600
#  Fri Jan 15 14:02:34 2016 +0100
# Node ID 842c1c22848e171f174cc45ba7b961883fc3c184
# Parent  97146d7e9ebbb07f93d734dbdd7afe942f5cc557
Add: Route functions handle rdomain.

diff -r 97146d7e9ebb -r 842c1c22848e usr.sbin/npppd/pppd/npppd.c
--- usr.sbin/npppd/npppd/npppd.cFri Jan 15 14:02:34 2016 +0100
+++ usr.sbin/npppd/npppd/npppd.cFri Jan 15 14:02:34 2016 +0100
@@ -588,7 +588,8 @@
if (is_first)
in_route_add(>snp_addr,
>snp_mask, ,
-   LOOPBACK_IFNAME, RTF_BLACKHOLE, 0);
+   LOOPBACK_IFNAME, RTF_BLACKHOLE, 0,
+   _this->iface[0].rdomain);
break;
 
case SNP_PPP:
@@ -601,14 +602,16 @@
ppp_framed_ip_address,
_iface(ppp)->ip4addr,
ppp_iface(ppp)->ifname,
-   MRU_IPMTU(ppp->peer_mru));
+   MRU_IPMTU(ppp->peer_mru),
+   ppp_iface(ppp)->rdomain);
} else {
in_route_add(>
ppp_framed_ip_address,
>ppp_framed_ip_netmask,
_iface(ppp)->ip4addr,
ppp_iface(ppp)->ifname, 0,
-   MRU_IPMTU(ppp->peer_mru));
+   MRU_IPMTU(ppp->peer_mru),
+   ppp_iface(ppp)->rdomain);
}
break;
}
@@ -1392,19 +1395,21 @@
 */
in_route_delete(>ppp_framed_ip_address,
>ppp_framed_ip_netmask, ,
-   RTF_BLACKHOLE);
+   RTF_BLACKHOLE, ppp_iface(ppp)->rdomain);
/* See the comment for MRU_IPMTU() on ppp.h */
if (ppp->ppp_framed_ip_netmask.s_addr == 0xL) {
in_host_route_add(>ppp_framed_ip_address,
_iface(ppp)->ip4addr,
ppp_iface(ppp)->ifname,
-   MRU_IPMTU(ppp->peer_mru));
+   MRU_IPMTU(ppp->peer_mru),
+   ppp_iface(ppp)->rdomain);
} else {
in_route_add(>ppp_framed_ip_address,
>ppp_framed_ip_netmask,
_iface(ppp)->ip4addr,
ppp_iface(ppp)->ifname, 0,
-   MRU_IPMTU(ppp->peer_mru));
+   MRU_IPMTU(ppp->peer_mru),
+   ppp_iface(ppp)->rdomain);
}
}
 #endif
@@ -1413,11 +1418,13 @@
if (_this->iface[ppp->ifidx].using_pppx == 0) {
if (ppp->ppp_framed_ip_netmask.s_addr == 0xL) {

in_host_route_delete(>ppp_framed_ip_address,
-   _iface(ppp)->ip4addr);
+   _iface(ppp)->ip4addr,
+   ppp_iface(ppp)->rdomain);
} else {
in_route_delete(>ppp_framed_ip_address,
>ppp_framed_ip_netmask,
-   _iface(ppp)->ip4addr, 0);
+   _iface(ppp)->ip4addr, 0,
+   ppp_iface(ppp)->rdomain);
}
if (ppp->snp.snp_next != NULL)
/*
@@ -1426,7 +1433,8 @@
 */
in_route_add(>snp.snp_addr,
>snp.snp_mask, , LOOPBACK_IFNAME,
-   RTF_BLACKHOLE, 0);
+   RTF_BLACKHOLE, 0,
+   ppp_iface(ppp)->rdomain);
}
 #endif
if (ppp->username[0] != '\0') {
@@ -1729,7 +1737,7 @@
radish = slist_itr_next();
in_route_delete((radish->rd_route)->sin_addr,
(radish->rd_mask)->sin_addr, ,
-   

Patches for improving npppd with rdomain support [7/12]

2016-03-01 Thread Claer
Hello,

Patch 7


# HG changeset patch
# User MJP
# Date 1452862954 -3600
#  Fri Jan 15 14:02:34 2016 +0100
# Node ID 8d76f9f8cc873602c8593b896133648cdedb6afd
# Parent  90fa2a12bfaa8776e883c168aaf39be0b16fea4d
Add: In the configuration file, define the rdomain of an interface.

diff -r 90fa2a12bfaa -r 8d76f9f8cc87 usr.sbin/npppd/npppd/npppd.h
--- usr.sbin/npppd/npppd/npppd.hFri Jan 15 14:02:05 2016 +0100
+++ usr.sbin/npppd/npppd/npppd.hFri Jan 15 14:02:34 2016 +0100
@@ -179,6 +179,7 @@
TAILQ_ENTRY(iface) entry;
char   name[IFNAMSIZ];
struct in_addr ip4addr;
+   intrdomain;
struct ipcpconf   *ipcpconf;
bool   is_pppx;
 };
diff -r 90fa2a12bfaa -r 8d76f9f8cc87 usr.sbin/npppd/npppd/parse.y
--- usr.sbin/npppd/npppd/parse.yFri Jan 15 14:02:05 2016 +0100
+++ usr.sbin/npppd/npppd/parse.yFri Jan 15 14:02:34 2016 +0100
@@ -132,7 +132,7 @@
 %token X_TIMEOUT MAX_TRIES MAX_FAILOVERS SECRET
 %token  POOL_ADDRESS DNS_SERVERS NBNS_SERVERS FOR STATIC DYNAMIC
 %token  RESOLVER ALLOW_USER_SELECTED_ADDRESS
-%token  INTERFACE ADDRESS IPCP
+%token INTERFACE ADDRESS IPCP RDOMAIN
 %token BIND FROM AUTHENTICATED BY TO
 %token ERROR
 %token   STRING
@@ -154,6 +154,7 @@
 %typeauthmethod
 %typeauthmethod_l
 %typeipcppooltype
+%typeifrdomain
 
 %%
 
@@ -853,7 +854,7 @@
 /*
  * interface
  */
-interface  : INTERFACE STRING ADDRESS in4_addr IPCP STRING {
+interface  : INTERFACE STRING ADDRESS in4_addr IPCP STRING ifrdomain {
int  cnt;
struct iface*n;
struct ipcpconf *ipcp;
@@ -887,6 +888,7 @@
strlcpy(n->name, $2, sizeof(n->name));
free($2);
n->ip4addr = $4;
+   n->rdomain = $7;
if (strncmp(n->name, "pppx", 4) == 0)
n->is_pppx = true;
 
@@ -895,6 +897,10 @@
}
;
 
+ifrdomain  : /* empty */ { $$ = 0; }
+   | RDOMAIN NUMBER  { $$ = $2; }
+   ;
+
 /*
  * bind
  */
@@ -1079,6 +1085,7 @@
{ "pptp-vendor-name", PPTP_VENDOR_NAME},
{ "protocol", PROTOCOL},
{ "radius",   RADIUS},
+   { "rdomain",  RDOMAIN},
{ "required", REQUIRED},
{ "resolver", RESOLVER},
{ "secret",   SECRET},



Patches for improving npppd with rdomain support [6/12]

2016-03-01 Thread Claer
Hello,

patch 6,


# HG changeset patch
# User MJP
# Date 1452862925 -3600
#  Fri Jan 15 14:02:05 2016 +0100
# Node ID 90fa2a12bfaa8776e883c168aaf39be0b16fea4d
# Parent  fd7f48f3955596de5fe098de0f4208106578c9db
Feature: Can listen on an interface with a specific rdomain.

diff -r fd7f48f39555 -r 90fa2a12bfaa usr.sbin/npppd/l2tp/l2tpd.c
--- usr.sbin/npppd/l2tp/l2tpd.c Fri Jan 15 13:38:16 2016 +0100
+++ usr.sbin/npppd/l2tp/l2tpd.c Fri Jan 15 14:02:05 2016 +0100
@@ -60,6 +60,7 @@
 #include "l2tp_local.h"
 #include "addr_range.h"
 #include "net_utils.h"
+#include/* for IF_NAMESIZE */
 
 #ifdef L2TPD_DEBUG
 #defineL2TPD_ASSERT(x) ASSERT(x)
@@ -261,7 +262,8 @@
 l2tpd_listener_start(l2tpd_listener *_this)
 {
l2tpd *_l2tpd;
-   intaf, lvl, opt, sock, ival;
+   intaf, lvl, opt, sock, ival, rdomain;
+   char   ifname[IF_NAMESIZE];
char   hbuf[NI_MAXHOST + NI_MAXSERV + 16];
 
_l2tpd = _this->self;
@@ -301,6 +303,23 @@
"setsockopt(,,SO_REUSEPORT) failed in %s(): %m", __func__);
goto fail;
}
+   rdomain = 0;
+   get_ifname_by_sockaddr((struct sockaddr *)&_this->bind, ifname);
+   if (strlen(ifname) > 0) {
+   if (ifname_get_rdomain(ifname, ) != 0) {
+   l2tpd_log(_l2tpd, LOG_ERR,
+   "ifname_get_rdomain(%s) failed in %s()", ifname, 
__func__);
+   goto fail;
+   }
+   }
+   if (rdomain != 0) {
+   if (setsockopt(sock, SOL_SOCKET, SO_RTABLE, ,
+   sizeof(rdomain)) == -1) {
+   l2tpd_log(_l2tpd, LOG_ERR,
+   "setsockopt(,,SO_RTABLE) failed in %s(): %m", 
__func__);
+   goto fail;
+   }
+   }
if (bind(sock, (struct sockaddr *)&_this->bind,
_this->bind.sin6.sin6_len) != 0) {
l2tpd_log(_l2tpd, LOG_ERR, "Binding %s/udp: %m",
@@ -401,9 +420,11 @@
l2tpd_io_event, _this);
event_add(&_this->ev_sock, NULL);
 
-   l2tpd_log(_l2tpd, LOG_INFO, "Listening %s/udp (L2TP LNS) [%s]",
+   l2tpd_log(_l2tpd, LOG_INFO, 
+   "Listening %s/udp (rdomain %i) (L2TP LNS) [%s]",
addrport_tostring((struct sockaddr *)&_this->bind,
-   _this->bind.sin6.sin6_len, hbuf, sizeof(hbuf)), _this->tun_name);
+   _this->bind.sin6.sin6_len, hbuf, sizeof(hbuf)), rdomain,
+   _this->tun_name);
 
return 0;
 fail:
diff -r fd7f48f39555 -r 90fa2a12bfaa usr.sbin/npppd/pptp/pptpd.c
--- usr.sbin/npppd/pptp/pptpd.c Fri Jan 15 13:38:16 2016 +0100
+++ usr.sbin/npppd/pptp/pptpd.c Fri Jan 15 14:02:05 2016 +0100
@@ -290,7 +290,8 @@
 static int
 pptpd_listener_start(pptpd_listener *_this)
 {
-   int sock, ival, sock_gre;
+   int sock, ival, sock_gre, rdomain;
+   char ifname[IF_NAMESIZE];
struct sockaddr_in bind_sin, bind_sin_gre;
int wildcardbinding;
 
@@ -327,6 +328,23 @@
"fcntl(F_SET_FL) failed at %s(): %m", __func__);
goto fail;
}
+   rdomain = 0;
+   get_ifname_by_sockaddr((struct sockaddr *)&_this->bind_sin, ifname);
+   if (strlen(ifname) > 0) {
+   if (ifname_get_rdomain(ifname, ) != 0) {
+   pptpd_log(_this->self, LOG_ERR,
+   "ifname_get_rdomain(%s) failed in %s()", ifname, 
__func__);
+   goto fail;
+   }
+   }
+   if (rdomain != 0) {
+   if (setsockopt(sock, SOL_SOCKET, SO_RTABLE, ,
+   sizeof(rdomain)) == -1) {
+   pptpd_log(_this->self, LOG_ERR,
+   "setsockopt(,,SO_RTABLE) failed in %s(): %m", 
__func__);
+   goto fail;
+   }
+   }
if (bind(sock, (struct sockaddr *)&_this->bind_sin,
_this->bind_sin.sin_len) != 0) {
pptpd_log(_this->self, LOG_ERR,
@@ -376,6 +394,14 @@
"fcntl(F_SET_FL) failed at %s(): %m", __func__);
goto fail;
}
+   if (rdomain != 0) {
+   if (setsockopt(sock_gre, SOL_SOCKET, SO_RTABLE, ,
+   sizeof(rdomain)) == -1) {
+   pptpd_log(_this->self, LOG_ERR,
+   "setsockopt(,,SO_RTABLE) failed in %s(): %m", 
__func__);
+   goto fail;
+   }
+   }
if (bind(sock_gre, (struct sockaddr *)_sin_gre,
bind_sin_gre.sin_len) != 0) {
pptpd_log(_this->self, LOG_ERR,



Patches for improving npppd with rdomain support [1/12]

2016-03-01 Thread Claer
Hello,

This patch fix an incorrect check.

# HG changeset patch
# User MJP
# Date 1452429700 -3600
#  Sun Jan 10 13:41:40 2016 +0100
# Node ID 5df6e3ec88c3933dd06ced5fd459921a8043cead
# Parent  e414626941ab329294b3d6c26657e1b2a509f5f0
Fix: "authconf.users_file_path" is a char[] but is checked as a char*.

diff -r e414626941ab -r 5df6e3ec88c3 usr.sbin/npppd/npppd/npppd_auth.c
--- usr.sbin/npppd/npppd/npppd_auth.c   Thu Dec 17 14:39:03 2015 +0100
+++ usr.sbin/npppd/npppd/npppd_auth.c   Sun Jan 10 13:41:40 2016 +0100
@@ -197,7 +197,7 @@
base->has_users_file = 0;
base->radius_ready = 0;
 
-   if (auth->users_file_path != NULL) {
+   if (strlen(auth->users_file_path) > 0) {
strlcpy(base->users_file_path, auth->users_file_path,
sizeof(base->users_file_path));
base->has_users_file = 1;



Patches for improving npppd with rdomain support [5/12]

2016-03-01 Thread Claer
Hello,

Patch 5


# HG changeset patch
# User MJP
# Date 1452861496 -3600
#  Fri Jan 15 13:38:16 2016 +0100
# Node ID fd7f48f3955596de5fe098de0f4208106578c9db
# Parent  52f96bbfc0cb83010e78d49b63a18bdc00a7
Add: Introduce common tools to get and set the rdomain of an interface.

diff -r 52f96bbfc0cb -r fd7f48f39555 usr.sbin/npppd/common/net_utils.c
--- usr.sbin/npppd/common/net_utils.c   Sun Jan 10 15:40:46 2016 +0100
+++ usr.sbin/npppd/common/net_utils.c   Fri Jan 15 13:38:16 2016 +0100
@@ -26,6 +26,7 @@
 /* $Id: net_utils.c,v 1.4 2012/05/08 13:18:37 yasuoka Exp $ */
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -206,3 +207,47 @@
 }
 return -1;
 }
+
+/** Get the rdomain of a network interface */
+int
+ifname_get_rdomain(char *ifname, int *rdomain)
+{
+   int s;
+   struct ifreq ifr;
+
+   *rdomain = 0;
+   memset(, 0, sizeof(ifr));
+   if (ifname)
+   strlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
+
+   s = socket(AF_INET, SOCK_DGRAM, 0);
+   if (s < 0)
+   return 1;
+   if (ioctl(s, SIOCGIFRDOMAIN, ) != -1)
+   *rdomain = ifr.ifr_rdomainid;
+   if (s >= 0)
+   close(s);
+
+   return 0;
+}
+
+/** Set the rdomain of a network interface */
+int
+ifname_set_rdomain(char *ifname, int rdomain)
+{
+   int s, result = 0;
+   struct ifreq ifr;
+
+   memset(, 0, sizeof(ifr));
+   if (ifname)
+   strlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
+   ifr.ifr_rdomainid = rdomain;
+
+   s = socket(AF_INET, SOCK_DGRAM, 0);
+   if (s < 0 || ioctl(s, SIOCSIFRDOMAIN, ) != 0)
+   result = 1;
+   if (s >= 0)
+   close(s);
+
+   return result;
+}
diff -r 52f96bbfc0cb -r fd7f48f39555 usr.sbin/npppd/common/net_utils.h
--- usr.sbin/npppd/common/net_utils.h   Sun Jan 10 15:40:46 2016 +0100
+++ usr.sbin/npppd/common/net_utils.h   Fri Jan 15 13:38:16 2016 +0100
@@ -33,6 +33,8 @@
 int addrport_parse(const char *, int, struct addrinfo **);
 const char *addrport_tostring(struct sockaddr *, socklen_t, char *, int);
 int netmask2prefixlen(uint32_t);
+int ifname_get_rdomain(char *, int *);
+int ifname_set_rdomain(char *, int);
 
 
 #ifdef __cplusplus



Patches for improving npppd with rdomain support [2-4/12]

2016-03-01 Thread Claer
Hello,

These patches add support for defining pid-file & control-socket from
configuration file.

Claer

# HG changeset patch
# User MJP
# Date 1452430850 -3600
#  Sun Jan 10 14:00:50 2016 +0100
# Node ID 12ffa641c5d987c3e1373f8a9156f4951faa54ed
# Parent  5df6e3ec88c3933dd06ced5fd459921a8043cead
Add: In the configuration file, define the PID file to use (set pid-file).

diff -r 5df6e3ec88c3 -r 12ffa641c5d9 usr.sbin/npppd/npppd/npppd.c
--- usr.sbin/npppd/npppd/npppd.cSun Jan 10 13:41:40 2016 +0100
+++ usr.sbin/npppd/npppd/npppd.cSun Jan 10 14:00:50 2016 +0100
@@ -310,6 +310,9 @@
}
 
pidpath0 = DEFAULT_NPPPD_PIDFILE;
+   if (strlen(_this->conf.pid_file_path) > 0) {
+   pidpath0 = _this->conf.pid_file_path;
+   }
 
/* initialize event(3) */
event_init();
diff -r 5df6e3ec88c3 -r 12ffa641c5d9 usr.sbin/npppd/npppd/npppd.h
--- usr.sbin/npppd/npppd/npppd.hSun Jan 10 13:41:40 2016 +0100
+++ usr.sbin/npppd/npppd/npppd.hSun Jan 10 14:00:50 2016 +0100
@@ -193,6 +193,7 @@
 struct npppd_conf {
intmax_session;
intuser_max_session;
+   char   pid_file_path[PATH_MAX];
TAILQ_HEAD(tunnconfs, tunnconf)tunnconfs;
TAILQ_HEAD(authconfs, authconf)authconfs;
TAILQ_HEAD(ipcpconfs, ipcpconf)ipcpconfs;
diff -r 5df6e3ec88c3 -r 12ffa641c5d9 usr.sbin/npppd/npppd/parse.y
--- usr.sbin/npppd/npppd/parse.ySun Jan 10 13:41:40 2016 +0100
+++ usr.sbin/npppd/npppd/parse.ySun Jan 10 14:00:50 2016 +0100
@@ -102,7 +102,7 @@
 
 %}
 
-%token SET MAX_SESSION USER_MAX_SESSION
+%token SET MAX_SESSION USER_MAX_SESSION PID_FILE
 %token TUNNEL LISTEN ON PROTOCOL
 %token MRU
 %token IP LCP PAP CHAP EAP MPPE CCP MSCHAPV2 STATEFUL STATELESS REQUIRED
@@ -171,6 +171,10 @@
 
 set: SET MAX_SESSION NUMBER{ conf->max_session = $3; }
| SET USER_MAX_SESSION NUMBER   { conf->user_max_session = $3; }
+   | SET PID_FILE STRING   {
+   strlcpy(conf->pid_file_path, $3, 
sizeof(conf->pid_file_path));
+   free($3);
+   }
;
 
 /*
@@ -1047,6 +1051,7 @@
{ "no",   NO},
{ "on",   ON},
{ "pap",  PAP},
+   { "pid-file", PID_FILE},
{ "pipex",PIPEX},
{ "pool-address", POOL_ADDRESS},
{ "port", PORT},



# HG changeset patch
# User MJP
# Date 1452430858 -3600
#  Sun Jan 10 14:00:58 2016 +0100
# Node ID 6e76b1f3b116537de0e91ab176f7681cb9c9daed
# Parent  12ffa641c5d987c3e1373f8a9156f4951faa54ed
Add: In the configuration file, define the control socket to use (set 
control-socket).

diff -r 12ffa641c5d9 -r 6e76b1f3b116 usr.sbin/npppd/npppd/npppd.c
--- usr.sbin/npppd/npppd/npppd.cSun Jan 10 14:00:50 2016 +0100
+++ usr.sbin/npppd/npppd/npppd.cSun Jan 10 14:00:58 2016 +0100
@@ -317,6 +317,9 @@
/* initialize event(3) */
event_init();
_this->ctl_sock.cs_name = NPPPD_SOCKET;
+   if (strlen(_this->conf.control_socket_path) > 0) {
+   _this->ctl_sock.cs_name = _this->conf.control_socket_path;
+   }
_this->ctl_sock.cs_ctx = _this;
if (control_init(&_this->ctl_sock) == -1) {
log_printf(LOG_ERR, "control_init() failed %s(): %m",
diff -r 12ffa641c5d9 -r 6e76b1f3b116 usr.sbin/npppd/npppd/npppd.h
--- usr.sbin/npppd/npppd/npppd.hSun Jan 10 14:00:50 2016 +0100
+++ usr.sbin/npppd/npppd/npppd.hSun Jan 10 14:00:58 2016 +0100
@@ -194,6 +194,7 @@
intmax_session;
intuser_max_session;
char   pid_file_path[PATH_MAX];
+   char   control_socket_path[PATH_MAX];
TAILQ_HEAD(tunnconfs, tunnconf)tunnconfs;
TAILQ_HEAD(authconfs, authconf)authconfs;
TAILQ_HEAD(ipcpconfs, ipcpconf)ipcpconfs;
diff -r 12ffa641c5d9 -r 6e76b1f3b116 usr.sbin/npppd/npppd/parse.y
--- usr.sbin/npppd/npppd/parse.ySun Jan 10 14:00:50 2016 +0100
+++ usr.sbin/npppd/npppd/parse.ySun Jan 10 14:00:58 2016 +0100
@@ -102,7 +102,7 @@
 
 %}
 
-%token SET MAX_SESSION USER_MAX_SESSION PID_FILE
+%token SET MAX_SESSION USER_MAX_SESSION PID_FILE CONTROL_SOCKET
 %token TUNNEL LISTEN ON PROTOCOL
 %token MRU
 %token IP LCP PAP CHAP EAP MPPE CCP MSCHAPV2 STATEFUL STATELESS REQUIRED
@@ -175,6 +175,10 @@
strlcpy(conf->pid_file_path, $3, 
sizeof(conf->pid_file_path));
free($3);
}
+   | SET CONTROL_SOCKET STRING  {
+   

Patches for improving npppd with rdomain support

2016-03-01 Thread Claer
Hello dear developers,

I asked a friend, Mathieu Papineau, to help me with an issue I have with npppd.
For a project here, I thought building multitenancy firewall with rdomain
support. For remote access, I wanted to use npppd to be able to authenticate
users in different domains in their respective domains using RADIUS.

After some infructuous tests, it appears that npppd wasn't designed to support
rdomains. Mathieu developed the following patches to support the
functionnality I wished. Actually, due to the current limitation, it only
works with tun devices. The pppx driver does not support rdomain ioctls yet.

The serie contains 12 patches, I'll try to post one per mail for easier review.

Thanks for review!

Claer



Re: Kill db_lookup()

2016-03-01 Thread Martin Pieuchot
On 01/03/16(Tue) 15:10, Mike Belopuhov wrote:
> On 1 March 2016 at 12:59, Martin Pieuchot  wrote:
> > No need for an empty wrapper.  ok?
> >
> 
> I'm certainly fine with calling db_elf_sym_lookup directly from the
> db_value_of_name, but i'm not sure about moving db_value_of_name into
> db_elf.c as it makes it sort of stand out by not having consistent
> naming with the other functions in the db_elf.c.  And besides, it's a
> more generic function (judging by code and usage), not an ELF
> implementation detail. Hard to say if it's a benefit w/o knowing your
> plans for this.  So maybe keep it for now and have it moved/removed
> along with some other changes?  Just my two cents, really.

Since we only support ELF I plan to get rid of the abstraction layer
completely and kill db_sym.c.  More functions will shrink, be merged
or disappear.



sched_bsd.c update comment

2016-03-01 Thread Michal Mazurek

Index: sys/kern/sched_bsd.c
===
RCS file: /cvs/src/sys/kern/sched_bsd.c,v
retrieving revision 1.42
diff -u -p -r1.42 sched_bsd.c
--- sys/kern/sched_bsd.c8 Nov 2015 20:45:57 -   1.42
+++ sys/kern/sched_bsd.c1 Mar 2016 15:19:24 -
@@ -70,8 +70,8 @@ scheduler_start(void)
/*
 * We avoid polluting the global namespace by keeping the scheduler
 * timeouts static in this function.
-* We setup the timeouts here and kick schedcpu and roundrobin once to
-* make them do their job.
+* We setup the timeouts here and kick schedcpu once to make it do
+* its job.
 */
 
timeout_set(_to, schedcpu, _to);

-- 
Michal Mazurek



fortune(6): replace hand-rolled strtonum

2016-03-01 Thread Theo Buehler
The option parsing code of fortune(6) contains a hand-rolled strtonum.
There are several problems with it: fortune won't accept any files
whose name starts with a number larger than 100 and the string
conversion is susceptible to overflow, which leads to bizarre errors:

$ fortune 101dalmatians
percentages must be <= 100
$ fortune 4294967280% all
fortune: no place to put residual probability (-16%)

The patch below fixes both these issues and makes some further minor
simplifications. Now the only impossible names for a fortune file are
the ones matching the regex [0-9][0-9.]*%

Index: fortune.c
===
RCS file: /var/cvs/src/games/fortune/fortune/fortune.c,v
retrieving revision 1.51
diff -u -p -r1.51 fortune.c
--- fortune.c   10 Jan 2016 13:35:09 -  1.51
+++ fortune.c   1 Mar 2016 14:19:22 -
@@ -38,6 +38,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -330,37 +331,34 @@ form_file_list(char **files, int file_cn
}
for (i = 0; i < file_cnt; i++) {
percent = NO_PROB;
-   if (!isdigit((unsigned char)files[i][0]))
-   sp = files[i];
-   else {
-   percent = 0;
-   for (sp = files[i]; isdigit((unsigned char)*sp); sp++)
-   percent = percent * 10 + *sp - '0';
-   if (percent > 100) {
-   fprintf(stderr, "percentages must be <= 100\n");
-   return 0;
-   }
-   if (*sp == '.') {
-   fprintf(stderr, "percentages must be 
integers\n");
-   return 0;
-   }
+
+   if (isdigit((unsigned char)files[i][0])) {
+   int pos = strspn(files[i], "0123456789.");
+
/*
-* If the number isn't followed by a '%', then
-* it was not a percentage, just the first part
-* of a file name which starts with digits.
+* Only try to interpret files[i] as a percentage if
+* it ends in '%'. Otherwise assume it's a file name.
 */
-   if (*sp != '%') {
-   percent = NO_PROB;
-   sp = files[i];
-   }
-   else if (*++sp == '\0') {
-   if (++i >= file_cnt) {
-   fprintf(stderr, "percentages must 
precede files\n");
-   return 0;
-   }
-   sp = files[i];
+   if (files[i][pos] == '%' && files[i][pos+1] == '\0') {
+   const char *errstr;
+   char *prefix;
+
+   if ((prefix = strndup(files[i], pos)) == NULL)
+   err(1, NULL);
+   if (strchr(prefix, '.') != NULL)
+   errx(1, "percentages must be integers");
+   percent = strtonum(prefix, 0, 100, );
+   if (errstr != NULL)
+   errx(1, "percentage is %s: %s", errstr,
+   prefix);
+   free(prefix);
+
+   if (++i >= file_cnt)
+   errx(1,
+   "percentages must precede files");
}
}
+   sp = files[i];
if (strcmp(sp, "all") == 0)
sp = FORTDIR;
if (!add_file(percent, sp, NULL, _list, _tail, NULL))



Re: db_sym_numargs() is always false

2016-03-01 Thread Mike Belopuhov
On 1 March 2016 at 13:04, Martin Pieuchot  wrote:
> I'd like to remove this dead code because I'd like to unify to some
> extend the frame walking code between archs and this doesn't help.
>
> ok?
>

OK mikeb



Re: Kill db_lookup()

2016-03-01 Thread Mike Belopuhov
On 1 March 2016 at 12:59, Martin Pieuchot  wrote:
> No need for an empty wrapper.  ok?
>

I'm certainly fine with calling db_elf_sym_lookup directly from the
db_value_of_name, but i'm not sure about moving db_value_of_name into
db_elf.c as it makes it sort of stand out by not having consistent
naming with the other functions in the db_elf.c.  And besides, it's a
more generic function (judging by code and usage), not an ELF
implementation detail. Hard to say if it's a benefit w/o knowing your
plans for this.  So maybe keep it for now and have it moved/removed
along with some other changes?  Just my two cents, really.



Re: Kill db_find_trace_symbols()

2016-03-01 Thread Mike Belopuhov
On 1 March 2016 at 13:06, Martin Pieuchot  wrote:
> This is also dead code. ok?
>

Sure, OK mikeb



Re: df(1): tidy function declarations and definitions

2016-03-01 Thread Michal Mazurek
On 13:00:53,  1.03.16, Theo Buehler wrote:
> > +int bread(int, off_t, void *, int);
>   ^
> space before tab here, otherwise ok tb@

Oups

Index: bin/df/df.c
===
RCS file: /cvs/src/bin/df/df.c,v
retrieving revision 1.55
diff -u -p -r1.55 df.c
--- bin/df/df.c 8 Feb 2016 16:23:54 -   1.55
+++ bin/df/df.c 1 Mar 2016 12:22:31 -
@@ -49,21 +49,21 @@
 
 extern char *__progname;
 
-char   *getmntpt(char *);
-int selected(const char *);
-voidmaketypelist(char *);
-longregetmntinfo(struct statfs **, long);
-voidbsdprint(struct statfs *, long, int);
-voidprtstat(struct statfs *, int, int, int);
-voidposixprint(struct statfs *, long, int);
-int bread(int, off_t, void *, int);
-voidusage(void);
-voidprthumanval(long long);
-voidprthuman(struct statfs *sfsp, unsigned long long);
-
-intraw_df(char *, struct statfs *);
-extern int ffs_df(int, char *, struct statfs *);
-extern int e2fs_df(int, char *, struct statfs *);
+int bread(int, off_t, void *, int);
+static void bsdprint(struct statfs *, long, int);
+char   *getmntpt(char *);
+static void maketypelist(char *);
+static void posixprint(struct statfs *, long, int);
+static void prthuman(struct statfs *sfsp, unsigned long long);
+static void prthumanval(long long);
+static void prtstat(struct statfs *, int, int, int);
+static long regetmntinfo(struct statfs **, long);
+static int  selected(const char *);
+static __dead void usage(void);
+
+extern int  e2fs_df(int, char *, struct statfs *);
+extern int  ffs_df(int, char *, struct statfs *);
+static int  raw_df(char *, struct statfs *);
 
 inthflag, iflag, kflag, lflag, nflag, Pflag;
 char   **typelist = NULL;
@@ -196,7 +196,7 @@ getmntpt(char *name)
 
 static enum { IN_LIST, NOT_IN_LIST } which;
 
-int
+static int
 selected(const char *type)
 {
char **av;
@@ -210,7 +210,7 @@ selected(const char *type)
return (which == IN_LIST ? 0 : 1);
 }
 
-void
+static void
 maketypelist(char *fslist)
 {
int i;
@@ -251,7 +251,7 @@ maketypelist(char *fslist)
  * filesystem types not in ``fsmask'' and possibly re-stating to get
  * current (not cached) info.  Returns the new count of valid statfs bufs.
  */
-long
+static long
 regetmntinfo(struct statfs **mntbufp, long mntsize)
 {
int i, j;
@@ -281,7 +281,7 @@ regetmntinfo(struct statfs **mntbufp, lo
  * the end.  Makes output compact and easy-to-read esp. on huge disks.
  * Code moved into libutil; this is now just a wrapper.
  */
-void
+static void
 prthumanval(long long bytes)
 {
char ret[FMT_SCALED_STRSIZE];
@@ -293,7 +293,7 @@ prthumanval(long long bytes)
(void)printf(" %7s", ret);
 }
 
-void
+static void
 prthuman(struct statfs *sfsp, unsigned long long used)
 {
prthumanval(sfsp->f_blocks * sfsp->f_bsize);
@@ -312,7 +312,7 @@ prthuman(struct statfs *sfsp, unsigned l
 /*
  * Print out status about a filesystem.
  */
-void
+static void
 prtstat(struct statfs *sfsp, int maxwidth, int headerlen, int blocksize)
 {
u_int64_t used, inodes;
@@ -343,7 +343,7 @@ prtstat(struct statfs *sfsp, int maxwidt
 /*
  * Print in traditional BSD format.
  */
-void
+static void
 bsdprint(struct statfs *mntbuf, long mntsize, int maxwidth)
 {
int i;
@@ -380,7 +380,7 @@ bsdprint(struct statfs *mntbuf, long mnt
 /*
  * Print in format defined by POSIX 1002.2, invoke with -P option.
  */
-void
+static void
 posixprint(struct statfs *mntbuf, long mntsize, int maxwidth)
 {
int i;
@@ -421,7 +421,7 @@ posixprint(struct statfs *mntbuf, long m
}
 }
 
-int
+static int
 raw_df(char *file, struct statfs *sfsp)
 {
int rfd, ret = -1;
@@ -456,7 +456,7 @@ bread(int rfd, off_t off, void *buf, int
return (1);
 }
 
-void
+static __dead void
 usage(void)
 {
(void)fprintf(stderr,

-- 
Michal Mazurek



Re: df(1): return from main() and simplify maxwidth

2016-03-01 Thread Theo Buehler
I agree that this is nicer.  ok tb@

On Tue, Mar 01, 2016 at 12:42:24PM +0100, Michal Mazurek wrote:
> Index: bin/df/df.c
> ===
> RCS file: /cvs/src/bin/df/df.c,v
> retrieving revision 1.55
> diff -u -p -r1.55 df.c
> --- bin/df/df.c   8 Feb 2016 16:23:54 -   1.55
> +++ bin/df/df.c   1 Mar 2016 11:40:40 -
> @@ -161,23 +161,20 @@ main(int argc, char *argv[])
>   }
>  
>   if (mntsize) {
> - maxwidth = 0;
> + maxwidth = 11;
>   for (i = 0; i < mntsize; i++) {
>   width = strlen(mntbuf[i].f_mntfromname);
>   if (width > maxwidth)
>   maxwidth = width;
>   }
>  
> - if (maxwidth < 11)
> - maxwidth = 11;
> -
>   if (Pflag)
>   posixprint(mntbuf, mntsize, maxwidth);
>   else
>   bsdprint(mntbuf, mntsize, maxwidth);
>   }
>  
> - exit(mntsize ? 0 : 1);
> + return (mntsize ? 0 : 1);
>  }
>  
>  char *
> 
> -- 
> Michal Mazurek
> 



Kill db_find_trace_symbols()

2016-03-01 Thread Martin Pieuchot
This is also dead code. ok?

diff --git sys/arch/amd64/amd64/db_trace.c sys/arch/amd64/amd64/db_trace.c
index 27fe24d..f0af6ec 100644
--- sys/arch/amd64/amd64/db_trace.c
+++ sys/arch/amd64/amd64/db_trace.c
@@ -106,30 +106,10 @@ db_x86_64_regop(struct db_variable *vp, db_expr_t *val, 
int opcode)
 #defineINTERRUPT   3
 #defineAST 4
 
-db_addr_t  db_trap_symbol_value = 0;
-db_addr_t  db_syscall_symbol_value = 0;
-db_addr_t  db_kdintr_symbol_value = 0;
-boolean_t  db_trace_symbols_found = FALSE;
-
-void db_find_trace_symbols(void);
 int db_numargs(struct callframe *);
 void db_nextframe(struct callframe **, db_addr_t *, long *, int,
 int (*) (const char *, ...));
 
-void
-db_find_trace_symbols(void)
-{
-   db_expr_t   value;
-
-   if (db_value_of_name("_trap", ))
-   db_trap_symbol_value = (db_addr_t) value;
-   if (db_value_of_name("_kdintr", ))
-   db_kdintr_symbol_value = (db_addr_t) value;
-   if (db_value_of_name("_syscall", ))
-   db_syscall_symbol_value = (db_addr_t) value;
-   db_trace_symbols_found = TRUE;
-}
-
 /*
  * Figure out how many arguments were passed into the frame at "fp".
  * We can probably figure out how many arguments where passed above
@@ -202,11 +182,6 @@ db_stack_trace_print(db_expr_t addr, boolean_t have_addr, 
db_expr_t count,
boolean_t   kernel_only = TRUE;
boolean_t   trace_proc = FALSE;
 
-#if 0
-   if (!db_trace_symbols_found)
-   db_find_trace_symbols();
-#endif
-
{
char *cp = modif;
char c;
diff --git sys/arch/i386/i386/db_trace.c sys/arch/i386/i386/db_trace.c
index e867dc2..0280fa9 100644
--- sys/arch/i386/i386/db_trace.c
+++ sys/arch/i386/i386/db_trace.c
@@ -74,30 +74,10 @@ struct db_variable *db_eregs = db_regs + nitems(db_regs);
 #defineINTERRUPT   3
 #defineAST 4
 
-db_addr_t  db_trap_symbol_value = 0;
-db_addr_t  db_syscall_symbol_value = 0;
-db_addr_t  db_kdintr_symbol_value = 0;
-boolean_t  db_trace_symbols_found = FALSE;
-
-void db_find_trace_symbols(void);
 int db_numargs(struct callframe *);
 void db_nextframe(struct callframe **, db_addr_t *, int *, int,
 int (*pr)(const char *, ...));
 
-void
-db_find_trace_symbols(void)
-{
-   db_expr_t   value;
-
-   if (db_value_of_name("trap", ))
-   db_trap_symbol_value = (db_addr_t) value;
-   if (db_value_of_name("kdintr", ))
-   db_kdintr_symbol_value = (db_addr_t) value;
-   if (db_value_of_name("syscall", ))
-   db_syscall_symbol_value = (db_addr_t) value;
-   db_trace_symbols_found = TRUE;
-}
-
 /*
  * Figure out how many arguments were passed into the frame at "fp".
  */
@@ -185,11 +165,6 @@ db_stack_trace_print(db_expr_t addr, boolean_t have_addr, 
db_expr_t count,
boolean_t   trace_thread = FALSE;
boolean_t   trace_proc = FALSE;
 
-#if 0
-   if (!db_trace_symbols_found)
-   db_find_trace_symbols();
-#endif
-
{
char *cp = modif;
char c;



db_sym_numargs() is always false

2016-03-01 Thread Martin Pieuchot
I'd like to remove this dead code because I'd like to unify to some
extend the frame walking code between archs and this doesn't help.

ok?

diff --git sys/arch/amd64/amd64/db_trace.c sys/arch/amd64/amd64/db_trace.c
index 7c86efe..27fe24d 100644
--- sys/arch/amd64/amd64/db_trace.c
+++ sys/arch/amd64/amd64/db_trace.c
@@ -244,8 +244,6 @@ db_stack_trace_print(db_expr_t addr, boolean_t have_addr, 
db_expr_t count,
char *  name;
db_expr_t   offset;
db_sym_tsym;
-#define MAXNARG16
-   char*argnames[MAXNARG], **argnp = NULL;
 
sym = db_search_symbol(callpc, DB_STGY_ANY, );
db_symbol_values(sym, , NULL);
@@ -284,11 +282,7 @@ db_stack_trace_print(db_expr_t addr, boolean_t have_addr, 
db_expr_t count,
} else {
normal:
is_trap = NONE;
-   narg = MAXNARG;
-   if (db_sym_numargs(sym, , argnames))
-   argnp = argnames;
-   else
-   narg = db_numargs(frame);
+   narg = db_numargs(frame);
}
 
(*pr)("%s(", name);
@@ -304,8 +298,6 @@ db_stack_trace_print(db_expr_t addr, boolean_t have_addr, 
db_expr_t count,
}
 
while (narg) {
-   if (argnp)
-   (*pr)("%s=", *argnp++);
(*pr)("%lx", db_get_value((db_addr_t)argp, 8, FALSE));
argp++;
if (--narg != 0)
diff --git sys/arch/hppa/hppa/db_interface.c sys/arch/hppa/hppa/db_interface.c
index 8270fe6..17aff81 100644
--- sys/arch/hppa/hppa/db_interface.c
+++ sys/arch/hppa/hppa/db_interface.c
@@ -244,7 +244,6 @@ db_stack_trace_print(addr, have_addr, count, modif, pr)
db_sym_t sym;
db_expr_t off;
char *name;
-   char **argnp, *argnames[HPPA_FRAME_NARGS];
int nargs;
 
if (count < 0)
@@ -274,19 +273,12 @@ db_stack_trace_print(addr, have_addr, count, modif, pr)
(*pr)("%s(", name);
 
/* args */
-   nargs = HPPA_FRAME_NARGS;
-   argnp = NULL;
-   if (db_sym_numargs(sym, , argnames))
-   argnp = argnames;
-   else
-   nargs = 4;
+   nargs = 4;
/*
 * XXX first four args are passed on registers, and may not
 * be stored on stack, dunno how to recover their values yet
 */
for (argp = [-9]; nargs--; argp--) {
-   if (argnp)
-   (*pr)("%s=", *argnp++);
(*pr)("%x%s", db_get_value((int)argp, 4, FALSE),
  nargs? ",":"");
}
diff --git sys/arch/hppa64/hppa64/db_interface.c 
sys/arch/hppa64/hppa64/db_interface.c
index e5be765..c7d2636 100644
--- sys/arch/hppa64/hppa64/db_interface.c
+++ sys/arch/hppa64/hppa64/db_interface.c
@@ -213,7 +213,6 @@ db_stack_trace_print(db_expr_t addr, int have_addr, 
db_expr_t count,
db_sym_t sym;
db_expr_t off;
char *name;
-   char **argnp, *argnames[8];
int nargs;
 
if (count < 0)
@@ -244,18 +243,11 @@ db_stack_trace_print(db_expr_t addr, int have_addr, 
db_expr_t count,
 
/* args */
nargs = 8;
-   argnp = NULL;
-   if (db_sym_numargs(sym, , argnames))
-   argnp = argnames;
-   else
-   nargs = 4;
/*
 * XXX first eight args are passed on registers, and may not
 * be stored on stack, dunno how to recover their values yet
 */
for (argp = [-9]; nargs--; argp--) {
-   if (argnp)
-   (*pr)("%s=", *argnp++);
(*pr)("%x%s", db_get_value((long)argp, 8, FALSE),
  nargs? ",":"");
}
diff --git sys/arch/i386/i386/db_trace.c sys/arch/i386/i386/db_trace.c
index 72d968a..e867dc2 100644
--- sys/arch/i386/i386/db_trace.c
+++ sys/arch/i386/i386/db_trace.c
@@ -233,8 +233,6 @@ db_stack_trace_print(db_expr_t addr, boolean_t have_addr, 
db_expr_t count,
char *  name;
db_expr_t   offset;
db_sym_tsym;
-#define MAXNARG16
-   char*argnames[MAXNARG], **argnp = NULL;
 
sym = db_search_symbol(callpc, DB_STGY_ANY, );
db_symbol_values(sym, , NULL);
@@ -272,11 +270,7 @@ db_stack_trace_print(db_expr_t addr, boolean_t have_addr, 
db_expr_t count,
} else {
normal:
is_trap = NONE;
-   narg = MAXNARG;
-   

Re: df(1): remove unneeded includes

2016-03-01 Thread Theo Buehler
On Tue, Mar 01, 2016 at 12:37:17PM +0100, Theo Buehler wrote:
> Wasn't this the part of your previous header cleanup that mmcc decided
> not to commit for some reason? 

if mmcc no longer objects, this once more ok tb@



Re: df(1): tidy function declarations and definitions

2016-03-01 Thread Theo Buehler
> +int   bread(int, off_t, void *, int);
  ^
space before tab here, otherwise ok tb@



Kill db_lookup()

2016-03-01 Thread Martin Pieuchot
No need for an empty wrapper.  ok?

Index: ddb/db_elf.c
===
RCS file: /cvs/src/sys/ddb/db_elf.c,v
retrieving revision 1.18
diff -u -p -r1.18 db_elf.c
--- ddb/db_elf.c1 Mar 2016 11:56:00 -   1.18
+++ ddb/db_elf.c1 Mar 2016 11:57:05 -
@@ -55,8 +55,9 @@ typedef struct {
 
 db_symtab_t db_symtab;
 
-static char *db_elf_find_strtab(db_symtab_t *);
-static char *db_elf_find_linetab(db_symtab_t *, size_t *);
+Elf_Sym*db_elf_sym_lookup(char *);
+static char*db_elf_find_strtab(db_symtab_t *);
+static char*db_elf_find_linetab(db_symtab_t *, size_t *);
 
 #defineSTAB_TO_SYMSTART(stab)  ((Elf_Sym *)((stab)->start))
 #defineSTAB_TO_SYMEND(stab)((Elf_Sym *)((stab)->end))
@@ -247,7 +248,7 @@ db_elf_find_linetab(db_symtab_t *stab, s
 /*
  * Lookup the symbol with the given name.
  */
-db_sym_t
+Elf_Sym *
 db_elf_sym_lookup(char *symstr)
 {
db_symtab_t *stab = _symtab;
@@ -267,7 +268,7 @@ db_elf_sym_lookup(char *symstr)
for (symp = symtab_start; symp < symtab_end; symp++) {
if (symp->st_name != 0 &&
db_eqname(strtab + symp->st_name, symstr, 0))
-   return ((db_sym_t)symp);
+   return (symp);
}
 
return (NULL);
@@ -439,4 +440,16 @@ db_elf_sym_forall(db_forall_func_t db_fo
(*db_forall_func)((db_sym_t)symp,
strtab + symp->st_name, suffix, 0, arg);
}
+}
+
+int
+db_value_of_name(char *name, db_expr_t *valuep)
+{
+   Elf_Sym *sym;
+
+   sym = db_elf_sym_lookup(name);
+   if (sym == NULL)
+   return (0);
+   db_symbol_values((db_sym_t)sym, , valuep);
+   return (1);
 }
Index: ddb/db_sym.c
===
RCS file: /cvs/src/sys/ddb/db_sym.c,v
retrieving revision 1.48
diff -u -p -r1.48 db_sym.c
--- ddb/db_sym.c1 Mar 2016 11:56:00 -   1.48
+++ ddb/db_sym.c1 Mar 2016 11:57:05 -
@@ -91,28 +91,6 @@ db_eqname(char *src, char *dst, int c)
return (FALSE);
 }
 
-boolean_t
-db_value_of_name(char *name, db_expr_t *valuep)
-{
-   db_sym_tsym;
-
-   sym = db_lookup(name);
-   if (sym == NULL)
-   return (FALSE);
-   db_symbol_values(sym, , valuep);
-   return (TRUE);
-}
-
-
-/*
- * Lookup a symbol.
- */
-db_sym_t
-db_lookup(char *symstr)
-{
-   return db_elf_sym_lookup(symstr);
-}
-
 /*
  * Find the closest symbol to val, and return its name
  * and the difference between val and the symbol found.
Index: ddb/db_sym.h
===
RCS file: /cvs/src/sys/ddb/db_sym.h,v
retrieving revision 1.23
diff -u -p -r1.23 db_sym.h
--- ddb/db_sym.h1 Mar 2016 11:56:00 -   1.23
+++ ddb/db_sym.h1 Mar 2016 11:57:05 -
@@ -69,8 +69,6 @@ boolean_t db_eqname(char *, char *, int)
 int db_value_of_name(char *, db_expr_t *);
/* find symbol value given name */
 
-db_sym_t db_lookup(char *);
-
 db_sym_t db_search_symbol(db_addr_t, db_strategy_t, db_expr_t *);
/* find symbol given value */
 
@@ -91,7 +89,6 @@ void db_printsym(db_expr_t, db_strategy_
 #define db_sym_numargs(sym, nargp, argnames) (FALSE)
 
 boolean_t db_elf_sym_init(int, void *, void *, const char *);
-db_sym_t db_elf_sym_lookup(char *);
 void db_elf_sym_values(db_sym_t, char **, db_expr_t *);
 db_sym_t db_elf_sym_search(db_addr_t, db_strategy_t, db_expr_t *);
 boolean_t db_elf_line_at_pc(db_sym_t, char **, int *, db_expr_t);



df(1): tidy function declarations and definitions

2016-03-01 Thread Michal Mazurek
Index: bin/df/df.c
===
RCS file: /cvs/src/bin/df/df.c,v
retrieving revision 1.55
diff -u -p -r1.55 df.c
--- bin/df/df.c 8 Feb 2016 16:23:54 -   1.55
+++ bin/df/df.c 1 Mar 2016 11:33:08 -
@@ -49,21 +49,21 @@
 
 extern char *__progname;
 
-char   *getmntpt(char *);
-int selected(const char *);
-voidmaketypelist(char *);
-longregetmntinfo(struct statfs **, long);
-voidbsdprint(struct statfs *, long, int);
-voidprtstat(struct statfs *, int, int, int);
-voidposixprint(struct statfs *, long, int);
-int bread(int, off_t, void *, int);
-voidusage(void);
-voidprthumanval(long long);
-voidprthuman(struct statfs *sfsp, unsigned long long);
-
-intraw_df(char *, struct statfs *);
-extern int ffs_df(int, char *, struct statfs *);
-extern int e2fs_df(int, char *, struct statfs *);
+int bread(int, off_t, void *, int);
+static void bsdprint(struct statfs *, long, int);
+char   *getmntpt(char *);
+static void maketypelist(char *);
+static void posixprint(struct statfs *, long, int);
+static void prthuman(struct statfs *sfsp, unsigned long long);
+static void prthumanval(long long);
+static void prtstat(struct statfs *, int, int, int);
+static long regetmntinfo(struct statfs **, long);
+static int  selected(const char *);
+static __dead void usage(void);
+
+extern int  e2fs_df(int, char *, struct statfs *);
+extern int  ffs_df(int, char *, struct statfs *);
+static int  raw_df(char *, struct statfs *);
 
 inthflag, iflag, kflag, lflag, nflag, Pflag;
 char   **typelist = NULL;
@@ -196,7 +196,7 @@ getmntpt(char *name)
 
 static enum { IN_LIST, NOT_IN_LIST } which;
 
-int
+static int
 selected(const char *type)
 {
char **av;
@@ -210,7 +210,7 @@ selected(const char *type)
return (which == IN_LIST ? 0 : 1);
 }
 
-void
+static void
 maketypelist(char *fslist)
 {
int i;
@@ -251,7 +251,7 @@ maketypelist(char *fslist)
  * filesystem types not in ``fsmask'' and possibly re-stating to get
  * current (not cached) info.  Returns the new count of valid statfs bufs.
  */
-long
+static long
 regetmntinfo(struct statfs **mntbufp, long mntsize)
 {
int i, j;
@@ -281,7 +281,7 @@ regetmntinfo(struct statfs **mntbufp, lo
  * the end.  Makes output compact and easy-to-read esp. on huge disks.
  * Code moved into libutil; this is now just a wrapper.
  */
-void
+static void
 prthumanval(long long bytes)
 {
char ret[FMT_SCALED_STRSIZE];
@@ -293,7 +293,7 @@ prthumanval(long long bytes)
(void)printf(" %7s", ret);
 }
 
-void
+static void
 prthuman(struct statfs *sfsp, unsigned long long used)
 {
prthumanval(sfsp->f_blocks * sfsp->f_bsize);
@@ -312,7 +312,7 @@ prthuman(struct statfs *sfsp, unsigned l
 /*
  * Print out status about a filesystem.
  */
-void
+static void
 prtstat(struct statfs *sfsp, int maxwidth, int headerlen, int blocksize)
 {
u_int64_t used, inodes;
@@ -343,7 +343,7 @@ prtstat(struct statfs *sfsp, int maxwidt
 /*
  * Print in traditional BSD format.
  */
-void
+static void
 bsdprint(struct statfs *mntbuf, long mntsize, int maxwidth)
 {
int i;
@@ -380,7 +380,7 @@ bsdprint(struct statfs *mntbuf, long mnt
 /*
  * Print in format defined by POSIX 1002.2, invoke with -P option.
  */
-void
+static void
 posixprint(struct statfs *mntbuf, long mntsize, int maxwidth)
 {
int i;
@@ -421,7 +421,7 @@ posixprint(struct statfs *mntbuf, long m
}
 }
 
-int
+static int
 raw_df(char *file, struct statfs *sfsp)
 {
int rfd, ret = -1;
@@ -456,7 +456,7 @@ bread(int rfd, off_t off, void *buf, int
return (1);
 }
 
-void
+static __dead void
 usage(void)
 {
(void)fprintf(stderr,

-- 
Michal Mazurek



df(1): replace __progname with getprogname()

2016-03-01 Thread Michal Mazurek
Index: bin/df/df.c
===
RCS file: /cvs/src/bin/df/df.c,v
retrieving revision 1.55
diff -u -p -r1.55 df.c
--- bin/df/df.c 8 Feb 2016 16:23:54 -   1.55
+++ bin/df/df.c 1 Mar 2016 11:36:54 -
@@ -47,8 +47,6 @@
 #include 
 #include 
 
-extern char *__progname;
-
 char   *getmntpt(char *);
 int selected(const char *);
 voidmaketypelist(char *);
@@ -461,6 +459,6 @@ usage(void)
 {
(void)fprintf(stderr,
"usage: %s [-hiklnP] [-t type] [[file | file_system] ...]\n",
-   __progname);
+   getprogname());
exit(1);
 }

-- 
Michal Mazurek



df(1): return from main() and simplify maxwidth

2016-03-01 Thread Michal Mazurek
Index: bin/df/df.c
===
RCS file: /cvs/src/bin/df/df.c,v
retrieving revision 1.55
diff -u -p -r1.55 df.c
--- bin/df/df.c 8 Feb 2016 16:23:54 -   1.55
+++ bin/df/df.c 1 Mar 2016 11:40:40 -
@@ -161,23 +161,20 @@ main(int argc, char *argv[])
}
 
if (mntsize) {
-   maxwidth = 0;
+   maxwidth = 11;
for (i = 0; i < mntsize; i++) {
width = strlen(mntbuf[i].f_mntfromname);
if (width > maxwidth)
maxwidth = width;
}
 
-   if (maxwidth < 11)
-   maxwidth = 11;
-
if (Pflag)
posixprint(mntbuf, mntsize, maxwidth);
else
bsdprint(mntbuf, mntsize, maxwidth);
}
 
-   exit(mntsize ? 0 : 1);
+   return (mntsize ? 0 : 1);
 }
 
 char *

-- 
Michal Mazurek



Re: df(1): remove unneeded includes

2016-03-01 Thread Theo Buehler
Wasn't this the part of your previous header cleanup that mmcc decided
not to commit for some reason? 

On Tue, Mar 01, 2016 at 12:27:36PM +0100, Michal Mazurek wrote:
> 
> Index: bin/df/ext2fs_df.c
> ===
> RCS file: /cvs/src/bin/df/ext2fs_df.c,v
> retrieving revision 1.15
> diff -u -p -r1.15 ext2fs_df.c
> --- bin/df/ext2fs_df.c8 Feb 2016 16:23:54 -   1.15
> +++ bin/df/ext2fs_df.c1 Mar 2016 11:26:06 -
> @@ -42,8 +42,6 @@
>  #include 
>  #include 
>  #include 
> -#include 
> -#include 
>  #include 
>  
>  int  e2fs_df(int, char *, struct statfs *);
> Index: bin/df/ffs_df.c
> ===
> RCS file: /cvs/src/bin/df/ffs_df.c,v
> retrieving revision 1.18
> diff -u -p -r1.18 ffs_df.c
> --- bin/df/ffs_df.c   8 Feb 2016 16:23:54 -   1.18
> +++ bin/df/ffs_df.c   1 Mar 2016 11:26:06 -
> @@ -39,8 +39,6 @@
>  #include 
>  #include 
>  
> -#include 
> -#include 
>  #include 
>  
>  int  ffs_df(int, char *, struct statfs *);
> 
> -- 
> Michal Mazurek
> 



df(1): remove unneeded includes

2016-03-01 Thread Michal Mazurek

Index: bin/df/ext2fs_df.c
===
RCS file: /cvs/src/bin/df/ext2fs_df.c,v
retrieving revision 1.15
diff -u -p -r1.15 ext2fs_df.c
--- bin/df/ext2fs_df.c  8 Feb 2016 16:23:54 -   1.15
+++ bin/df/ext2fs_df.c  1 Mar 2016 11:26:06 -
@@ -42,8 +42,6 @@
 #include 
 #include 
 #include 
-#include 
-#include 
 #include 
 
 inte2fs_df(int, char *, struct statfs *);
Index: bin/df/ffs_df.c
===
RCS file: /cvs/src/bin/df/ffs_df.c,v
retrieving revision 1.18
diff -u -p -r1.18 ffs_df.c
--- bin/df/ffs_df.c 8 Feb 2016 16:23:54 -   1.18
+++ bin/df/ffs_df.c 1 Mar 2016 11:26:06 -
@@ -39,8 +39,6 @@
 #include 
 #include 
 
-#include 
-#include 
 #include 
 
 intffs_df(int, char *, struct statfs *);

-- 
Michal Mazurek