Remove unused params from function on user(8)

2017-05-23 Thread Ricardo Mestre
Hi,

Remove 2 unused paramaters from copydotfiles function. While here sort headers
and add missing prototypes.

Index: user.c
===
RCS file: /cvs/src/usr.sbin/user/user.c,v
retrieving revision 1.119
diff -u -p -u -r1.119 user.c
--- user.c  12 May 2017 18:03:00 -  1.119
+++ user.c  24 May 2017 06:20:27 -
@@ -38,6 +38,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -48,7 +49,6 @@
 #include 
 #include 
 #include 
-#include 
 #include 
 
 #include "usermgmt.h"
@@ -177,8 +177,31 @@ enum {
 #define UNSET_INACTIVE "Null (unset)"
 #define UNSET_EXPIRY   "Null (unset)"
 
-static int asystem(const char *fmt, ...)
+static int adduser(char *, user_t *);
+static int append_group(char *, int, const char **);
+static int asystem(const char *, ...)
__attribute__((__format__(__printf__, 1, 2)));
+static int copydotfiles(char *, char *);
+static int creategid(char *, gid_t, const char *);
+static int getnextgid(uid_t *, uid_t, uid_t);
+static int getnextuid(int, uid_t *, uid_t, uid_t);
+static int is_local(char *, const char *);
+static int modify_gid(char *, char *);
+static int moduser(char *, char *, user_t *);
+static int removehomedir(const char *, uid_t, const char *);
+static int rm_user_from_groups(char *);
+static int save_range(user_t *, char *);
+static int scantime(time_t *, char *);
+static int setdefaults(user_t *);
+static int valid_class(char *);
+static int valid_group(char *);
+static int valid_login(char *);
+static size_t expand_len(const char *, const char *);
+static struct group *find_group_info(const char *);
+static struct passwd *find_user_info(const char *);
+static void checkeuid(void);
+static void memsave(char **, const char *, size_t);
+static void read_defaults(user_t *);
 
 static int verbose;
 
@@ -267,7 +290,7 @@ checkeuid(void)
 
 /* copy any dot files into the user's home directory */
 static int
-copydotfiles(char *skeldir, uid_t uid, gid_t gid, char *dir)
+copydotfiles(char *skeldir, char *dir)
 {
struct dirent   *dp;
DIR *dirp;
@@ -1157,7 +1180,7 @@ adduser(char *login_name, user_t *up)
errc(EXIT_FAILURE, saved_errno,
"can't mkdir `%s'", home);
}
-   (void) copydotfiles(up->u_skeldir, up->u_uid, gid, 
home);
+   (void) copydotfiles(up->u_skeldir, home);
(void) asystem("%s -R -P %u:%u %s", CHOWN, up->u_uid,
gid, home);
(void) asystem("%s -R u+w %s", CHMOD, home);



small diff for acme-client that clarifies why the domain is not found.

2017-05-23 Thread Han Boetes
I just added a new domain in my nameserver and then ran acme-client

% sudo acme-client -D niets.boetes.org
acme-client: domain niets.boetes.org not found

So I assumed the dns was not yet in DNS. I waited a bit, checked the
propagation of my new entry in DNS, double checked
everything. Debugged, everything checked out fine. Still the same
error. What was going on!? Ten minutes later I realised my error.

This patch explains the problem so nobody can misunderstand the cause
of the problem.

diff --git a/usr.sbin/acme-client/main.c b/usr.sbin/acme-client/main.c
index f8dc22c8756..bcc00c3bc35 100644
--- a/usr.sbin/acme-client/main.c
+++ b/usr.sbin/acme-client/main.c
@@ -98,7 +98,7 @@ main(int argc, char *argv[])
goto usage;
 
if ((domain = domain_find(conf, argv[0])) == NULL)
-   errx(EXIT_FAILURE, "domain %s not found", argv[0]);
+   errx(EXIT_FAILURE, "domain %s not found in %s", argv[0], 
conffile);
 
argc--;
argv++;


resulting in:

% sudo ./acme-client -D niets.boetes.org
acme-client: domain niets.boetes.org not found in /etc/acme-client.conf


Please add me in your CC when replying to this email since I'm not
subscribed to this list.



# Han



Re: athn: fix ar9380 receive code

2017-05-23 Thread Kevin Lo
On Thu, May 18, 2017 at 02:42:45PM +0800, Kevin Lo wrote:
> 
> On Thu, May 18, 2017 at 08:08:52AM +0200, Stefan Sperling wrote:
> > 
> > On Thu, May 18, 2017 at 01:19:18PM +0800, Kevin Lo wrote:
> > > On Thu, May 18, 2017 at 02:40:49AM +0200, Stefan Sperling wrote:
> > > > athn0 at pci1 dev 0 function 0 "Atheros AR9300" rev 0x01: apic 2 int 16
> > > > athn0: AR9380 rev 3 (3T3R), ROM rev 0, address xx:xx:xx:xx:xx:xx
> > 
> > > Can't receive packets with my AR9382 card.
> > 
> > That is interesting, but there is no reason to reject my diff, I think.
> 
> Right :)  I'll try to get the ar9380 card, thanks.

My AR9380 adapter arrived, but I hit a kernel panic on amd64:

booting hd0a:/bsd: 6232140+2110472+246816+0+671744 [72+625728+421114]=0x9d6c08
entry point at 0x1001000 [7205c766, 3404, 24448b12, e960a304]
[ using 1047560 bytes of bsd ELF symbol table ]
Copyright (c) 1982, 1986, 1989, 1991, 1993
The Regents of the University of California.  All rights reserved.
Copyright (c) 1995-2017 OpenBSD. All rights reserved.  https://www.OpenBSD.org

OpenBSD 6.1-current (GENERIC.MP) #0: Wed May 24 09:48:26 CST 2017
root@winlab.SSG5-Serial:/usr/src/sys/arch/amd64/compile/GENERIC.MP
real mem = 2016292864 (1922MB)
avail mem = 1951485952 (1861MB) 
mpath0 at root  
scsibus0 at mpath0: 256 targets 
mainbus0 at root
bios0 at mainbus0: SMBIOS rev. 2.8 @ 0xec9b0 (51 entries)   
bios0: vendor American Megatrends Inc. version "5.6.5" date 12/09/2014  
acpi0 at bios0: rev 2   
acpi0: sleep states S0 S3 S4 S5 
acpi0: tables DSDT FACP APIC FPDT FIDT LPIT MCFG HPET SSDT SSDT SSDT UEFI CSRT  
acpi0: wakeup devices XHC1(S4) PXSX(S4) PXSX(S4) PXSX(S4) PXSX(S4) PWRB(S0) 
acpitimer0 at acpi0: 3579545 Hz, 24 bits
acpimadt0 at acpi0 addr 0xfee0: PC-AT compat
cpu0 at mainbus0: apid 0 (boot processor)   
cpu0: Intel(R) Atom(TM) CPU E3845 @ 1.91GHz, 1917.06 MHz
cpu0: FPU,VME,DE,PSE,TSC,MSR,PAE,MCE,CX8,APIC,SEP,MTRR,PGE,MCA,CMOV,PAT,PSE36,CT
cpu0: 1MB 64b/line 16-way L2 cache  
cpu0: TSC frequency 1917057130 Hz   
cpu0: smt 0, core 0, package 0  
mtrr: Pentium Pro MTRR support, 8 var ranges, 88 fixed ranges   
cpu0: apic clock running at 83MHz   
cpu0: mwait min=64, max=64, C-substates=0.2.0.0.0.0.3, IBE  
cpu1 at mainbus0: apid 2 (application processor)
cpu1: Intel(R) Atom(TM) CPU E3845 @ 1.91GHz, 1916.67 MHz
cpu1: FPU,VME,DE,PSE,TSC,MSR,PAE,MCE,CX8,APIC,SEP,MTRR,PGE,MCA,CMOV,PAT,PSE36,CT
cpu1: 1MB 64b/line 16-way L2 cache  
cpu1: smt 0, core 1, package 0  
cpu2 at mainbus0: apid 4 (application processor)
cpu2: Intel(R) Atom(TM) CPU E3845 @ 1.91GHz, 1916.67 MHz
cpu2: FPU,VME,DE,PSE,TSC,MSR,PAE,MCE,CX8,APIC,SEP,MTRR,PGE,MCA,CMOV,PAT,PSE36,CT
cpu2: 1MB 64b/line 16-way L2 cache  
cpu2: smt 0, core 2, package 0  
cpu3 at mainbus0: apid 6 (application processor)
cpu3: Intel(R) Atom(TM) CPU E3845 @ 1.91GHz, 1916.67 MHz
cpu3: FPU,VME,DE,PSE,TSC,MSR,PAE,MCE,CX8,APIC,SEP,MTRR,PGE,MCA,CMOV,PAT,PSE36,CT
cpu3: 1MB 64b/line 16-way L2 cache  
cpu3: smt 0, core 3, package 0  
ioapic0 at mainbus0: apid 1 pa 0xfec0, version 20, 87 pins  
acpimcfg0 at acpi0 addr 0xe000, bus 0-255   
acpihpet0 at acpi0: 14318179 Hz 
acpiprt0 at acpi0: bus 0 (PCI0) 
acpiprt1 at acpi0: bus 1 (RP01) 
acpiprt2 at acpi0: bus 2 (RP02) 
acpiprt3 at acpi0: bus 3 (RP03) 
acpiprt4 at acpi0: bus 4 (RP04) 
acpiec0 at acpi0: not present   
acpicpu0 at acpi0: C3(10@1500 mwait.1@0x52), C2(10@500 mwait.1@0x51), C1(1000@1S
acpicpu1 at acpi0: C3(10@1500 mwait.1@0x

Remove unused function from compress(1)

2017-05-23 Thread Brian Callahan
Hi tech --

clang says zclose is an unused function. Seems to check out.

~Brian

Index: zopen.c
===
RCS file: /cvs/src/usr.bin/compress/zopen.c,v
retrieving revision 1.21
diff -u -p -u -p -r1.21 zopen.c
--- zopen.c 3 Sep 2016 11:41:10 -   1.21
+++ zopen.c 23 May 2017 03:31:05 -
@@ -343,12 +343,6 @@ z_close(void *cookie, struct z_info *inf
return (rval);
 }
 
-static int
-zclose(void *cookie)
-{
-   return z_close(cookie, NULL, NULL, NULL);
-}
-
 /*-
  * Output the given code.
  * Inputs:



Re: memory barriers and atomic instructions

2017-05-23 Thread Mark Kettenis
> Date: Tue, 23 May 2017 17:58:56 +0200
> From: Mike Belopuhov 
> 
> On Tue, May 23, 2017 at 17:41 +0200, Mark Kettenis wrote:
> > So here is a diff that implements what I proposed recently.  This
> > recognizes that atomic instructions on amd64 already include an
> > implicit memory barrier and allows us to write optimized code that
> > avoids a redundant memory barrier.
> > 
> > Note that I don't have a use-case for membar_exit_before_atomic() yet;
> > I merely added it for symmetry reasons.  I can leave it out if that's
> > what people prefer.
> > 
> > This should allow us to use a generic mutex implementation written in
> > C without a significant penalty.
> > 
> > ok?
> >
> 
> LGTM, but shouldn't the same thing be done to i386?

Yes.

> > Index: sys/atomic.h
> > ===
> > RCS file: /cvs/src/sys/sys/atomic.h,v
> > retrieving revision 1.4
> > diff -u -p -r1.4 atomic.h
> > --- sys/atomic.h24 Jan 2017 22:22:20 -  1.4
> > +++ sys/atomic.h23 May 2017 15:01:34 -
> > @@ -219,4 +219,12 @@ atomic_sub_long_nv(volatile unsigned lon
> >  #define membar_sync() __sync_synchronize()
> >  #endif
> >  
> > +#ifndef membar_enter_after_atomic
> > +#define membar_enter_after_atomic() membar_enter()
> > +#endif
> > +
> > +#ifndef membar_exit_before_atomic
> > +#define membar_exit_before_atomic() membar_exit()
> > +#endif
> > +
> >  #endif /* _SYS_ATOMIC_H_ */
> > Index: arch/amd64/include/atomic.h
> > ===
> > RCS file: /cvs/src/sys/arch/amd64/include/atomic.h,v
> > retrieving revision 1.19
> > diff -u -p -r1.19 atomic.h
> > --- arch/amd64/include/atomic.h 12 May 2017 08:47:03 -  1.19
> > +++ arch/amd64/include/atomic.h 23 May 2017 15:02:23 -
> > @@ -276,6 +276,9 @@ _atomic_sub_long_nv(volatile unsigned lo
> >  #define membar_sync()  __membar("")
> >  #endif
> >  
> > +#define membar_enter_after_atomic()__membar("")
> > +#define membar_exit_before_atomic()__membar("")
> > +
> >  #ifdef _KERNEL
> >  
> >  /* virtio needs MP membars even on SP kernels */
> > 
> 



Re: memory barriers and atomic instructions

2017-05-23 Thread Mike Belopuhov
On Tue, May 23, 2017 at 17:41 +0200, Mark Kettenis wrote:
> So here is a diff that implements what I proposed recently.  This
> recognizes that atomic instructions on amd64 already include an
> implicit memory barrier and allows us to write optimized code that
> avoids a redundant memory barrier.
> 
> Note that I don't have a use-case for membar_exit_before_atomic() yet;
> I merely added it for symmetry reasons.  I can leave it out if that's
> what people prefer.
> 
> This should allow us to use a generic mutex implementation written in
> C without a significant penalty.
> 
> ok?
>

LGTM, but shouldn't the same thing be done to i386?

> 
> 
> Index: sys/atomic.h
> ===
> RCS file: /cvs/src/sys/sys/atomic.h,v
> retrieving revision 1.4
> diff -u -p -r1.4 atomic.h
> --- sys/atomic.h  24 Jan 2017 22:22:20 -  1.4
> +++ sys/atomic.h  23 May 2017 15:01:34 -
> @@ -219,4 +219,12 @@ atomic_sub_long_nv(volatile unsigned lon
>  #define membar_sync() __sync_synchronize()
>  #endif
>  
> +#ifndef membar_enter_after_atomic
> +#define membar_enter_after_atomic() membar_enter()
> +#endif
> +
> +#ifndef membar_exit_before_atomic
> +#define membar_exit_before_atomic() membar_exit()
> +#endif
> +
>  #endif /* _SYS_ATOMIC_H_ */
> Index: arch/amd64/include/atomic.h
> ===
> RCS file: /cvs/src/sys/arch/amd64/include/atomic.h,v
> retrieving revision 1.19
> diff -u -p -r1.19 atomic.h
> --- arch/amd64/include/atomic.h   12 May 2017 08:47:03 -  1.19
> +++ arch/amd64/include/atomic.h   23 May 2017 15:02:23 -
> @@ -276,6 +276,9 @@ _atomic_sub_long_nv(volatile unsigned lo
>  #define membar_sync()__membar("")
>  #endif
>  
> +#define membar_enter_after_atomic()  __membar("")
> +#define membar_exit_before_atomic()  __membar("")
> +
>  #ifdef _KERNEL
>  
>  /* virtio needs MP membars even on SP kernels */
> 



Fix warnings and unifdef talk(1)

2017-05-23 Thread Brian Callahan
Hi tech --

Turned on WARNINGS=yes for talk(1). Found a few things. The nready
assignment is a false positive from gcc but I fixed it anyway.

Then I ran unifdef on talk(1). It unconditionally pulls in curses.h
from talk.h so there's no need to have those #ifdefs. Similar deal
with MSG_EOR, those files already pull in sys/socket.h so it's
always defined.

~Brian

Index: ctl_transact.c
===
RCS file: /cvs/src/usr.bin/talk/ctl_transact.c,v
retrieving revision 1.13
diff -u -p -u -p -r1.13 ctl_transact.c
--- ctl_transact.c  1 Feb 2016 07:29:25 -   1.13
+++ ctl_transact.c  23 May 2017 15:23:42 -
@@ -47,12 +47,12 @@
  * of time
  */
 void
-ctl_transact(struct in_addr target, CTL_MSG msg, int type, CTL_RESPONSE *rp)
+ctl_transact(struct in_addr target, CTL_MSG mesg, int type, CTL_RESPONSE *rp)
 {
struct pollfd pfd[1];
-   int nready, cc;
+   int nready = 0, cc;
 
-   msg.type = type;
+   mesg.type = type;
daemon_addr.sin_addr = target;
daemon_addr.sin_port = daemon_port;
pfd[0].fd = ctl_sockt;
@@ -65,10 +65,10 @@ ctl_transact(struct in_addr target, CTL_
do {
/* resend message until a response is obtained */
do {
-   cc = sendto(ctl_sockt, (char *)&msg, sizeof (msg), 0,
+   cc = sendto(ctl_sockt, (char *)&mesg, sizeof(mesg), 0,
(struct sockaddr *)&daemon_addr,
-   sizeof (daemon_addr));
-   if (cc != sizeof (msg)) {
+   sizeof(daemon_addr));
+   if (cc != sizeof(mesg)) {
if (errno == EINTR)
continue;
quit("Error on write to talk daemon", 1);
@@ -86,7 +86,7 @@ ctl_transact(struct in_addr target, CTL_
 * request/acknowledgements being sent)
 */
do {
-   cc = recv(ctl_sockt, (char *)rp, sizeof (*rp), 0);
+   cc = recv(ctl_sockt, (char *)rp, sizeof(*rp), 0);
if (cc < 0) {
if (errno == EINTR)
continue;
Index: display.c
===
RCS file: /cvs/src/usr.bin/talk/display.c,v
retrieving revision 1.18
diff -u -p -u -p -r1.18 display.c
--- display.c   1 Feb 2016 07:29:25 -   1.18
+++ display.c   23 May 2017 15:23:42 -
@@ -95,7 +95,7 @@ display(xwin_t *win, char *text, int siz
 * the line.
 */
if (*text == win->werase) {
-   int endcol, xcol, i, c;
+   int endcol, xcol, j, c;
 
endcol = win->x_col;
xcol = endcol - 1;
@@ -112,7 +112,7 @@ display(xwin_t *win, char *text, int siz
xcol--;
}
wmove(win->x_win, win->x_line, xcol + 1);
-   for (i = xcol + 1; i < endcol; i++)
+   for (j = xcol + 1; j < endcol; j++)
waddch(win->x_win, ' ');
wmove(win->x_win, win->x_line, xcol + 1);
getyx(win->x_win, win->x_line, win->x_col);
Index: init_disp.c
===
RCS file: /cvs/src/usr.bin/talk/init_disp.c,v
retrieving revision 1.22
diff -u -p -u -p -r1.22 init_disp.c
--- init_disp.c 1 Feb 2016 07:29:25 -   1.22
+++ init_disp.c 23 May 2017 15:23:42 -
@@ -81,11 +81,7 @@ init_display(void)
wclear(his_win.x_win);
 
line_win = newwin(1, COLS, my_win.x_nlines, 0);
-#if defined(NCURSES_VERSION) || defined(whline)
whline(line_win, '-', COLS);
-#else
-   box(line_win, '-', '-');
-#endif
wrefresh(line_win);
/* let them know we are working on it */
current_state = "No connection yet";
@@ -192,12 +188,7 @@ resize_display(void)
 
wresize(line_win, 1, COLS);
mvwin(line_win, my_win.x_nlines, 0);
-#if defined(NCURSES_VERSION) || defined(whline)
whline(line_win, '-', COLS);
-#else
-   wmove(line_win, my_win.x_nlines, 0);
-   box(line_win, '-', '-');
-#endif
 
/* Now redraw the screen. */
wrefresh(his_win.x_win);
Index: invite.c
===
RCS file: /cvs/src/usr.bin/talk/invite.c,v
retrieving revision 1.17
diff -u -p -u -p -r1.17 invite.c
--- invite.c16 Mar 2016 15:41:11 -  1.17
+++ invite.c23 May 2017 15:23:42 -
@@ -75,13 +75,9 @@ invite_remote(void)
itimer.it_interval = itimer.it_value;
if (listen(sockt, 5) != 0)
quit("Error on attempt to listen for caller", 1);
-#ifdef MSG_EOR
   

memory barriers and atomic instructions

2017-05-23 Thread Mark Kettenis
So here is a diff that implements what I proposed recently.  This
recognizes that atomic instructions on amd64 already include an
implicit memory barrier and allows us to write optimized code that
avoids a redundant memory barrier.

Note that I don't have a use-case for membar_exit_before_atomic() yet;
I merely added it for symmetry reasons.  I can leave it out if that's
what people prefer.

This should allow us to use a generic mutex implementation written in
C without a significant penalty.

ok?



Index: sys/atomic.h
===
RCS file: /cvs/src/sys/sys/atomic.h,v
retrieving revision 1.4
diff -u -p -r1.4 atomic.h
--- sys/atomic.h24 Jan 2017 22:22:20 -  1.4
+++ sys/atomic.h23 May 2017 15:01:34 -
@@ -219,4 +219,12 @@ atomic_sub_long_nv(volatile unsigned lon
 #define membar_sync() __sync_synchronize()
 #endif
 
+#ifndef membar_enter_after_atomic
+#define membar_enter_after_atomic() membar_enter()
+#endif
+
+#ifndef membar_exit_before_atomic
+#define membar_exit_before_atomic() membar_exit()
+#endif
+
 #endif /* _SYS_ATOMIC_H_ */
Index: arch/amd64/include/atomic.h
===
RCS file: /cvs/src/sys/arch/amd64/include/atomic.h,v
retrieving revision 1.19
diff -u -p -r1.19 atomic.h
--- arch/amd64/include/atomic.h 12 May 2017 08:47:03 -  1.19
+++ arch/amd64/include/atomic.h 23 May 2017 15:02:23 -
@@ -276,6 +276,9 @@ _atomic_sub_long_nv(volatile unsigned lo
 #define membar_sync()  __membar("")
 #endif
 
+#define membar_enter_after_atomic()__membar("")
+#define membar_exit_before_atomic()__membar("")
+
 #ifdef _KERNEL
 
 /* virtio needs MP membars even on SP kernels */



Re: multipath / route priority support for ospf6d

2017-05-23 Thread Alexander Bluhm
On Mon, May 15, 2017 at 08:43:02PM +0200, Florian Riehm wrote:
> > The attached patch ports the multipath support from ospfd to ospf6d.

> @@ -171,48 +260,30 @@ kr_change(struct kroute *kroute)
>* - zero out ifindex (this is no longer relevant)
>*/
>   action = RTM_CHANGE;
> - kr->r.flags = kroute->flags | F_OSPFD_INSERTED;
> - kr->r.ifindex = 0;
> - rtlabel_unref(kr->r.rtlabel);
> - kr->r.ext_tag = kroute->ext_tag;
> - kr->r.rtlabel = kroute->rtlabel;
> - }
> + } else if (kr->next == NULL)/* single path OSPF route */
> + action = RTM_CHANGE;

I wonder wether this check should be
} else if (kr->next == NULL && krcount == 1)
At least this is what ospfd is doing.

>   RB_FOREACH(kr, kroute_tree, &krt)
>   if (!(kr->r.flags & F_KERNEL))
> - send_rtmsg(kr_state.fd, RTM_ADD, &kr->r);
> + for (kn = kr; kn != NULL; kn = kn->next) {
> + send_rtmsg(kr_state.fd, RTM_ADD, &kn->r);
> + }

> - RB_FOREACH(kr, kroute_tree, &krt)
> + RB_FOREACH(kr, kroute_tree, &krt) {
>   if (!(kr->r.flags & F_KERNEL))
> - send_rtmsg(kr_state.fd, RTM_DELETE, &kr->r);
> + for (kn = kr; kn != NULL; kn = kn->next) {
> + send_rtmsg(kr_state.fd, RTM_DELETE, &kn->r);
> + }
> + }

The braces { } are used a bit inconsistently here.

Anyway I think this diff should go in as it is.

OK bluhm@



Re: IP in IP header chain input

2017-05-23 Thread Martin Pieuchot
On 23/05/17(Tue) 13:36, Alexander Bluhm wrote:
> The IP in IP input function strips the outer header and reinserts
> the inner IP packet into the internet queue.  The IPv6 local delivery
> code has a loop to deal with header chains.  My idea is to use this
> loop and avoid the queueing and rescheduling.  The packet could be
> processed in a single flow.
> 
> - The ip_input() and ip6_input() functions behave like regular
>   protocol input functions.
> - Use one ip_local() loop that can process IPv4 and IPv6 headers.
>   When we have IP in IP the address family may change.
> - The ipip_input() function calls ip_input() and ip6_input().
> - Add a check to prevent recursion, only a single loop may run.
> 
> If we agree that this is a useful direction, I will split die diff
> in smaller parts for review.

I think it's a useful direction however your diff conflict with the
one to unlock the IPv4 forwarding path:

http://marc.info/?l=openbsd-tech&m=148778467826115&w=2

I'm using ip{6,}_ours() to enqueue mbufs.  I worked hard to make sure
these functions only take a single mbuf, your diff is going in the
opposite direction.

I also think that you should introduce ip6_local() instead of mixing the
two protocols.  The reason is simple, right now my diff enqueues packets
for local delivery in ip_ours(), but we might want to move that to ip_local() 
if somebody would do the work to turn the reassembly code MP-safe.  IPv6
is different in this regard since multiples protocol input routines can
be called per packet, so merging the two functions won't help.

I'm also don't think we should add more parameters to ip_input() because
it will be called directly.


> Index: netinet/ip_input.c
> ===
> RCS file: /data/mirror/openbsd/cvs/src/sys/netinet/ip_input.c,v
> retrieving revision 1.304
> diff -u -p -r1.304 ip_input.c
> --- netinet/ip_input.c22 May 2017 22:23:11 -  1.304
> +++ netinet/ip_input.c23 May 2017 11:28:32 -
> @@ -61,6 +61,11 @@
>  #include 
>  #include 
>  
> +#ifdef INET6
> +#include 
> +#include 
> +#endif
> +
>  #if NPF > 0
>  #include 
>  #endif
> @@ -126,7 +131,7 @@ int ip_sysctl_ipstat(void *, size_t *, v
>  
>  static struct mbuf_queue ipsend_mq;
>  
> -void ip_ours(struct mbuf *);
> +void ip_ours(struct mbuf *, int *, int *, int);
>  int  ip_dooptions(struct mbuf *, struct ifnet *);
>  int  in_ouraddr(struct mbuf *, struct ifnet *, struct rtentry **);
>  
> @@ -211,6 +216,7 @@ void
>  ipintr(void)
>  {
>   struct mbuf *m;
> + int off;
>  
>   /*
>* Get next datagram off input queue and get IP header
> @@ -221,7 +227,8 @@ ipintr(void)
>   if ((m->m_flags & M_PKTHDR) == 0)
>   panic("ipintr no HDR");
>  #endif
> - ipv4_input(m);
> + off = 0;
> + ip_input(&m, &off, IPPROTO_IPV4, AF_UNSPEC);
>   }
>  }
>  
> @@ -230,24 +237,27 @@ ipintr(void)
>   *
>   * Checksum and byte swap header.  Process options. Forward or deliver.
>   */
> -void
> -ipv4_input(struct mbuf *m)
> +int
> +ip_input(struct mbuf **mp, int *offp, int nxt, int af)
>  {
> + struct mbuf *m = *mp;
>   struct ifnet*ifp;
>   struct rtentry  *rt = NULL;
>   struct ip   *ip;
>   int hlen, len;
>   in_addr_t pfrdr = 0;
>  
> + KASSERT(*offp == 0);
> +
>   ifp = if_get(m->m_pkthdr.ph_ifidx);
>   if (ifp == NULL)
>   goto bad;
>  
>   ipstat_inc(ips_total);
>   if (m->m_len < sizeof (struct ip) &&
> - (m = m_pullup(m, sizeof (struct ip))) == NULL) {
> + (m = *mp = m_pullup(m, sizeof (struct ip))) == NULL) {
>   ipstat_inc(ips_toosmall);
> - goto out;
> + goto bad;
>   }
>   ip = mtod(m, struct ip *);
>   if (ip->ip_v != IPVERSION) {
> @@ -260,9 +270,9 @@ ipv4_input(struct mbuf *m)
>   goto bad;
>   }
>   if (hlen > m->m_len) {
> - if ((m = m_pullup(m, hlen)) == NULL) {
> + if ((m = *mp = m_pullup(m, hlen)) == NULL) {
>   ipstat_inc(ips_badhlen);
> - goto out;
> + goto bad;
>   }
>   ip = mtod(m, struct ip *);
>   }
> @@ -329,10 +339,11 @@ ipv4_input(struct mbuf *m)
>* Packet filter
>*/
>   pfrdr = ip->ip_dst.s_addr;
> - if (pf_test(AF_INET, PF_IN, ifp, &m) != PF_PASS)
> + if (pf_test(AF_INET, PF_IN, ifp, mp) != PF_PASS)
>   goto bad;
> + m = *mp;
>   if (m == NULL)
> - goto out;
> + goto bad;
>  
>   ip = mtod(m, struct ip *);
>   hlen = ip->ip_hl << 2;
> @@ -346,17 +357,18 @@ ipv4_input(struct mbuf *m)
>* to be sent and the original packet to be freed).
>*/
>   if (hlen > sizeof (struct ip) && ip_dooptions(m, ifp)) {
> - goto out;
> + m = *mp = NULL;
> + goto bad;
>  

IP in IP header chain input

2017-05-23 Thread Alexander Bluhm
Hi,

The IP in IP input function strips the outer header and reinserts
the inner IP packet into the internet queue.  The IPv6 local delivery
code has a loop to deal with header chains.  My idea is to use this
loop and avoid the queueing and rescheduling.  The packet could be
processed in a single flow.

- The ip_input() and ip6_input() functions behave like regular
  protocol input functions.
- Use one ip_local() loop that can process IPv4 and IPv6 headers.
  When we have IP in IP the address family may change.
- The ipip_input() function calls ip_input() and ip6_input().
- Add a check to prevent recursion, only a single loop may run.

If we agree that this is a useful direction, I will split die diff
in smaller parts for review.

bluhm

Index: netinet/ip_input.c
===
RCS file: /data/mirror/openbsd/cvs/src/sys/netinet/ip_input.c,v
retrieving revision 1.304
diff -u -p -r1.304 ip_input.c
--- netinet/ip_input.c  22 May 2017 22:23:11 -  1.304
+++ netinet/ip_input.c  23 May 2017 11:28:32 -
@@ -61,6 +61,11 @@
 #include 
 #include 
 
+#ifdef INET6
+#include 
+#include 
+#endif
+
 #if NPF > 0
 #include 
 #endif
@@ -126,7 +131,7 @@ int ip_sysctl_ipstat(void *, size_t *, v
 
 static struct mbuf_queue   ipsend_mq;
 
-void   ip_ours(struct mbuf *);
+void   ip_ours(struct mbuf *, int *, int *, int);
 intip_dooptions(struct mbuf *, struct ifnet *);
 intin_ouraddr(struct mbuf *, struct ifnet *, struct rtentry **);
 
@@ -211,6 +216,7 @@ void
 ipintr(void)
 {
struct mbuf *m;
+   int off;
 
/*
 * Get next datagram off input queue and get IP header
@@ -221,7 +227,8 @@ ipintr(void)
if ((m->m_flags & M_PKTHDR) == 0)
panic("ipintr no HDR");
 #endif
-   ipv4_input(m);
+   off = 0;
+   ip_input(&m, &off, IPPROTO_IPV4, AF_UNSPEC);
}
 }
 
@@ -230,24 +237,27 @@ ipintr(void)
  *
  * Checksum and byte swap header.  Process options. Forward or deliver.
  */
-void
-ipv4_input(struct mbuf *m)
+int
+ip_input(struct mbuf **mp, int *offp, int nxt, int af)
 {
+   struct mbuf *m = *mp;
struct ifnet*ifp;
struct rtentry  *rt = NULL;
struct ip   *ip;
int hlen, len;
in_addr_t pfrdr = 0;
 
+   KASSERT(*offp == 0);
+
ifp = if_get(m->m_pkthdr.ph_ifidx);
if (ifp == NULL)
goto bad;
 
ipstat_inc(ips_total);
if (m->m_len < sizeof (struct ip) &&
-   (m = m_pullup(m, sizeof (struct ip))) == NULL) {
+   (m = *mp = m_pullup(m, sizeof (struct ip))) == NULL) {
ipstat_inc(ips_toosmall);
-   goto out;
+   goto bad;
}
ip = mtod(m, struct ip *);
if (ip->ip_v != IPVERSION) {
@@ -260,9 +270,9 @@ ipv4_input(struct mbuf *m)
goto bad;
}
if (hlen > m->m_len) {
-   if ((m = m_pullup(m, hlen)) == NULL) {
+   if ((m = *mp = m_pullup(m, hlen)) == NULL) {
ipstat_inc(ips_badhlen);
-   goto out;
+   goto bad;
}
ip = mtod(m, struct ip *);
}
@@ -329,10 +339,11 @@ ipv4_input(struct mbuf *m)
 * Packet filter
 */
pfrdr = ip->ip_dst.s_addr;
-   if (pf_test(AF_INET, PF_IN, ifp, &m) != PF_PASS)
+   if (pf_test(AF_INET, PF_IN, ifp, mp) != PF_PASS)
goto bad;
+   m = *mp;
if (m == NULL)
-   goto out;
+   goto bad;
 
ip = mtod(m, struct ip *);
hlen = ip->ip_hl << 2;
@@ -346,17 +357,18 @@ ipv4_input(struct mbuf *m)
 * to be sent and the original packet to be freed).
 */
if (hlen > sizeof (struct ip) && ip_dooptions(m, ifp)) {
-   goto out;
+   m = *mp = NULL;
+   goto bad;
}
 
if (ip->ip_dst.s_addr == INADDR_BROADCAST ||
ip->ip_dst.s_addr == INADDR_ANY) {
-   ip_ours(m);
+   ip_ours(m, offp, &nxt, af);
goto out;
}
 
if (in_ouraddr(m, ifp, &rt)) {
-   ip_ours(m);
+   ip_ours(m, offp, &nxt, af);
goto out;
}
 
@@ -373,9 +385,9 @@ ipv4_input(struct mbuf *m)
int rv;
 
if (m->m_flags & M_EXT) {
-   if ((m = m_pullup(m, hlen)) == NULL) {
+   if ((m = *mp = m_pullup(m, hlen)) == NULL) {
ipstat_inc(ips_toosmall);
-   goto out;
+   goto bad;
}
ip = mtod(m, struct ip *);
}
@@ -405,7 +417,7 @@ ipv4_input(struct mbuf *m)
 * host belongs to their destination

Re: UDP sendspace for dlna providing

2017-05-23 Thread Mike Belopuhov
On Tue, May 23, 2017 at 11:51 +0100, Stuart Henderson wrote:
> (replying to an old mail),
> 
> On 2017/03/16 18:07, Claudio Jeker wrote:
> > On Thu, Mar 16, 2017 at 03:46:38PM +0100, Eric JACQUOT wrote:
> > > Hi all,
> > > 
> > > I had some problems with dlna server (minidlna) and a lot of cuts and 
> > > crashes of the client when playing videos.
> > > It seems that the default net.inet.udp.sendspace (9216 by default) 
> > > variable is not suitable. I have increased it as a result of the 
> > > capacities of my network and I no longer have issue of broadcasting 
> > > videos.
> > > It may be time to increase the default value or document all ports based 
> > > on dlna accordingly.
> > > Not having much time for these actions, thank you for giving me the best 
> > > way so that I provide the necessary diffs.
> > > 
> > > Maybe I'm wrong so tell me...
> > > 
> > 
> > Please change minidlna to use a setsockopt() to increase the send buffer.
> > Doing this globally is not the right fix.
> 
> I don't see a sockopt to control udp_sendspace per-socket, am I missing
> something? Nameservers easily run into the default limit too (I've been
> running with increased net.inet.udp.sendspace on nameservers for ages)..
> 

Isn't SO_SNDBUF what you're looking for?  tcpbench(1) does it via -S
for instance.



Re: UDP sendspace for dlna providing

2017-05-23 Thread Stuart Henderson
(replying to an old mail),

On 2017/03/16 18:07, Claudio Jeker wrote:
> On Thu, Mar 16, 2017 at 03:46:38PM +0100, Eric JACQUOT wrote:
> > Hi all,
> > 
> > I had some problems with dlna server (minidlna) and a lot of cuts and 
> > crashes of the client when playing videos.
> > It seems that the default net.inet.udp.sendspace (9216 by default) variable 
> > is not suitable. I have increased it as a result of the capacities of my 
> > network and I no longer have issue of broadcasting videos.
> > It may be time to increase the default value or document all ports based on 
> > dlna accordingly.
> > Not having much time for these actions, thank you for giving me the best 
> > way so that I provide the necessary diffs.
> > 
> > Maybe I'm wrong so tell me...
> > 
> 
> Please change minidlna to use a setsockopt() to increase the send buffer.
> Doing this globally is not the right fix.

I don't see a sockopt to control udp_sendspace per-socket, am I missing
something? Nameservers easily run into the default limit too (I've been
running with increased net.inet.udp.sendspace on nameservers for ages)..