Re: Enabled bnxt on arm64

2018-09-10 Thread Jonathan Matthew

On 11/09/18 12:03, Carlos Cardenas wrote:

Howdy.

Attached is a patch to enable bnxt on arm64.

Tested (and running) on mcbin with Broadcom BCM57404 (Dell variant).

Comments? Ok?


ok by me.



+--+
Carlos





Re: vmd fail fast on unknown disk format

2018-09-10 Thread Ori Bernstein
On Mon, 10 Sep 2018 20:00:16 -0700, Carlos Cardenas  
wrote:

> Howdy.
> 
> Attached patch allows vmd to fail fast on unknown disk format along with
> some minor clean up on logging.
> 
> Comments? Ok?
> 
> +--+
> Carlos

One nit:

refs = htobe16(refs);
if (pwrite(disk->fd, , sizeof refs, l2cluster + 2*l2idx) != 2) {
-   log_warn("could not write ref block");
+   log_warn("%s: could not write ref block", __func__);
}
return 0;
 }

Should probably return -1 in the error case. I think I changed that in
my (WIP) cluster reuse change, but if you're touching the code it might
as well go in here.


-- 
Ori Bernstein



vmd fail fast on unknown disk format

2018-09-10 Thread Carlos Cardenas
Howdy.

Attached patch allows vmd to fail fast on unknown disk format along with
some minor clean up on logging.

Comments? Ok?

+--+
Carlos
Index: vioqcow2.c
===
RCS file: /home/los/cvs/src/usr.sbin/vmd/vioqcow2.c,v
retrieving revision 1.1
diff -u -p -r1.1 vioqcow2.c
--- vioqcow2.c  9 Sep 2018 04:09:32 -   1.1
+++ vioqcow2.c  11 Sep 2018 02:42:11 -
@@ -127,7 +127,7 @@ virtio_init_qcow2(struct virtio_backing 
if (diskp == NULL)
return -1;
if (qc2_open(diskp, fd) == -1) {
-   log_warnx("could not open qcow2 disk");
+   log_warnx("%s: could not open qcow2 disk", __func__);
free(diskp);
return -1;
}
@@ -162,11 +162,11 @@ qc2_open(struct qcdisk *disk, int fd)
int version;
 
if (pread(fd, , sizeof header, 0) != sizeof header) {
-   log_warn("short read on header");
+   log_warn("%s: short read on header", __func__);
return -1;
}
if (strncmp(header.magic, "QFI\xfb", 4) != 0) {
-   log_warn("invalid magic numbers");
+   log_warn("%s: invalid magic numbers", __func__);
return -1;
}
pthread_rwlock_init(>lock, NULL);
@@ -196,7 +196,7 @@ qc2_open(struct qcdisk *disk, int fd)
 * We only know about the dirty or corrupt bits here.
 */
if (disk->incompatfeatures & ~(QCOW2_DIRTY|QCOW2_CORRUPT)) {
-   log_warn("%s: unsupported features %llx", __progname,
+   log_warn("%s: unsupported features %llx", __func__,
disk->incompatfeatures & ~(QCOW2_DIRTY|QCOW2_CORRUPT));
return -1;
}
@@ -211,7 +211,7 @@ qc2_open(struct qcdisk *disk, int fd)
disk->l1[i] = be64toh(disk->l1[i]);
version = be32toh(header.version);
if (version != 2 && version != 3) {
-   log_warn("%s: unknown qcow2 version %d", __progname, version);
+   log_warn("%s: unknown qcow2 version %d", __func__, version);
return -1;
}
 
@@ -222,16 +222,16 @@ qc2_open(struct qcdisk *disk, int fd)
 * FIXME: we need to figure out a way of opening these things,
 * otherwise we just crash with a pledge violation.
 */
-   log_warn("unsupported external snapshot images");
+   log_warn("%s: unsupported external snapshot images", __func__);
return -1;
 
if (backingsz >= sizeof basepath - 1) {
-   log_warn("%s: snapshot path too long", __progname);
+   log_warn("%s: snapshot path too long", __func__);
return -1;
}
if (pread(fd, basepath, backingsz, backingoff) != backingsz) {
log_warn("%s: could not read snapshot base name",
-   __progname);
+   __func__);
return -1;
}
basepath[backingsz] = 0;
@@ -243,7 +243,7 @@ qc2_open(struct qcdisk *disk, int fd)
}
if (disk->base->clustersz != disk->clustersz) {
log_warn("%s: all disks must share clustersize",
-   __progname);
+   __func__);
free(disk->base);
return -1;
}
@@ -414,7 +414,7 @@ xlate(struct qcdisk *disk, off_t off, in
if (inplace)
*inplace = !!(cluster & QCOW2_INPLACE);
if (cluster & QCOW2_COMPRESSED) {
-   log_warn("%s: compressed clusters unsupported", __progname);
+   log_warn("%s: compressed clusters unsupported", __func__);
goto err;
}
pthread_rwlock_unlock(>lock);
@@ -556,7 +556,7 @@ inc_refs(struct qcdisk *disk, off_t off,
l2cluster = disk->end;
disk->end += disk->clustersz;
if (ftruncate(disk->fd, disk->end) < 0) {
-   log_warn("refs block grow fail ");
+   log_warn("%s: refs block grow fail", __func__);
return -1;
}
buf = htobe64(l2cluster);
@@ -573,7 +573,7 @@ inc_refs(struct qcdisk *disk, off_t off,
}
refs = htobe16(refs);
if (pwrite(disk->fd, , sizeof refs, l2cluster + 2*l2idx) != 2) {
-   log_warn("could not write ref block");
+   log_warn("%s: could not write ref block", __func__);
}
return 0;
 }
Index: virtio.c
===
RCS file: /home/los/cvs/src/usr.sbin/vmd/virtio.c,v
retrieving revision 1.65
diff -u -p -r1.65 virtio.c
--- virtio.c9 Sep 2018 04:09:32 -   1.65
+++ virtio.c11 Sep 2018 02:51:37 -
@@ 

Enabled bnxt on arm64

2018-09-10 Thread Carlos Cardenas
Howdy.

Attached is a patch to enable bnxt on arm64.

Tested (and running) on mcbin with Broadcom BCM57404 (Dell variant).

Comments? Ok?

+--+
Carlos
Index: GENERIC
===
RCS file: /home/los/cvs/src/sys/arch/arm64/conf/GENERIC,v
retrieving revision 1.90
diff -u -p -r1.90 GENERIC
--- GENERIC 27 Aug 2018 21:09:47 -  1.90
+++ GENERIC 11 Sep 2018 02:00:16 -
@@ -180,6 +180,7 @@ ppb*at pci? # PCI-PCI 
bridges
 pci*   at ppb?
 
 # PCI Ethernet
+bnxt*  at pci? # Broadcom BCM573xx, BCM574xx
 em*at pci? # Intel Pro/1000 Ethernet
 ix*at pci? # Intel 82598EB 10Gb Ethernet
 mskc*  at pci? # Marvell Yukon-2
Index: RAMDISK
===
RCS file: /home/los/cvs/src/sys/arch/arm64/conf/RAMDISK,v
retrieving revision 1.72
diff -u -p -r1.72 RAMDISK
--- RAMDISK 27 Aug 2018 20:05:06 -  1.72
+++ RAMDISK 11 Sep 2018 02:00:14 -
@@ -171,6 +171,7 @@ ppb*at pci? # PCI-PCI 
bridges
 pci*   at ppb?
 
 # PCI Ethernet
+bnxt*  at pci? # Broadcom BCM573xx, BCM574xx
 em*at pci? # Intel Pro/1000 Ethernet
 ix*at pci? # Intel 82598EB 10Gb Ethernet
 mskc*  at pci? # Marvell Yukon-2


pfctl: host(): remove now unused r buffer

2018-09-10 Thread Klemens Nanni
`r' is a left over from before my AF swipe.

While here, use __func__. Now I can start syncing daemons in base.

OK?

Index: pfctl_parser.c
===
RCS file: /cvs/src/sbin/pfctl/pfctl_parser.c,v
retrieving revision 1.334
diff -u -p -r1.334 pfctl_parser.c
--- pfctl_parser.c  10 Sep 2018 20:53:53 -  1.334
+++ pfctl_parser.c  10 Sep 2018 22:35:00 -
@@ -1612,11 +1612,11 @@ host(const char *s, int opts)
 {
struct node_host*h = NULL, *n;
int  mask = -1;
-   char*p, *r, *ps, *if_name;
+   char*p, *ps, *if_name;
const char  *errstr;
 
if ((ps = strdup(s)) == NULL)
-   err(1, "host: strdup");
+   err(1, "%s: strdup", __func__);
 
if ((if_name = strrchr(ps, '@')) != NULL) {
if_name[0] = '\0';
@@ -1624,16 +1624,13 @@ host(const char *s, int opts)
}
 
if ((p = strrchr(ps, '/')) != NULL) {
-   if ((r = strdup(ps)) == NULL)
-   err(1, "host: strdup");
mask = strtonum(p+1, 0, 128, );
if (errstr) {
fprintf(stderr, "netmask is %s: %s\n", errstr, p);
goto error;
}
p[0] = '\0';
-   } else
-   r = ps;
+   }
 
if ((h = host_if(ps, mask)) == NULL &&
(h = host_ip(ps, mask)) == NULL &&
@@ -1645,15 +1642,13 @@ host(const char *s, int opts)
if (if_name && if_name[0])
for (n = h; n != NULL; n = n->next)
if ((n->ifname = strdup(if_name)) == NULL)
-   err(1, "host: strdup");
+   err(1, "%s: strdup", __func__);
for (n = h; n != NULL; n = n->next) {
n->addr.type = PF_ADDR_ADDRMASK;
n->weight = 0;
}   
 
 error:
-   if (r != ps)
-   free(r);
free(ps);
return (h);
 }



Re: remove pcb hash macros

2018-09-10 Thread Stefan Sperling
On Tue, Sep 11, 2018 at 12:01:28AM +0200, Alexander Bluhm wrote:
> Hi,
> 
> I don't see any use for the INPCBHASH() macros.  Just expand them.
> 
> ok?

ok.

Pretty pointless indeed.

> 
> bluhm
> 
> Index: netinet/in_pcb.c
> ===
> RCS file: /data/mirror/openbsd/cvs/src/sys/netinet/in_pcb.c,v
> retrieving revision 1.241
> diff -u -p -r1.241 in_pcb.c
> --- netinet/in_pcb.c  7 Sep 2018 10:55:35 -   1.241
> +++ netinet/in_pcb.c  10 Sep 2018 21:49:00 -
> @@ -153,9 +153,6 @@ in_pcbhash(struct inpcbtable *table, int
>   return (>inpt_hashtbl[SipHash24_End() & table->inpt_mask]);
>  }
>  
> -#define  INPCBHASH(table, faddr, fport, laddr, lport, rdom) \
> - in_pcbhash(table, rdom, faddr, fport, laddr, lport)
> -
>  struct inpcbhead *
>  in6_pcbhash(struct inpcbtable *table, int rdom,
>  const struct in6_addr *faddr, u_short fport,
> @@ -174,9 +171,6 @@ in6_pcbhash(struct inpcbtable *table, in
>   return (>inpt_hashtbl[SipHash24_End() & table->inpt_mask]);
>  }
>  
> -#define  IN6PCBHASH(table, faddr, fport, laddr, lport, rdom) \
> - in6_pcbhash(table, rdom, faddr, fport, laddr, lport)
> -
>  struct inpcbhead *
>  in_pcblhash(struct inpcbtable *table, int rdom, u_short lport)
>  {
> @@ -190,8 +184,6 @@ in_pcblhash(struct inpcbtable *table, in
>   return (>inpt_lhashtbl[SipHash24_End() & table->inpt_lmask]);
>  }
>  
> -#define  INPCBLHASH(table, lport, rdom) in_pcblhash(table, rdom, lport)
> -
>  void
>  in_pcbinit(struct inpcbtable *table, int hashsize)
>  {
> @@ -284,18 +276,18 @@ in_pcballoc(struct socket *so, struct in
>   if (table->inpt_count++ > INPCBHASH_LOADFACTOR(table->inpt_size))
>   (void)in_pcbresize(table, table->inpt_size * 2);
>   TAILQ_INSERT_HEAD(>inpt_queue, inp, inp_queue);
> - head = INPCBLHASH(table, inp->inp_lport, inp->inp_rtableid);
> + head = in_pcblhash(table, inp->inp_rtableid, inp->inp_lport);
>   LIST_INSERT_HEAD(head, inp, inp_lhash);
>  #ifdef INET6
>   if (sotopf(so) == PF_INET6)
> - head = IN6PCBHASH(table, >inp_faddr6, inp->inp_fport,
> - >inp_laddr6, inp->inp_lport,
> - rtable_l2(inp->inp_rtableid));
> + head = in6_pcbhash(table, rtable_l2(inp->inp_rtableid),
> + >inp_faddr6, inp->inp_fport,
> + >inp_laddr6, inp->inp_lport);
>   else
>  #endif /* INET6 */
> - head = INPCBHASH(table, >inp_faddr, inp->inp_fport,
> - >inp_laddr, inp->inp_lport,
> - rtable_l2(inp->inp_rtableid));
> + head = in_pcbhash(table, rtable_l2(inp->inp_rtableid),
> + >inp_faddr, inp->inp_fport,
> + >inp_laddr, inp->inp_lport);
>   LIST_INSERT_HEAD(head, inp, inp_hash);
>   so->so_pcb = inp;
>  
> @@ -770,7 +762,7 @@ in_pcblookup_local(struct inpcbtable *ta
>   u_int rdomain;
>  
>   rdomain = rtable_l2(rtable);
> - head = INPCBLHASH(table, lport, rdomain);
> + head = in_pcblhash(table, rdomain, lport);
>   LIST_FOREACH(inp, head, inp_lhash) {
>   if (rtable_l2(inp->inp_rtableid) != rdomain)
>   continue;
> @@ -971,19 +963,19 @@ in_pcbrehash(struct inpcb *inp)
>   NET_ASSERT_LOCKED();
>  
>   LIST_REMOVE(inp, inp_lhash);
> - head = INPCBLHASH(table, inp->inp_lport, inp->inp_rtableid);
> + head = in_pcblhash(table, inp->inp_rtableid, inp->inp_lport);
>   LIST_INSERT_HEAD(head, inp, inp_lhash);
>   LIST_REMOVE(inp, inp_hash);
>  #ifdef INET6
>   if (inp->inp_flags & INP_IPV6)
> - head = IN6PCBHASH(table, >inp_faddr6, inp->inp_fport,
> - >inp_laddr6, inp->inp_lport,
> - rtable_l2(inp->inp_rtableid));
> + head = in6_pcbhash(table, rtable_l2(inp->inp_rtableid),
> + >inp_faddr6, inp->inp_fport,
> + >inp_laddr6, inp->inp_lport);
>   else
>  #endif /* INET6 */
> - head = INPCBHASH(table, >inp_faddr, inp->inp_fport,
> - >inp_laddr, inp->inp_lport,
> - rtable_l2(inp->inp_rtableid));
> + head = in_pcbhash(table, rtable_l2(inp->inp_rtableid),
> + >inp_faddr, inp->inp_fport,
> + >inp_laddr, inp->inp_lport);
>   LIST_INSERT_HEAD(head, inp, inp_hash);
>  }
>  
> @@ -1046,7 +1038,7 @@ in_pcbhashlookup(struct inpcbtable *tabl
>   u_int rdomain;
>  
>   rdomain = rtable_l2(rtable);
> - head = INPCBHASH(table, , fport, , lport, rdomain);
> + head = in_pcbhash(table, rdomain, , fport, , lport);
>   LIST_FOREACH(inp, head, inp_hash) {
>  #ifdef INET6
>   if (inp->inp_flags & INP_IPV6)
> @@ -1090,7 +1082,7 @@ in6_pcbhashlookup(struct inpcbtable *tab
>   u_int rdomain;
>  
>   rdomain = rtable_l2(rtable);
> - head = IN6PCBHASH(table, faddr, fport, laddr, lport, rdomain);
> + head = 

remove pcb hash macros

2018-09-10 Thread Alexander Bluhm
Hi,

I don't see any use for the INPCBHASH() macros.  Just expand them.

ok?

bluhm

Index: netinet/in_pcb.c
===
RCS file: /data/mirror/openbsd/cvs/src/sys/netinet/in_pcb.c,v
retrieving revision 1.241
diff -u -p -r1.241 in_pcb.c
--- netinet/in_pcb.c7 Sep 2018 10:55:35 -   1.241
+++ netinet/in_pcb.c10 Sep 2018 21:49:00 -
@@ -153,9 +153,6 @@ in_pcbhash(struct inpcbtable *table, int
return (>inpt_hashtbl[SipHash24_End() & table->inpt_mask]);
 }
 
-#defineINPCBHASH(table, faddr, fport, laddr, lport, rdom) \
-   in_pcbhash(table, rdom, faddr, fport, laddr, lport)
-
 struct inpcbhead *
 in6_pcbhash(struct inpcbtable *table, int rdom,
 const struct in6_addr *faddr, u_short fport,
@@ -174,9 +171,6 @@ in6_pcbhash(struct inpcbtable *table, in
return (>inpt_hashtbl[SipHash24_End() & table->inpt_mask]);
 }
 
-#defineIN6PCBHASH(table, faddr, fport, laddr, lport, rdom) \
-   in6_pcbhash(table, rdom, faddr, fport, laddr, lport)
-
 struct inpcbhead *
 in_pcblhash(struct inpcbtable *table, int rdom, u_short lport)
 {
@@ -190,8 +184,6 @@ in_pcblhash(struct inpcbtable *table, in
return (>inpt_lhashtbl[SipHash24_End() & table->inpt_lmask]);
 }
 
-#defineINPCBLHASH(table, lport, rdom) in_pcblhash(table, rdom, lport)
-
 void
 in_pcbinit(struct inpcbtable *table, int hashsize)
 {
@@ -284,18 +276,18 @@ in_pcballoc(struct socket *so, struct in
if (table->inpt_count++ > INPCBHASH_LOADFACTOR(table->inpt_size))
(void)in_pcbresize(table, table->inpt_size * 2);
TAILQ_INSERT_HEAD(>inpt_queue, inp, inp_queue);
-   head = INPCBLHASH(table, inp->inp_lport, inp->inp_rtableid);
+   head = in_pcblhash(table, inp->inp_rtableid, inp->inp_lport);
LIST_INSERT_HEAD(head, inp, inp_lhash);
 #ifdef INET6
if (sotopf(so) == PF_INET6)
-   head = IN6PCBHASH(table, >inp_faddr6, inp->inp_fport,
-   >inp_laddr6, inp->inp_lport,
-   rtable_l2(inp->inp_rtableid));
+   head = in6_pcbhash(table, rtable_l2(inp->inp_rtableid),
+   >inp_faddr6, inp->inp_fport,
+   >inp_laddr6, inp->inp_lport);
else
 #endif /* INET6 */
-   head = INPCBHASH(table, >inp_faddr, inp->inp_fport,
-   >inp_laddr, inp->inp_lport,
-   rtable_l2(inp->inp_rtableid));
+   head = in_pcbhash(table, rtable_l2(inp->inp_rtableid),
+   >inp_faddr, inp->inp_fport,
+   >inp_laddr, inp->inp_lport);
LIST_INSERT_HEAD(head, inp, inp_hash);
so->so_pcb = inp;
 
@@ -770,7 +762,7 @@ in_pcblookup_local(struct inpcbtable *ta
u_int rdomain;
 
rdomain = rtable_l2(rtable);
-   head = INPCBLHASH(table, lport, rdomain);
+   head = in_pcblhash(table, rdomain, lport);
LIST_FOREACH(inp, head, inp_lhash) {
if (rtable_l2(inp->inp_rtableid) != rdomain)
continue;
@@ -971,19 +963,19 @@ in_pcbrehash(struct inpcb *inp)
NET_ASSERT_LOCKED();
 
LIST_REMOVE(inp, inp_lhash);
-   head = INPCBLHASH(table, inp->inp_lport, inp->inp_rtableid);
+   head = in_pcblhash(table, inp->inp_rtableid, inp->inp_lport);
LIST_INSERT_HEAD(head, inp, inp_lhash);
LIST_REMOVE(inp, inp_hash);
 #ifdef INET6
if (inp->inp_flags & INP_IPV6)
-   head = IN6PCBHASH(table, >inp_faddr6, inp->inp_fport,
-   >inp_laddr6, inp->inp_lport,
-   rtable_l2(inp->inp_rtableid));
+   head = in6_pcbhash(table, rtable_l2(inp->inp_rtableid),
+   >inp_faddr6, inp->inp_fport,
+   >inp_laddr6, inp->inp_lport);
else
 #endif /* INET6 */
-   head = INPCBHASH(table, >inp_faddr, inp->inp_fport,
-   >inp_laddr, inp->inp_lport,
-   rtable_l2(inp->inp_rtableid));
+   head = in_pcbhash(table, rtable_l2(inp->inp_rtableid),
+   >inp_faddr, inp->inp_fport,
+   >inp_laddr, inp->inp_lport);
LIST_INSERT_HEAD(head, inp, inp_hash);
 }
 
@@ -1046,7 +1038,7 @@ in_pcbhashlookup(struct inpcbtable *tabl
u_int rdomain;
 
rdomain = rtable_l2(rtable);
-   head = INPCBHASH(table, , fport, , lport, rdomain);
+   head = in_pcbhash(table, rdomain, , fport, , lport);
LIST_FOREACH(inp, head, inp_hash) {
 #ifdef INET6
if (inp->inp_flags & INP_IPV6)
@@ -1090,7 +1082,7 @@ in6_pcbhashlookup(struct inpcbtable *tab
u_int rdomain;
 
rdomain = rtable_l2(rtable);
-   head = IN6PCBHASH(table, faddr, fport, laddr, lport, rdomain);
+   head = in6_pcbhash(table, rdomain, faddr, fport, laddr, lport);
LIST_FOREACH(inp, head, inp_hash) {
if (!(inp->inp_flags & INP_IPV6))
continue;
@@ -1171,7 +1163,7 @@ 

Re: [patch] rebound: add NULL pointer checks

2018-09-10 Thread Ted Unangst
Anton Lindqvist wrote:
> > > > Since it's a daemon I guess it makes sense to continue execution instead
> > > > of dying. However, we should make sure to not leak memory along the
> > > > error paths. Also, log something when preloading the cache fails.
> 
> Committed, I settled on using goto. Thanks!

a little late, but looks good. thanks.



drm_wait_one_vblank() fix

2018-09-10 Thread Mark Kettenis
When we're cold, vblank interrupts don't happen, so we would wait
forever.  I added a short-circuit for this case, but apparently some
output connector detection code in inteldrm(4) relies on a delay here
to reliably detect whether something is connected or not.

I tried fixing this in our Linux compat code, but I didn't come up
with a working solution.  So this adds an #ifdef __OpenBSD__ block in
the drm_wait_one_vblank() implementations that we hopefully won't miss
when updating the drm code in the future.

Thanks to Philippe Meunier for figuring out the root cause of the
problem.  And sorry for the delay...

ok?


Index: dev/pci/drm/drm_irq.c
===
RCS file: /cvs/src/sys/dev/pci/drm/drm_irq.c,v
retrieving revision 1.70
diff -u -p -r1.70 drm_irq.c
--- dev/pci/drm/drm_irq.c   28 Mar 2018 05:27:28 -  1.70
+++ dev/pci/drm/drm_irq.c   10 Sep 2018 18:45:33 -
@@ -1317,8 +1317,21 @@ void drm_wait_one_vblank(struct drm_devi
int ret;
u32 last;
 
-   if (WARN_ON(pipe >= dev->num_crtcs) || cold)
+   if (WARN_ON(pipe >= dev->num_crtcs))
return;
+
+#ifdef __OpenBSD__
+   /*
+* If we're cold, vblank interrupts won't happen even if
+* they're turned on by the driver.  Just stall long enough
+* for a vblank to pass.  This assumes a vrefresh of at least
+* 25 Hz.
+*/
+   if (cold) {
+   delay(4);
+   return;
+   }
+#endif
 
ret = drm_vblank_get(dev, pipe);
if (WARN(ret, "vblank not available on crtc %i, ret=%i\n", pipe, ret))



add uid_from_user/gid_from_group [3/3]

2018-09-10 Thread Todd C. Miller
This diff replaces calls to getpwuid/getgrgid with
uid_from_user/gid_from_group and fixes warnings caused by the
user_from_uid/group_from_gid return value change to const char *.

I've also changed some getpwnam/getgrnam to user_from_uid/group_from_gid
where it makes sense.

If desired, I can break the warning fixes out into a separate diff.

 - todd

Index: bin/chmod/chmod.c
===
RCS file: /cvs/src/bin/chmod/chmod.c,v
retrieving revision 1.42
diff -u -p -u -r1.42 chmod.c
--- bin/chmod/chmod.c   28 May 2017 08:03:36 -  1.42
+++ bin/chmod/chmod.c   10 Sep 2018 00:46:49 -
@@ -293,7 +293,6 @@ done:
 uid_t
 a_uid(const char *s, int silent)
 {
-   struct passwd *pw;
const char *errstr;
uid_t uid;
 
@@ -301,8 +300,8 @@ a_uid(const char *s, int silent)
return ((uid_t)-1);
 
/* User name was given. */
-   if ((pw = getpwnam(s)) != NULL)
-   return (pw->pw_uid);
+   if (uid_from_user(s, ) != -1)
+   return (uid);
 
/* UID was given. */
uid = (uid_t)strtonum(s, 0, UID_MAX, );
@@ -323,7 +322,6 @@ a_uid(const char *s, int silent)
 gid_t
 a_gid(const char *s)
 {
-   struct group *gr;
const char *errstr;
gid_t gid;
 
@@ -331,8 +329,8 @@ a_gid(const char *s)
return ((gid_t)-1);
 
/* Group name was given. */
-   if ((gr = getgrnam(s)) != NULL)
-   return (gr->gr_gid);
+   if (gid_from_group(s, ) != -1)
+   return (gid);
 
/* GID was given. */
gid = (gid_t)strtonum(s, 0, GID_MAX, );
Index: bin/ls/ls.c
===
RCS file: /cvs/src/bin/ls/ls.c,v
retrieving revision 1.50
diff -u -p -u -r1.50 ls.c
--- bin/ls/ls.c 4 Feb 2018 22:09:33 -   1.50
+++ bin/ls/ls.c 10 Sep 2018 15:34:13 -
@@ -431,8 +431,9 @@ display(FTSENT *p, FTSENT *list)
int bcfile, flen, glen, ulen, maxflags, maxgroup, maxuser, maxlen;
int entries, needstats;
int width;
-   char *user, *group, buf[21];/* 64 bits == 20 digits */
+   const char *user, *group;
char nuser[12], ngroup[12];
+   char buf[21];   /* 64 bits == 20 digits */
char *flags = NULL;
 
/*
Index: bin/ps/ps.c
===
RCS file: /cvs/src/bin/ps/ps.c,v
retrieving revision 1.72
diff -u -p -u -r1.72 ps.c
--- bin/ps/ps.c 8 Aug 2018 14:38:31 -   1.72
+++ bin/ps/ps.c 10 Sep 2018 00:46:49 -
@@ -92,7 +92,6 @@ main(int argc, char *argv[])
struct kinfo_proc *kp, **kinfo;
struct varent *vent;
struct winsize ws;
-   struct passwd *pwd;
dev_t ttydev;
pid_t pid;
uid_t uid;
@@ -217,11 +216,8 @@ main(int argc, char *argv[])
break;
}
case 'U':
-   pwd = getpwnam(optarg);
-   if (pwd == NULL)
+   if (uid_from_user(optarg, ) == -1)
errx(1, "%s: no such user", optarg);
-   uid = pwd->pw_uid;
-   endpwent();
Uflag = xflg = 1;
break;
case 'u':
Index: sbin/fsck_ext2fs/inode.c
===
RCS file: /cvs/src/sbin/fsck_ext2fs/inode.c,v
retrieving revision 1.27
diff -u -p -u -r1.27 inode.c
--- sbin/fsck_ext2fs/inode.c16 Dec 2016 17:44:59 -  1.27
+++ sbin/fsck_ext2fs/inode.c10 Sep 2018 00:46:49 -
@@ -559,10 +559,7 @@ void
 pinode(ino_t ino)
 {
struct ext2fs_dinode *dp;
-   char *p;
-#ifndef SMALL
-   struct passwd *pw;
-#endif
+   const char *p;
time_t t;
u_int32_t uid;
 
@@ -573,11 +570,11 @@ pinode(ino_t ino)
printf(" OWNER=");
uid = letoh16(dp->e2di_uid_low) | (letoh16(dp->e2di_uid_high) << 16);
 #ifndef SMALL
-   if ((pw = getpwuid((int)uid)) != 0)
-   printf("%s ", pw->pw_name);
+   if ((p = user_from_uid(uid, 1)) != NULL)
+   printf("%s ", p);
else
 #endif
-   printf("%u ", (unsigned)uid);
+   printf("%u ", uid);
printf("MODE=%o\n", letoh16(dp->e2di_mode));
if (preen)
printf("%s: ", cdevname());
Index: sbin/fsck_ffs/inode.c
===
RCS file: /cvs/src/sbin/fsck_ffs/inode.c,v
retrieving revision 1.48
diff -u -p -u -r1.48 inode.c
--- sbin/fsck_ffs/inode.c   16 Dec 2016 17:44:59 -  1.48
+++ sbin/fsck_ffs/inode.c   10 Sep 2018 00:46:49 -
@@ -525,10 +525,7 @@ void
 pinode(ino_t ino)
 {
union dinode *dp;
-   char *p;
-#ifndef SMALL
-   struct passwd *pw;
-#endif
+   const char *p;
time_t t;
 
printf(" I=%llu ", (unsigned long long)ino);
@@ 

add uid_from_user/gid_from_group [2/3]

2018-09-10 Thread Todd C. Miller
This removes cache.c from pax in favor of using the new uid_from_user()
and gid_from_group() functions in libc.  I've added explicit calls
to setpassent() and setgroupent() since they are no longer implicitly
called.

 - todd

Index: bin/pax/Makefile
===
RCS file: /cvs/src/bin/pax/Makefile,v
retrieving revision 1.12
diff -u -p -u -r1.12 Makefile
--- bin/pax/Makefile23 Aug 2016 06:00:28 -  1.12
+++ bin/pax/Makefile10 Sep 2018 00:46:52 -
@@ -2,7 +2,7 @@
 
 WARNINGS=Yes
 PROG=   pax
-SRCS=  ar_io.c ar_subs.c buf_subs.c cache.c cpio.c file_subs.c ftree.c\
+SRCS=  ar_io.c ar_subs.c buf_subs.c cpio.c file_subs.c ftree.c\
gen_subs.c getoldopt.c options.c pat_rep.c pax.c sel_subs.c tables.c\
tar.c tty_subs.c
 MAN=   pax.1 tar.1 cpio.1
Index: bin/pax/cache.c
===
RCS file: bin/pax/cache.c
diff -N bin/pax/cache.c
--- bin/pax/cache.c 26 Aug 2016 04:08:18 -  1.23
+++ /dev/null   1 Jan 1970 00:00:00 -
@@ -1,267 +0,0 @@
-/* $OpenBSD: cache.c,v 1.23 2016/08/26 04:08:18 guenther Exp $ */
-/* $NetBSD: cache.c,v 1.4 1995/03/21 09:07:10 cgd Exp $*/
-
-/*-
- * Copyright (c) 1992 Keith Muller.
- * Copyright (c) 1992, 1993
- * The Regents of the University of California.  All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Keith Muller of the University of California, San Diego.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *notice, this list of conditions and the following disclaimer in the
- *documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- *may be used to endorse or promote products derived from this software
- *without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-
-#include "pax.h"
-#include "extern.h"
-
-/*
- * Constants and data structures used to implement group and password file
- * caches. Traditional passwd/group cache routines perform quite poorly with
- * archives. The chances of hitting a valid lookup with an archive is quite a
- * bit worse than with files already resident on the file system. These misses
- * create a MAJOR performance cost. To address this problem, these routines
- * cache both hits and misses.
- *
- * NOTE:  name lengths must be as large as those stored in ANY PROTOCOL and
- * as stored in the passwd and group files. CACHE SIZES MUST BE PRIME
- */
-#define UNMLEN 32  /* >= user name found in any protocol */
-#define GNMLEN 32  /* >= group name found in any protocol */
-#define UNM_SZ 317 /* size of uid_name() cache */
-#define GNM_SZ 317 /* size of gid_name() cache */
-#define VALID  1   /* entry and name are valid */
-#define INVALID2   /* entry valid, name NOT valid */
-
-/*
- * Node structures used in the user, group, uid, and gid caches.
- */
-
-typedef struct uidc {
-   int valid;  /* is this a valid or a miss entry */
-   char name[UNMLEN];  /* uid name */
-   uid_t uid;  /* cached uid */
-} UIDC;
-
-typedef struct gidc {
-   int valid;  /* is this a valid or a miss entry */
-   char name[GNMLEN];  /* gid name */
-   gid_t gid;  /* cached gid */
-} GIDC;
-
-
-/*
- * routines that control user, group, uid and gid caches (for the archive
- * member print routine).
- * IMPORTANT:
- * these routines cache BOTH hits and misses, a major performance improvement
- */
-
-static int pwopn = 0;  /* is password file open */
-static int gropn = 0;  /* is group file open */
-static UIDC **usrtb = NULL;/* user 

add uid_from_user/gid_from_group [1/3]

2018-09-10 Thread Todd C. Miller
This is a port of uid_from_user() and gid_from_group() from NetBSD
(also present in FreeBSD).  I did not port the pwcache_userdb() and
pwcache_groupdb() functions which we have no use for.

This is basically just the contents pax's cache.c moved to libc.
It replaces the existing pwcache.c functions user_from_uid(3) and
group_from_gid(3).  The pax-derived version does not have a limit
to the size of the hash table.

Unlike the Net/Free version, this does not call setpassent(3) or
setgroupent(3) directly.  If you want to keep the passwd or group
files open you need to call those directly.  This is consistent
with rev 1.10 of pwcache.c.

The new functions can be used to speed up repeated user -> uid
lookups in mtree, newsyslog and others.  Those diffs will be sent
separately.

 - todd

Index: include/pwd.h
===
RCS file: /cvs/src/include/pwd.h,v
retrieving revision 1.25
diff -u -p -u -r1.25 pwd.h
--- include/pwd.h   9 Mar 2017 10:13:03 -   1.25
+++ include/pwd.h   10 Sep 2018 00:46:44 -
@@ -106,7 +106,8 @@ void endpwent(void);
 #endif
 #if __BSD_VISIBLE
 int setpassent(int);
-char   *user_from_uid(uid_t, int);
+int uid_from_user(const char *, uid_t *);
+const char *user_from_uid(uid_t, int);
 char   *bcrypt_gensalt(u_int8_t);
 char   *bcrypt(const char *, const char *);
 intbcrypt_newhash(const char *, int, char *, size_t);
Index: include/grp.h
===
RCS file: /cvs/src/include/grp.h,v
retrieving revision 1.12
diff -u -p -u -r1.12 grp.h
--- include/grp.h   31 Aug 2014 04:04:38 -  1.12
+++ include/grp.h   10 Sep 2018 00:46:44 -
@@ -70,7 +70,8 @@ intgetgrnam_r(const char *, struct gr
 #endif
 #if __BSD_VISIBLE
 int setgroupent(int);
-char   *group_from_gid(gid_t, int);
+int gid_from_group(const char *, gid_t *);
+const char *group_from_gid(gid_t, int);
 #endif
 __END_DECLS
 
Index: lib/libc/gen/pwcache.3
===
RCS file: /cvs/src/lib/libc/gen/pwcache.3,v
retrieving revision 1.13
diff -u -p -u -r1.13 pwcache.3
--- lib/libc/gen/pwcache.3  26 Mar 2016 14:36:37 -  1.13
+++ lib/libc/gen/pwcache.3  10 Sep 2018 00:46:44 -
@@ -32,14 +32,20 @@
 .Os
 .Sh NAME
 .Nm user_from_uid ,
+.Nm uid_from_user ,
 .Nm group_from_gid
+.Nm gid_from_group
 .Nd cache password and group entries
 .Sh SYNOPSIS
-.In grp.h
 .In pwd.h
-.Ft char *
+.Ft int
+.Fn uid_from_user "const char *name" "uid_t *uid"
+.Ft const char *
 .Fn user_from_uid "uid_t uid" "int nouser"
-.Ft char *
+.In grp.h
+.Ft int
+.Fn gid_from_group "const char *name" "gid_t *gid"
+.Ft const char *
 .Fn group_from_gid "gid_t gid" "int nogroup"
 .Sh DESCRIPTION
 The
@@ -60,6 +66,22 @@ unless the argument
 is non-zero, in which case a null pointer is returned.
 .Pp
 The
+.Fn uid_from_user
+function returns the uid associated with the argument
+.Fa name .
+The uid is cached so that multiple calls with the same
+.Fa name
+do not require additional calls to
+.Xr getpwnam 3 .
+If there is no uid associated with the
+.Fa name ,
+the
+.Fn uid_from_user
+function returns -1; otherwise it stores the uid at the location pointed to by
+.Fa uid
+and returns 0.
+.Pp
+The
 .Fn group_from_gid
 function returns the group name associated with the argument
 .Fa gid .
@@ -75,6 +97,22 @@ to a string representation of the
 unless the argument
 .Fa nogroup
 is non-zero, in which case a null pointer is returned.
+.Pp
+The
+.Fn gid_from_group
+function returns the gid associated with the argument
+.Fa name .
+The gid is cached so that multiple calls with the same
+.Fa name
+do not require additional calls to
+.Xr getgrnam 3 .
+If there is no gid associated with the
+.Fa name ,
+the
+.Fn gid_from_group
+function returns -1; otherwise it stores the gid at the location pointed to by
+.Fa gid
+and returns 0.
 .Sh SEE ALSO
 .Xr getgrgid 3 ,
 .Xr getpwuid 3
@@ -85,3 +123,12 @@ and
 .Fn group_from_gid
 functions first appeared in
 .Bx 4.4 .
+.Pp
+The
+.Fn uid_from_user
+and
+.Fn gid_from_group
+functions were ported from
+.Nx
+and first appeared in
+.Ox 6.4 .
Index: lib/libc/gen/pwcache.c
===
RCS file: /cvs/src/lib/libc/gen/pwcache.c,v
retrieving revision 1.13
diff -u -p -u -r1.13 pwcache.c
--- lib/libc/gen/pwcache.c  25 Nov 2015 23:16:01 -  1.13
+++ lib/libc/gen/pwcache.c  10 Sep 2018 15:04:35 -
@@ -1,8 +1,13 @@
-/* $OpenBSD: pwcache.c,v 1.13 2015/11/25 23:16:01 jcs Exp $ */
-/*
- * Copyright (c) 1989, 1993
+/* $OpenBSD: pwcache.c,v 1.13 2015/11/25 23:16:01 jcs Exp $*/
+
+/*-
+ * Copyright (c) 1992 Keith Muller.
+ * Copyright (c) 1992, 1993
  * The Regents of the University of California.  All rights reserved.
  *
+ * This code is 

Re: pfctl: merge host_v{4,6}() into simpler host_ip()

2018-09-10 Thread Klemens Nanni
On Mon, Sep 10, 2018 at 12:46:22AM +0200, Klemens Nanni wrote:
> Reduce duplicate code, make similar paths such as the memcpy() calls
> more uniform to simplify upcoming diffs and tidy up a bit.
Updated version that

* has copy_satoaddr() instead of mempcy()
* fills the node_host struct directly from inet_net_pton() without the
  need for an extra in_addr on the stack

OK?

Index: pfctl_parser.c
===
RCS file: /cvs/src/sbin/pfctl/pfctl_parser.c,v
retrieving revision 1.333
diff -u -p -r1.333 pfctl_parser.c
--- pfctl_parser.c  10 Sep 2018 16:17:48 -  1.333
+++ pfctl_parser.c  10 Sep 2018 16:30:36 -
@@ -75,8 +75,7 @@ intifa_skip_if(const char *filter, st
 
 struct node_host   *ifa_grouplookup(const char *, int);
 struct node_host   *host_if(const char *, int);
-struct node_host   *host_v4(const char *, int);
-struct node_host   *host_v6(const char *, int);
+struct node_host   *host_ip(const char *, int);
 struct node_host   *host_dns(const char *, int, int);
 
 const char *tcpflags = "FSRPAUEW";
@@ -1637,8 +1636,7 @@ host(const char *s, int opts)
r = ps;
 
if ((h = host_if(ps, mask)) == NULL &&
-   (h = host_v4(r, mask)) == NULL &&
-   (h = host_v6(ps, mask)) == NULL &&
+   (h = host_ip(ps, mask)) == NULL &&
(h = host_dns(ps, mask, (opts & PF_OPT_NODNS))) == NULL) {
fprintf(stderr, "no IP address found for %s\n", s);
goto error;
@@ -1705,57 +1703,42 @@ error:
 }
 
 struct node_host *
-host_v4(const char *s, int mask)
-{
-   struct node_host*h = NULL;
-   struct in_addr   ina;
-
-   memset(, 0, sizeof(ina));
-   if (mask > -1) {
-   if (inet_net_pton(AF_INET, s, , sizeof(ina)) == -1)
-   return (NULL);
-   } else {
-   if (inet_pton(AF_INET, s, ) != 1)
-   return (NULL);
-   }
-
-   h = calloc(1, sizeof(struct node_host));
-   if (h == NULL)
-   err(1, "address: calloc");
-   h->ifname = NULL;
-   h->af = AF_INET;
-   h->addr.v.a.addr.addr32[0] = ina.s_addr;
-   set_ipmask(h, mask);
-   h->next = NULL;
-   h->tail = h;
-
-   return (h);
-}
-
-struct node_host *
-host_v6(const char *s, int mask)
+host_ip(const char *s, int mask)
 {
struct addrinfo  hints, *res;
struct node_host*h = NULL;
 
memset(, 0, sizeof(hints));
-   hints.ai_family = AF_INET6;
+   hints.ai_family = AF_UNSPEC;
hints.ai_socktype = SOCK_DGRAM; /*dummy*/
hints.ai_flags = AI_NUMERICHOST;
-   if (getaddrinfo(s, "0", , ) == 0) {
-   h = calloc(1, sizeof(struct node_host));
+   if (getaddrinfo(s, NULL, , ) == 0) {
+   h = calloc(1, sizeof(*h));
if (h == NULL)
-   err(1, "address: calloc");
-   h->ifname = NULL;
-   h->af = AF_INET6;
+   err(1, "%s: calloc", __func__);
+   h->af = res->ai_family;
copy_satopfaddr(>addr.v.a.addr, res->ai_addr);
-   h->ifindex =
-   ((struct sockaddr_in6 *)res->ai_addr)->sin6_scope_id;
-   set_ipmask(h, mask);
+   if (h->af == AF_INET6)
+   h->ifindex =
+   ((struct sockaddr_in6 
*)res->ai_addr)->sin6_scope_id;
freeaddrinfo(res);
-   h->next = NULL;
-   h->tail = h;
+   } else {/* ie. for 10/8 parsing */
+   if (mask == -1)
+   return (NULL);
+   h = calloc(1, sizeof(*h));
+   if (h == NULL)
+   err(1, "%s: calloc", __func__);
+   h->af = AF_INET;
+   if (inet_net_pton(AF_INET, s, >addr.v.a.addr.v4,
+   sizeof(h->addr.v.a.addr.v4)) == -1) {
+   free(h);
+   return (NULL);
+   }
}
+   set_ipmask(h, mask);
+   h->ifname = NULL;
+   h->next = NULL;
+   h->tail = h;
 
return (h);
 }



Re: pfctl: introduce copy_satopfaddr()

2018-09-10 Thread Alexandr Nedvedicky
On Mon, Sep 10, 2018 at 06:01:05PM +0200, Alexander Bluhm wrote:
> On Mon, Sep 10, 2018 at 05:52:43PM +0200, Klemens Nanni wrote:
> > On Mon, Sep 10, 2018 at 05:41:56PM +0200, Alexander Bluhm wrote:
> > > I would prefer to access pfa.v6 than to rely on the fact that pf_addr
> > > contains a union as the first field.  And the memcpy() is eqivalent
> > > to the following assignment as both structures are aligned.
> > > 
> > >   pfa.v6 = ((struct sockaddr_in6 *)sa)->sin6_addr;
> > Agreed, except `pfa' is a pointer so rather `pfa->v6'.
> > 
> > Works expected, OK with that?
> 
> OK bluhm@
> 

either way (memcpy() vs. bluhm's suggestion) is OK with me.

sashan@



Re: switchd(8) stdio /dev/null

2018-09-10 Thread Klemens Nanni
On Mon, Sep 10, 2018 at 02:37:07AM -0700, Ayaka Koshibe wrote:
> Mirroring bluhm's fixes for proc.c daemons to dup /dev/null for child
> processes, for switchd(8).
OK kn



Re: pfctl: introduce copy_satopfaddr()

2018-09-10 Thread Alexander Bluhm
On Mon, Sep 10, 2018 at 05:52:43PM +0200, Klemens Nanni wrote:
> On Mon, Sep 10, 2018 at 05:41:56PM +0200, Alexander Bluhm wrote:
> > I would prefer to access pfa.v6 than to rely on the fact that pf_addr
> > contains a union as the first field.  And the memcpy() is eqivalent
> > to the following assignment as both structures are aligned.
> > 
> > pfa.v6 = ((struct sockaddr_in6 *)sa)->sin6_addr;
> Agreed, except `pfa' is a pointer so rather `pfa->v6'.
> 
> Works expected, OK with that?

OK bluhm@



Re: pfctl: introduce copy_satopfaddr()

2018-09-10 Thread Klemens Nanni
On Mon, Sep 10, 2018 at 05:41:56PM +0200, Alexander Bluhm wrote:
> I would prefer to access pfa.v6 than to rely on the fact that pf_addr
> contains a union as the first field.  And the memcpy() is eqivalent
> to the following assignment as both structures are aligned.
> 
>   pfa.v6 = ((struct sockaddr_in6 *)sa)->sin6_addr;
Agreed, except `pfa' is a pointer so rather `pfa->v6'.

Works expected, OK with that?



Re: pfctl: introduce copy_satopfaddr()

2018-09-10 Thread Alexander Bluhm
On Mon, Sep 10, 2018 at 05:24:04PM +0200, Klemens Nanni wrote:
> If you find a bug in this diff, dinner is on me.

unfortunately no bug found, just remarks

> +void
> +copy_satopfaddr(struct pf_addr *pfa, struct sockaddr *sa)
> +{
> + if (sa->sa_family == AF_INET6)
> + memcpy(pfa, &((struct sockaddr_in6 *)sa)->sin6_addr.s6_addr,
> + sizeof(struct in6_addr));

I would prefer to access pfa.v6 than to rely on the fact that pf_addr
contains a union as the first field.  And the memcpy() is eqivalent
to the following assignment as both structures are aligned.

pfa.v6 = ((struct sockaddr_in6 *)sa)->sin6_addr;


> + else
> + memcpy(pfa, &((struct sockaddr_in *)sa)->sin_addr.s_addr,
> + sizeof(struct in_addr));

pfa.v4 = ((struct sockaddr_in *)sa)->sin_addr;

bluhm



calculate packet header length

2018-09-10 Thread Alexander Bluhm
Hi,

Instead of calculating the mbuf packet header length here and there,
put the algorithm in a function m_calchdrlen().

ok?

bluhm

Index: share/man/man9/mbuf.9
===
RCS file: /data/mirror/openbsd/cvs/src/share/man/man9/mbuf.9,v
retrieving revision 1.112
diff -u -p -r1.112 mbuf.9
--- share/man/man9/mbuf.9   10 Sep 2018 12:47:02 -  1.112
+++ share/man/man9/mbuf.9   10 Sep 2018 13:36:24 -
@@ -37,6 +37,7 @@
 .Nm m_gethdr ,
 .Nm m_removehdr ,
 .Nm m_resethdr ,
+.Nm m_calchdrlen ,
 .Nm MGETHDR ,
 .Nm m_prepend ,
 .Nm M_PREPEND ,
@@ -83,6 +84,8 @@
 .Fn m_removehdr "struct mbuf *m"
 .Ft void
 .Fn m_resethdr "struct mbuf *m"
+.Ft void
+.Fn m_calchdrlen "struct mbuf *m"
 .Ft struct mbuf *
 .Fn m_gethdr "int how" "int type"
 .Fn MGETHDR "struct mbuf *m" "int how" "int type"
@@ -502,6 +505,9 @@ Delete all
 data and all tags attached to a
 .Fa mbuf .
 Keep the data and mbuf chain, initialize the packet header.
+.It Fn m_calchdrlen "struct mbuf *m"
+Set the packet header length to the sum of all length values in the
+mbuf chain.
 .It Fn m_gethdr "int how" "int type"
 Return a pointer to an mbuf of the type specified after initializing
 it to contain a packet header.
Index: sys/kern/uipc_mbuf.c
===
RCS file: /data/mirror/openbsd/cvs/src/sys/kern/uipc_mbuf.c,v
retrieving revision 1.257
diff -u -p -r1.257 uipc_mbuf.c
--- sys/kern/uipc_mbuf.c10 Sep 2018 12:47:02 -  1.257
+++ sys/kern/uipc_mbuf.c10 Sep 2018 12:58:58 -
@@ -327,6 +327,18 @@ m_resethdr(struct mbuf *m)
m->m_pkthdr.ph_loopcnt = loopcnt;
 }
 
+void
+m_calchdrlen(struct mbuf *m)
+{
+   struct mbuf *n;
+   int plen = 0;
+
+   KASSERT(m->m_flags & M_PKTHDR);
+   for (n = m; n; n = n->m_next)
+   plen += n->m_len;
+   m->m_pkthdr.len = plen;
+}
+
 struct mbuf *
 m_getclr(int nowait, int type)
 {
Index: sys/net/pf_norm.c
===
RCS file: /data/mirror/openbsd/cvs/src/sys/net/pf_norm.c,v
retrieving revision 1.215
diff -u -p -r1.215 pf_norm.c
--- sys/net/pf_norm.c   10 Sep 2018 12:47:02 -  1.215
+++ sys/net/pf_norm.c   10 Sep 2018 13:11:47 -
@@ -805,16 +805,7 @@ pf_reassemble(struct mbuf **m0, int dir,
hdrlen = frent->fe_hdrlen;
m = *m0 = pf_join_fragment(frag);
frag = NULL;
-
-   {
-   int plen = 0;
-
-   KASSERT(m->m_flags & M_PKTHDR);
-   for (m = *m0; m; m = m->m_next)
-   plen += m->m_len;
-   m = *m0;
-   m->m_pkthdr.len = plen;
-   }
+   m_calchdrlen(m);
 
ip = mtod(m, struct ip *);
ip->ip_len = htons(hdrlen + total);
@@ -907,15 +898,7 @@ pf_reassemble6(struct mbuf **m0, struct 
if (frag6_deletefraghdr(m, hdrlen) != 0)
goto fail;
 
-   {
-   int plen = 0;
-
-   KASSERT(m->m_flags & M_PKTHDR);
-   for (m = *m0; m; m = m->m_next)
-   plen += m->m_len;
-   m = *m0;
-   m->m_pkthdr.len = plen;
-   }
+   m_calchdrlen(m);
 
if ((mtag = m_tag_get(PACKET_TAG_PF_REASSEMBLED, sizeof(struct
pf_fragment_tag), M_NOWAIT)) == NULL)
Index: sys/netinet/ip_input.c
===
RCS file: /data/mirror/openbsd/cvs/src/sys/netinet/ip_input.c,v
retrieving revision 1.339
diff -u -p -r1.339 ip_input.c
--- sys/netinet/ip_input.c  10 Sep 2018 12:47:02 -  1.339
+++ sys/netinet/ip_input.c  10 Sep 2018 13:11:09 -
@@ -964,14 +964,7 @@ insert:
pool_put(_pool, fp);
m->m_len += (ip->ip_hl << 2);
m->m_data -= (ip->ip_hl << 2);
-   {
-   int plen = 0;
-
-   KASSERT(m->m_flags & M_PKTHDR);
-   for (t = m; t; t = t->m_next)
-   plen += t->m_len;
-   m->m_pkthdr.len = plen;
-   }
+   m_calchdrlen(m);
return (m);
 
 dropfrag:
Index: sys/netinet6/frag6.c
===
RCS file: /data/mirror/openbsd/cvs/src/sys/netinet6/frag6.c,v
retrieving revision 1.84
diff -u -p -r1.84 frag6.c
--- sys/netinet6/frag6.c10 Sep 2018 12:47:02 -  1.84
+++ sys/netinet6/frag6.c10 Sep 2018 13:11:07 -
@@ -431,14 +431,7 @@ frag6_input(struct mbuf **mp, int *offp,
 
pool_put(_pool, q6);
 
-   {
-   int plen = 0;
-
-   KASSERT(m->m_flags & M_PKTHDR);
-   for (t = m; t; t = t->m_next)
-   plen += t->m_len;
-   m->m_pkthdr.len = plen;
-   }
+   m_calchdrlen(m);
 
/*
 * Restore NXT to the original.
Index: sys/nfs/krpc_subr.c
===
RCS file: 

Re: pfctl: introduce copy_satopfaddr()

2018-09-10 Thread Klemens Nanni
On Mon, Sep 10, 2018 at 01:23:32PM +0200, Alexander Bluhm wrote:
> Can we call it copy_satopfaddr() so we know what is copied to where?
Sure.

> Could we use sa->sa_family?  Then we do not have to pass an additional
> parameter.
Even better.
My first diff passed a `struct node_host *' argument so I could use
`n->af'; after changing that I didn't think of the obvious fact that
`sockaddr' carries the same information.

> > +   //copy_sa(n->af, >addr.v.a.mask, ifa->ifa_netmask);
> 
> And why do you have a comment here?
Because I was sloppy (again) sending out the wrong diff before leaving
for lunch, pardon me.

If you find a bug in this diff, dinner is on me.

Index: pfctl_parser.c
===
RCS file: /cvs/src/sbin/pfctl/pfctl_parser.c,v
retrieving revision 1.332
diff -u -p -r1.332 pfctl_parser.c
--- pfctl_parser.c  7 Sep 2018 21:37:03 -   1.332
+++ pfctl_parser.c  10 Sep 2018 15:20:29 -
@@ -62,6 +62,7 @@
 #include "pfctl_parser.h"
 #include "pfctl.h"
 
+voidcopy_satopfaddr(struct pf_addr *, struct sockaddr *);
 voidprint_op (u_int8_t, const char *, const char *);
 voidprint_port (u_int8_t, u_int16_t, u_int16_t, const char *, int);
 voidprint_ugid (u_int8_t, unsigned, unsigned, const char *, 
unsigned);
@@ -211,6 +212,17 @@ const struct pf_timeout pf_timeouts[] = 
 
 enum { PF_POOL_ROUTE, PF_POOL_NAT, PF_POOL_RDR };
 
+void
+copy_satopfaddr(struct pf_addr *pfa, struct sockaddr *sa)
+{
+   if (sa->sa_family == AF_INET6)
+   memcpy(pfa, &((struct sockaddr_in6 *)sa)->sin6_addr.s6_addr,
+   sizeof(struct in6_addr));
+   else
+   memcpy(pfa, &((struct sockaddr_in *)sa)->sin_addr.s_addr,
+   sizeof(struct in_addr));
+}
+
 const struct icmptypeent *
 geticmptypebynumber(u_int8_t type, sa_family_t af)
 {
@@ -1371,41 +1383,19 @@ ifa_load(void)
}
 #endif
n->ifindex = 0;
-   if (n->af == AF_INET) {
-   memcpy(>addr.v.a.addr, &((struct sockaddr_in *)
-   ifa->ifa_addr)->sin_addr.s_addr,
-   sizeof(struct in_addr));
-   memcpy(>addr.v.a.mask, &((struct sockaddr_in *)
-   ifa->ifa_netmask)->sin_addr.s_addr,
-   sizeof(struct in_addr));
-   if (ifa->ifa_broadaddr != NULL)
-   memcpy(>bcast, &((struct sockaddr_in *)
-   ifa->ifa_broadaddr)->sin_addr.s_addr,
-   sizeof(struct in_addr));
-   if (ifa->ifa_dstaddr != NULL)
-   memcpy(>peer, &((struct sockaddr_in *)
-   ifa->ifa_dstaddr)->sin_addr.s_addr,
-   sizeof(struct in_addr));
-   } else if (n->af == AF_INET6) {
-   memcpy(>addr.v.a.addr, &((struct sockaddr_in6 *)
-   ifa->ifa_addr)->sin6_addr.s6_addr,
-   sizeof(struct in6_addr));
-   memcpy(>addr.v.a.mask, &((struct sockaddr_in6 *)
-   ifa->ifa_netmask)->sin6_addr.s6_addr,
-   sizeof(struct in6_addr));
-   if (ifa->ifa_broadaddr != NULL)
-   memcpy(>bcast, &((struct sockaddr_in6 *)
-   ifa->ifa_broadaddr)->sin6_addr.s6_addr,
-   sizeof(struct in6_addr));
-   if (ifa->ifa_dstaddr != NULL)
-memcpy(>peer, &((struct sockaddr_in6 *)
-   ifa->ifa_dstaddr)->sin6_addr.s6_addr,
-   sizeof(struct in6_addr));
-   n->ifindex = ((struct sockaddr_in6 *)
-   ifa->ifa_addr)->sin6_scope_id;
-   } else if (n->af == AF_LINK) {
+   if (n->af == AF_LINK)
n->ifindex = ((struct sockaddr_dl *)
ifa->ifa_addr)->sdl_index;
+   else {
+   copy_satopfaddr(>addr.v.a.addr, ifa->ifa_addr);
+   copy_satopfaddr(>addr.v.a.mask, ifa->ifa_netmask);
+   if (ifa->ifa_broadaddr != NULL)
+   copy_satopfaddr(>bcast, ifa->ifa_broadaddr);
+   if (ifa->ifa_dstaddr != NULL)
+   copy_satopfaddr(>peer, ifa->ifa_dstaddr);
+   if (n->af == AF_INET6)
+   n->ifindex = ((struct sockaddr_in6 *)
+   ifa->ifa_addr)->sin6_scope_id;
}
if ((n->ifname = strdup(ifa->ifa_name)) == NULL)
err(1, "%s: strdup", __func__);

Re: vmd stdio /dev/null

2018-09-10 Thread Ayaka Koshibe
On Mon, Sep 10, 2018 at 01:48:23PM +0200, Alexander Bluhm wrote:
> On Mon, Sep 10, 2018 at 09:59:31AM +0200, Reyk Floeter wrote:
> > I already gave my OK for relayd but asked to adjust all proc.c instances.
> 
> I have fixed relayd, httpd, vmd.
> akoshibe@ cares about switchd.

switchd is also now fixed.

> Could someone who uses snmpd apply the fix and test it?
> 
> lpd/proc.c looks differently and seems to be unaffected.
> 
> bluhm
> 



Re: vmd stdio /dev/null

2018-09-10 Thread Alexander Bluhm
On Mon, Sep 10, 2018 at 09:59:31AM +0200, Reyk Floeter wrote:
> I already gave my OK for relayd but asked to adjust all proc.c instances.

I have fixed relayd, httpd, vmd.
akoshibe@ cares about switchd.

Could someone who uses snmpd apply the fix and test it?

lpd/proc.c looks differently and seems to be unaffected.

bluhm



Re: pfctl: introduce copy_sa()

2018-09-10 Thread Alexander Bluhm
On Mon, Sep 10, 2018 at 01:10:29PM +0200, Klemens Nanni wrote:
> +void
> +copy_sa(int af, struct pf_addr *pfa, struct sockaddr *sa)

Can we call it copy_satopfaddr() so we know what is copied to where?

> +{
> + if (af == AF_INET6) 

Could we use sa->sa_family?  Then we do not have to pass an additional
parameter.

> + //copy_sa(n->af, >addr.v.a.addr, ifa->ifa_addr);
> + //copy_sa(n->af, >addr.v.a.mask, ifa->ifa_netmask);

And why do you have a comment here?

bluhm



Re: pfctl: introduce copy_sa()

2018-09-10 Thread Klemens Nanni
On Mon, Sep 10, 2018 at 11:59:55AM +0200, Klemens Nanni wrote:
> Small helper to put the dance around `af' into one single location.
New diff with less cleverness^Wstupidity.

regress passes, Both IPv4 and IPV6 addresses are parsed/copied correctly.

I'd like to commit this before the `host_ip()' change so that this diff
gets a tad smaller since `host_v4()' gets simplified here.

OK?

Index: pfctl_parser.c
===
RCS file: /cvs/src/sbin/pfctl/pfctl_parser.c,v
retrieving revision 1.332
diff -u -p -r1.332 pfctl_parser.c
--- pfctl_parser.c  7 Sep 2018 21:37:03 -   1.332
+++ pfctl_parser.c  10 Sep 2018 11:01:33 -
@@ -62,6 +62,7 @@
 #include "pfctl_parser.h"
 #include "pfctl.h"
 
+voidcopy_sa(int, struct pf_addr *, struct sockaddr *);
 voidprint_op (u_int8_t, const char *, const char *);
 voidprint_port (u_int8_t, u_int16_t, u_int16_t, const char *, int);
 voidprint_ugid (u_int8_t, unsigned, unsigned, const char *, 
unsigned);
@@ -211,6 +212,17 @@ const struct pf_timeout pf_timeouts[] = 
 
 enum { PF_POOL_ROUTE, PF_POOL_NAT, PF_POOL_RDR };
 
+void
+copy_sa(int af, struct pf_addr *pfa, struct sockaddr *sa)
+{
+   if (af == AF_INET6) 
+   memcpy(pfa, &((struct sockaddr_in6 *)sa)->sin6_addr.s6_addr,
+   sizeof(struct in6_addr));
+   else
+   memcpy(pfa, &((struct sockaddr_in *)sa)->sin_addr.s_addr,
+   sizeof(struct in_addr));
+}
+
 const struct icmptypeent *
 geticmptypebynumber(u_int8_t type, sa_family_t af)
 {
@@ -1371,41 +1383,19 @@ ifa_load(void)
}
 #endif
n->ifindex = 0;
-   if (n->af == AF_INET) {
-   memcpy(>addr.v.a.addr, &((struct sockaddr_in *)
-   ifa->ifa_addr)->sin_addr.s_addr,
-   sizeof(struct in_addr));
-   memcpy(>addr.v.a.mask, &((struct sockaddr_in *)
-   ifa->ifa_netmask)->sin_addr.s_addr,
-   sizeof(struct in_addr));
-   if (ifa->ifa_broadaddr != NULL)
-   memcpy(>bcast, &((struct sockaddr_in *)
-   ifa->ifa_broadaddr)->sin_addr.s_addr,
-   sizeof(struct in_addr));
-   if (ifa->ifa_dstaddr != NULL)
-   memcpy(>peer, &((struct sockaddr_in *)
-   ifa->ifa_dstaddr)->sin_addr.s_addr,
-   sizeof(struct in_addr));
-   } else if (n->af == AF_INET6) {
-   memcpy(>addr.v.a.addr, &((struct sockaddr_in6 *)
-   ifa->ifa_addr)->sin6_addr.s6_addr,
-   sizeof(struct in6_addr));
-   memcpy(>addr.v.a.mask, &((struct sockaddr_in6 *)
-   ifa->ifa_netmask)->sin6_addr.s6_addr,
-   sizeof(struct in6_addr));
-   if (ifa->ifa_broadaddr != NULL)
-   memcpy(>bcast, &((struct sockaddr_in6 *)
-   ifa->ifa_broadaddr)->sin6_addr.s6_addr,
-   sizeof(struct in6_addr));
-   if (ifa->ifa_dstaddr != NULL)
-memcpy(>peer, &((struct sockaddr_in6 *)
-   ifa->ifa_dstaddr)->sin6_addr.s6_addr,
-   sizeof(struct in6_addr));
-   n->ifindex = ((struct sockaddr_in6 *)
-   ifa->ifa_addr)->sin6_scope_id;
-   } else if (n->af == AF_LINK) {
+   if (n->af == AF_LINK)
n->ifindex = ((struct sockaddr_dl *)
ifa->ifa_addr)->sdl_index;
+   else {
+   //copy_sa(n->af, >addr.v.a.addr, ifa->ifa_addr);
+   //copy_sa(n->af, >addr.v.a.mask, ifa->ifa_netmask);
+   if (ifa->ifa_broadaddr != NULL)
+   //copy_sa(n->af, >bcast, ifa->ifa_broadaddr);
+   if (ifa->ifa_dstaddr != NULL)
+   //copy_sa(n->af, >peer, ifa->ifa_dstaddr);
+   if (n->af == AF_INET6)
+   n->ifindex = ((struct sockaddr_in6 *)
+   ifa->ifa_addr)->sin6_scope_id;
}
if ((n->ifname = strdup(ifa->ifa_name)) == NULL)
err(1, "%s: strdup", __func__);
@@ -1760,9 +1750,7 @@ host_v6(const char *s, int mask)
err(1, "address: calloc");
h->ifname = NULL;
h->af = AF_INET6;
-   memcpy(>addr.v.a.addr,
-   &((struct sockaddr_in6 *)res->ai_addr)->sin6_addr,
-  

Re: switchd(8) stdio /dev/null

2018-09-10 Thread Alexander Bluhm
On Mon, Sep 10, 2018 at 02:37:07AM -0700, Ayaka Koshibe wrote:
> Mirroring bluhm's fixes for proc.c daemons to dup /dev/null for child
> processes, for switchd(8).
> 
> OK?

OK bluhm@

> Index: proc.c
> ===
> RCS file: /cvs/src/usr.sbin/switchd/proc.c,v
> retrieving revision 1.13
> diff -u -p -u -r1.13 proc.c
> --- proc.c5 Aug 2018 08:16:24 -   1.13
> +++ proc.c10 Sep 2018 09:12:45 -
> @@ -29,13 +29,14 @@
>  #include 
>  #include 
>  #include 
> +#include 
>  #include 
>  #include 
>  #include 
>  
>  #include "proc.h"
>  
> -void  proc_exec(struct privsep *, struct privsep_proc *, unsigned int,
> +void  proc_exec(struct privsep *, struct privsep_proc *, unsigned int, int,
>   int, char **);
>  void  proc_setup(struct privsep *, struct privsep_proc *, unsigned int);
>  void  proc_open(struct privsep *, int, int);
> @@ -80,7 +81,7 @@ proc_getid(struct privsep_proc *procs, u
>  
>  void
>  proc_exec(struct privsep *ps, struct privsep_proc *procs, unsigned int nproc,
> -int argc, char **argv)
> +int debug, int argc, char **argv)
>  {
>   unsigned int proc, nargc, i, proc_i;
>   char**nargv;
> @@ -141,6 +142,16 @@ proc_exec(struct privsep *ps, struct pri
>   } else if (fcntl(fd, F_SETFD, 0) == -1)
>   fatal("fcntl");
>  
> + /* Daemons detach from terminal. */
> + if (!debug && (fd =
> + open(_PATH_DEVNULL, O_RDWR, 0)) != -1) {
> + (void)dup2(fd, STDIN_FILENO);
> + (void)dup2(fd, STDOUT_FILENO);
> + (void)dup2(fd, STDERR_FILENO);
> + if (fd > 2)
> + (void)close(fd);
> + }
> +
>   execvp(argv[0], nargv);
>   fatal("%s: execvp", __func__);
>   break;
> @@ -191,7 +202,7 @@ proc_connect(struct privsep *ps)
>  
>  void
>  proc_init(struct privsep *ps, struct privsep_proc *procs, unsigned int nproc,
> -int argc, char **argv, enum privsep_procid proc_id)
> +int debug, int argc, char **argv, enum privsep_procid proc_id)
>  {
>   struct privsep_proc *p = NULL;
>   struct privsep_pipes*pa, *pb;
> @@ -231,7 +242,7 @@ proc_init(struct privsep *ps, struct pri
>   }
>  
>   /* Engage! */
> - proc_exec(ps, procs, nproc, argc, argv);
> + proc_exec(ps, procs, nproc, debug, argc, argv);
>   return;
>   }
>  
> Index: proc.h
> ===
> RCS file: /cvs/src/usr.sbin/switchd/proc.h,v
> retrieving revision 1.7
> diff -u -p -u -r1.7 proc.h
> --- proc.h5 Aug 2018 08:16:24 -   1.7
> +++ proc.h10 Sep 2018 09:12:45 -
> @@ -126,7 +126,7 @@ TAILQ_HEAD(ctl_connlist, ctl_conn);
>  extern  struct ctl_connlist ctl_conns;
>  
>  /* proc.c */
> -void  proc_init(struct privsep *, struct privsep_proc *, unsigned int,
> +void  proc_init(struct privsep *, struct privsep_proc *, unsigned int, int,
>   int, char **, enum privsep_procid);
>  void  proc_kill(struct privsep *);
>  void  proc_connect(struct privsep *ps);
> Index: switchd.c
> ===
> RCS file: /cvs/src/usr.sbin/switchd/switchd.c,v
> retrieving revision 1.15
> diff -u -p -u -r1.15 switchd.c
> --- switchd.c 9 Jan 2017 14:49:22 -   1.15
> +++ switchd.c 10 Sep 2018 09:12:45 -
> @@ -184,7 +184,7 @@ main(int argc, char *argv[])
>   ps->ps_title[proc_id] = title;
>  
>   /* Only the parent returns. */
> - proc_init(ps, procs, nitems(procs), argc0, argv, proc_id);
> + proc_init(ps, procs, nitems(procs), debug, argc0, argv, proc_id);
>  
>   if (!debug && daemon(0, 0) == -1)
>   fatal("failed to daemonize");



Re: pfctl: introduce copy_sa()

2018-09-10 Thread Michael Mikonos
On Mon, Sep 10, 2018 at 12:16:57PM +0200, Klemens Nanni wrote:
> On Mon, Sep 10, 2018 at 11:59:55AM +0200, Klemens Nanni wrote:
> > Small helper to put the dance around `af' into one single location.
> Wrong/bad diff, please disregard.
> 
I was just about to reply that the size in the memcpy() might always be
the same.



Re: pfctl: introduce copy_sa()

2018-09-10 Thread Klemens Nanni
On Mon, Sep 10, 2018 at 11:59:55AM +0200, Klemens Nanni wrote:
> Small helper to put the dance around `af' into one single location.
Wrong/bad diff, please disregard.



Re: pfctl: merge host_v{4,6}() into simpler host_ip()

2018-09-10 Thread Alexandr Nedvedicky
Hello,

On Mon, Sep 10, 2018 at 12:46:22AM +0200, Klemens Nanni wrote:
> Reduce duplicate code, make similar paths such as the memcpy() calls
> more uniform to simplify upcoming diffs and tidy up a bit.
> 
> Feedback? OK?


I'm OK with change.

regards
sasha



pfctl: introduce copy_sa()

2018-09-10 Thread Klemens Nanni
Small helper to put the dance around `af' into one single location.

Feedback? OK?

Index: pfctl_parser.c
===
RCS file: /cvs/src/sbin/pfctl/pfctl_parser.c,v
retrieving revision 1.332
diff -u -p -r1.332 pfctl_parser.c
--- pfctl_parser.c  7 Sep 2018 21:37:03 -   1.332
+++ pfctl_parser.c  10 Sep 2018 09:48:11 -
@@ -62,6 +62,8 @@
 #include "pfctl_parser.h"
 #include "pfctl.h"
 
+voidcopy_sa(const int, const struct pf_addr *,
+   const struct sockaddr *);
 voidprint_op (u_int8_t, const char *, const char *);
 voidprint_port (u_int8_t, u_int16_t, u_int16_t, const char *, int);
 voidprint_ugid (u_int8_t, unsigned, unsigned, const char *, 
unsigned);
@@ -211,6 +213,18 @@ const struct pf_timeout pf_timeouts[] = 
 
 enum { PF_POOL_ROUTE, PF_POOL_NAT, PF_POOL_RDR };
 
+void
+copy_sa(const int af, const struct pf_addr *pfa, const struct sockaddr *sa)
+{
+   const void *src;
+
+   if (af == AF_INET6)
+   src = &((struct sockaddr_in6 *)sa)->sin6_addr;
+   else
+   src = &((struct sockaddr_in *)sa)->sin_addr;
+   memcpy(, , sizeof(*src));
+}
+
 const struct icmptypeent *
 geticmptypebynumber(u_int8_t type, sa_family_t af)
 {
@@ -1371,41 +1385,19 @@ ifa_load(void)
}
 #endif
n->ifindex = 0;
-   if (n->af == AF_INET) {
-   memcpy(>addr.v.a.addr, &((struct sockaddr_in *)
-   ifa->ifa_addr)->sin_addr.s_addr,
-   sizeof(struct in_addr));
-   memcpy(>addr.v.a.mask, &((struct sockaddr_in *)
-   ifa->ifa_netmask)->sin_addr.s_addr,
-   sizeof(struct in_addr));
-   if (ifa->ifa_broadaddr != NULL)
-   memcpy(>bcast, &((struct sockaddr_in *)
-   ifa->ifa_broadaddr)->sin_addr.s_addr,
-   sizeof(struct in_addr));
-   if (ifa->ifa_dstaddr != NULL)
-   memcpy(>peer, &((struct sockaddr_in *)
-   ifa->ifa_dstaddr)->sin_addr.s_addr,
-   sizeof(struct in_addr));
-   } else if (n->af == AF_INET6) {
-   memcpy(>addr.v.a.addr, &((struct sockaddr_in6 *)
-   ifa->ifa_addr)->sin6_addr.s6_addr,
-   sizeof(struct in6_addr));
-   memcpy(>addr.v.a.mask, &((struct sockaddr_in6 *)
-   ifa->ifa_netmask)->sin6_addr.s6_addr,
-   sizeof(struct in6_addr));
-   if (ifa->ifa_broadaddr != NULL)
-   memcpy(>bcast, &((struct sockaddr_in6 *)
-   ifa->ifa_broadaddr)->sin6_addr.s6_addr,
-   sizeof(struct in6_addr));
-   if (ifa->ifa_dstaddr != NULL)
-memcpy(>peer, &((struct sockaddr_in6 *)
-   ifa->ifa_dstaddr)->sin6_addr.s6_addr,
-   sizeof(struct in6_addr));
-   n->ifindex = ((struct sockaddr_in6 *)
-   ifa->ifa_addr)->sin6_scope_id;
-   } else if (n->af == AF_LINK) {
+   if (n->af == AF_LINK)
n->ifindex = ((struct sockaddr_dl *)
ifa->ifa_addr)->sdl_index;
+   else {
+   copy_sa(n->af, >addr.v.a.addr, ifa->ifa_addr);
+   copy_sa(n->af, >addr.v.a.mask, ifa->ifa_netmask);
+   if (ifa->ifa_broadaddr != NULL)
+   copy_sa(n->af, >bcast, ifa->ifa_broadaddr);
+   if (ifa->ifa_dstaddr != NULL)
+   copy_sa(n->af, >peer, ifa->ifa_dstaddr);
+   if (n->af == AF_INET6)
+   n->ifindex = ((struct sockaddr_in6 *)
+   ifa->ifa_addr)->sin6_scope_id;
}
if ((n->ifname = strdup(ifa->ifa_name)) == NULL)
err(1, "%s: strdup", __func__);
@@ -1760,9 +1752,7 @@ host_v6(const char *s, int mask)
err(1, "address: calloc");
h->ifname = NULL;
h->af = AF_INET6;
-   memcpy(>addr.v.a.addr,
-   &((struct sockaddr_in6 *)res->ai_addr)->sin6_addr,
-   sizeof(h->addr.v.a.addr));
+   copy_sa(h->af, >addr.v.a.addr, res->ai_addr);
h->ifindex =
((struct sockaddr_in6 *)res->ai_addr)->sin6_scope_id;
set_ipmask(h, mask);
@@ -1816,20 +1806,11 @@ host_dns(const char *s, int mask, int nu

switchd(8) stdio /dev/null

2018-09-10 Thread Ayaka Koshibe
Hi,

Mirroring bluhm's fixes for proc.c daemons to dup /dev/null for child
processes, for switchd(8).

OK?


Thanks,
Ayaka

Index: proc.c
===
RCS file: /cvs/src/usr.sbin/switchd/proc.c,v
retrieving revision 1.13
diff -u -p -u -r1.13 proc.c
--- proc.c  5 Aug 2018 08:16:24 -   1.13
+++ proc.c  10 Sep 2018 09:12:45 -
@@ -29,13 +29,14 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
 
 #include "proc.h"
 
-voidproc_exec(struct privsep *, struct privsep_proc *, unsigned int,
+voidproc_exec(struct privsep *, struct privsep_proc *, unsigned int, int,
int, char **);
 voidproc_setup(struct privsep *, struct privsep_proc *, unsigned int);
 voidproc_open(struct privsep *, int, int);
@@ -80,7 +81,7 @@ proc_getid(struct privsep_proc *procs, u
 
 void
 proc_exec(struct privsep *ps, struct privsep_proc *procs, unsigned int nproc,
-int argc, char **argv)
+int debug, int argc, char **argv)
 {
unsigned int proc, nargc, i, proc_i;
char**nargv;
@@ -141,6 +142,16 @@ proc_exec(struct privsep *ps, struct pri
} else if (fcntl(fd, F_SETFD, 0) == -1)
fatal("fcntl");
 
+   /* Daemons detach from terminal. */
+   if (!debug && (fd =
+   open(_PATH_DEVNULL, O_RDWR, 0)) != -1) {
+   (void)dup2(fd, STDIN_FILENO);
+   (void)dup2(fd, STDOUT_FILENO);
+   (void)dup2(fd, STDERR_FILENO);
+   if (fd > 2)
+   (void)close(fd);
+   }
+
execvp(argv[0], nargv);
fatal("%s: execvp", __func__);
break;
@@ -191,7 +202,7 @@ proc_connect(struct privsep *ps)
 
 void
 proc_init(struct privsep *ps, struct privsep_proc *procs, unsigned int nproc,
-int argc, char **argv, enum privsep_procid proc_id)
+int debug, int argc, char **argv, enum privsep_procid proc_id)
 {
struct privsep_proc *p = NULL;
struct privsep_pipes*pa, *pb;
@@ -231,7 +242,7 @@ proc_init(struct privsep *ps, struct pri
}
 
/* Engage! */
-   proc_exec(ps, procs, nproc, argc, argv);
+   proc_exec(ps, procs, nproc, debug, argc, argv);
return;
}
 
Index: proc.h
===
RCS file: /cvs/src/usr.sbin/switchd/proc.h,v
retrieving revision 1.7
diff -u -p -u -r1.7 proc.h
--- proc.h  5 Aug 2018 08:16:24 -   1.7
+++ proc.h  10 Sep 2018 09:12:45 -
@@ -126,7 +126,7 @@ TAILQ_HEAD(ctl_connlist, ctl_conn);
 extern  struct ctl_connlist ctl_conns;
 
 /* proc.c */
-voidproc_init(struct privsep *, struct privsep_proc *, unsigned int,
+voidproc_init(struct privsep *, struct privsep_proc *, unsigned int, int,
int, char **, enum privsep_procid);
 voidproc_kill(struct privsep *);
 voidproc_connect(struct privsep *ps);
Index: switchd.c
===
RCS file: /cvs/src/usr.sbin/switchd/switchd.c,v
retrieving revision 1.15
diff -u -p -u -r1.15 switchd.c
--- switchd.c   9 Jan 2017 14:49:22 -   1.15
+++ switchd.c   10 Sep 2018 09:12:45 -
@@ -184,7 +184,7 @@ main(int argc, char *argv[])
ps->ps_title[proc_id] = title;
 
/* Only the parent returns. */
-   proc_init(ps, procs, nitems(procs), argc0, argv, proc_id);
+   proc_init(ps, procs, nitems(procs), debug, argc0, argv, proc_id);
 
if (!debug && daemon(0, 0) == -1)
fatal("failed to daemonize");



Re: vmd stdio /dev/null

2018-09-10 Thread Reyk Floeter
Hi,

I already gave my OK for relayd but asked to adjust all proc.c instances.

OK reyk@

> Am 09.09.2018 um 23:47 schrieb Mike Larkin :
> 
>> On Sun, Sep 09, 2018 at 11:45:07PM +0200, Alexander Bluhm wrote:
>> Hi,
>> 
>> Like the other proc.c daemons, vmd(8) children do not detach from
>> the terminal properly.
>> 
>> ok?
>> 
> 
> Reads ok to me but reyk@ should approve.
> 
>> bluhm
>> 
>> Index: src/usr.sbin/vmd/proc.c
>> ===
>> RCS file: /data/mirror/openbsd/cvs/src/usr.sbin/vmd/proc.c,v
>> retrieving revision 1.17
>> diff -u -p -r1.17 proc.c
>> --- src/usr.sbin/vmd/proc.c5 Aug 2018 08:20:54 -1.17
>> +++ src/usr.sbin/vmd/proc.c9 Sep 2018 21:26:32 -
>> @@ -29,13 +29,14 @@
>> #include 
>> #include 
>> #include 
>> +#include 
>> #include 
>> #include 
>> #include 
>> 
>> #include "proc.h"
>> 
>> -void proc_exec(struct privsep *, struct privsep_proc *, unsigned int,
>> +void proc_exec(struct privsep *, struct privsep_proc *, unsigned int, 
>> int,
>>int, char **);
>> void proc_setup(struct privsep *, struct privsep_proc *, unsigned int);
>> void proc_open(struct privsep *, int, int);
>> @@ -80,7 +81,7 @@ proc_getid(struct privsep_proc *procs, u
>> 
>> void
>> proc_exec(struct privsep *ps, struct privsep_proc *procs, unsigned int nproc,
>> -int argc, char **argv)
>> +int debug, int argc, char **argv)
>> {
>>unsigned int proc, nargc, i, proc_i;
>>char**nargv;
>> @@ -141,6 +142,16 @@ proc_exec(struct privsep *ps, struct pri
>>} else if (fcntl(fd, F_SETFD, 0) == -1)
>>fatal("fcntl");
>> 
>> +/* Daemons detach from terminal. */
>> +if (!debug && (fd =
>> +open(_PATH_DEVNULL, O_RDWR, 0)) != -1) {
>> +(void)dup2(fd, STDIN_FILENO);
>> +(void)dup2(fd, STDOUT_FILENO);
>> +(void)dup2(fd, STDERR_FILENO);
>> +if (fd > 2)
>> +(void)close(fd);
>> +}
>> +
>>execvp(argv[0], nargv);
>>fatal("%s: execvp", __func__);
>>break;
>> @@ -191,7 +202,7 @@ proc_connect(struct privsep *ps)
>> 
>> void
>> proc_init(struct privsep *ps, struct privsep_proc *procs, unsigned int nproc,
>> -int argc, char **argv, enum privsep_procid proc_id)
>> +int debug, int argc, char **argv, enum privsep_procid proc_id)
>> {
>>struct privsep_proc*p = NULL;
>>struct privsep_pipes*pa, *pb;
>> @@ -231,7 +242,7 @@ proc_init(struct privsep *ps, struct pri
>>}
>> 
>>/* Engage! */
>> -proc_exec(ps, procs, nproc, argc, argv);
>> +proc_exec(ps, procs, nproc, debug, argc, argv);
>>return;
>>}
>> 
>> Index: src/usr.sbin/vmd/proc.h
>> ===
>> RCS file: /data/mirror/openbsd/cvs/src/usr.sbin/vmd/proc.h,v
>> retrieving revision 1.15
>> diff -u -p -r1.15 proc.h
>> --- src/usr.sbin/vmd/proc.h5 Aug 2018 08:20:54 -1.15
>> +++ src/usr.sbin/vmd/proc.h9 Sep 2018 21:15:50 -
>> @@ -156,7 +156,7 @@ struct privsep_fd {
>> #define PROC_MAX_INSTANCES32
>> 
>> /* proc.c */
>> -void proc_init(struct privsep *, struct privsep_proc *, unsigned int,
>> +void proc_init(struct privsep *, struct privsep_proc *, unsigned int, 
>> int,
>>int, char **, enum privsep_procid);
>> void proc_kill(struct privsep *);
>> void proc_connect(struct privsep *ps);
>> Index: src/usr.sbin/vmd/vmd.c
>> ===
>> RCS file: /data/mirror/openbsd/cvs/src/usr.sbin/vmd/vmd.c,v
>> retrieving revision 1.98
>> diff -u -p -r1.98 vmd.c
>> --- src/usr.sbin/vmd/vmd.c15 Jul 2018 14:36:54 -1.98
>> +++ src/usr.sbin/vmd/vmd.c9 Sep 2018 21:25:57 -
>> @@ -792,7 +792,8 @@ main(int argc, char **argv)
>>ps->ps_title[proc_id] = title;
>> 
>>/* only the parent returns */
>> -proc_init(ps, procs, nitems(procs), argc0, argv, proc_id);
>> +proc_init(ps, procs, nitems(procs), env->vmd_debug, argc0, argv,
>> +proc_id);
>> 
>>log_procinit("parent");
>>if (!env->vmd_debug && daemon(0, 0) == -1)
>> 
>