Re: [patch] Skip DHCP responsefile if no interface is given

2016-12-07 Thread Matthew Martin
ping

On Sat, Nov 26, 2016 at 11:28:55PM -0600, Matthew Martin wrote:
> Don't force the user to pick an interface if the responsefile is on
> a disk.
> 
> - Matthew Martin
> 
> 
> Index: install.sub
> ===
> RCS file: /cvs/src/distrib/miniroot/install.sub,v
> retrieving revision 1.932
> diff -u -p -r1.932 install.sub
> --- install.sub   24 Nov 2016 14:35:43 -  1.932
> +++ install.sub   27 Nov 2016 05:17:01 -
> @@ -529,6 +529,7 @@ get_responsefile() {
>   while (($# > 1)); do
>   ask_which "network interface" \
>   "should be used for the initial DHCP request" 
> "$*"
> + [[ $resp == done ]] && break 2
>   isin "$resp" $* && _if=$resp && break
>   done
>   [[ -n $_if ]] && dhclient $_if || break



dev/rnd.c comment typo

2016-12-07 Thread Michael W. Bombardieri
Hi,

Two typos in comments & explicit return at end of function returning void.

I am a little confused by mixture of memset and explicit_bzero in rnd.c for
clearing data. I understand explicit_bzero is meant for clearing sensitive
data. Would it be harmful for use only explicit_bzero here?

- Michael


Index: src/sys/dev/rnd.c
===
RCS file: /cvs/src/sys/dev/rnd.c,v
retrieving revision 1.190
diff -u -p -u -r1.190 rnd.c
--- src/sys/dev/rnd.c   18 Oct 2016 13:40:59 -  1.190
+++ src/sys/dev/rnd.c   8 Dec 2016 02:22:59 -
@@ -186,7 +186,7 @@
  * distance from evenly spaced; except for the last tap, which is 1 to
  * get the twisting happening as fast as possible.
  *
- * The reultant polynomial is:
+ * The resultant polynomial is:
  *   2^POOLWORDS + 2^POOL_TAP1 + 2^POOL_TAP2 + 2^POOL_TAP3 + 2^POOL_TAP4 + 1
  */
 #define POOLWORDS  2048
@@ -363,7 +363,7 @@ add_entropy_words(const u_int32_t *buf, 
 }
 
 /*
- * Pulls entropy out of the queue and throws merges it into the pool
+ * Pulls entropy out of the queue and merges it into the pool
  * with the CRC.
  */
 /* ARGSUSED */
@@ -631,7 +631,6 @@ _rs_random_u32(u_int32_t *val)
memcpy(val, rs_buf + RSBUFSZ - rs_have, sizeof(*val));
memset(rs_buf + RSBUFSZ - rs_have, 0, sizeof(*val));
rs_have -= sizeof(*val);
-   return;
 }
 
 /* Return one word of randomness from a ChaCha20 generator */



Re: dhcrelay(8): simplify get_interface()

2016-12-07 Thread Jeremie Courreges-Anglas
Rafael Zalamena  writes:

> On Wed, Dec 07, 2016 at 05:34:05PM +0100, Rafael Zalamena wrote:
>> This diff simplifies the get_interface function and makes it more
>> straightforward, it also makes dhcrelay(8) throw a more informative error
>> message when running layer 3 mode (default) on interfaces without an
>> address.
>> 
>> I'll use this code later to be able to get_interfaces() without an IP 
>> address.
>
> I forgot to make it return NULL if no interfaces are found (e.g. invalid
> interface name) and then it started failing with a cryptic death message:
> "Can't attach interface vip1 to bpf device: Device not configured"
>
> This updated diff fix the problem.
>
> ok?

ok jca@

-- 
jca | PGP : 0x1524E7EE / 5135 92C1 AD36 5293 2BDF  DDCC 0DFA 74AE 1524 E7EE



Re: Looking for Xen blkfront driver xbf(4) tests

2016-12-07 Thread Mike Belopuhov
On Wed, Dec 07, 2016 at 19:30 +0100, Mike Belopuhov wrote:
> Hi,
> 
> I've committed today a driver for the Xen paravirtualized disk
> interface also known as Blkfront.  Despite being pretty stable
> for me so far, it's not enabled by default at the moment.
> Therefore I'm looking for additional tests on different Xen
> versions and EC2 instances to ensure robustness and performance
> of the software.
> 
> To enable the driver, uncomment the xbf line in the kernel
> config file (/sys/arch/amd64/conf/GENERIC) and re-configure and
> re-build the kernel.  The system will automatically switch all
> available wd* disks to sd* but, unless you have opted out of
> using disklabel UIDs in the /etc/fstab, there's no configuration
> tweaking required.
> 
> Please report successes and failures.  In case of a reproducible
> issue, please enable the XEN_DEBUG define in /sys/dev/pv/xenvar.h,
> rebuild you kernel and send me relevant lines from the log (copied
> from the console or /var/log/messages).
> 
> Cheers,
> Mike

Reyk has endured some EC2 breakage and helped a great deal with
debugging.  As a result there has been some critical changes after
the initial check in so please make sure that xbf.c is at 1.5.

Cheers,
Mike



Re: dhcrelay(8): clean up function prototypes

2016-12-07 Thread Jeremie Courreges-Anglas
Rafael Zalamena  writes:

> I'm implementing some features for dhcrelay and to make them fit I need
> some clean ups in the dhcrelay(8) first. This diff changes most of the
> input/output functions prototypes to take one parameter with all addresses
> instead of passing multiple parameters.
>
> Basically this will make input functions gather more information (source/
> destination MACs, source/destination IPs, source/destination ports) and
> use it in the output instead of trying to figure out this information along
> the way.
>
> With this we will be able to add IPv6 support and layer 2 relaying.

Nice. :)

[...]

> ok?

This conflicts with a diff that has been committed by patrick@, you'll
need to refresh it.

I didn't review it entirely, but please address the point below.

[...]

> Index: dhcpd.h
> ===
> RCS file: /cvs/src/usr.sbin/dhcrelay/dhcpd.h,v
> retrieving revision 1.15
> diff -u -p -r1.15 dhcpd.h
> --- dhcpd.h   7 Dec 2016 13:19:18 -   1.15
> +++ dhcpd.h   7 Dec 2016 13:44:35 -
> @@ -42,15 +42,28 @@
>  #define  SERVER_PORT 67
>  #define  CLIENT_PORT 68
>  
> +/* Maximum size of client hardware address. */
> +#define CHADDR_SIZE  16
> +
> +struct packet_ctx {
> + uint8_t  pc_htype;
> + uint8_t  pc_hlen;
> + uint8_t  pc_smac[CHADDR_SIZE];
> + uint8_t  pc_dmac[CHADDR_SIZE];
> +
> + struct sockaddr_storage  pc_sss;
> + struct sockaddr_storage  pc_dss;

This doesn't strike me as meaningful variable names. Could you at least
replace "s" with "src" and "d" with "dst"?  The purpose of the storage
seems more valuable to me than its type...

-- 
jca | PGP : 0x1524E7EE / 5135 92C1 AD36 5293 2BDF  DDCC 0DFA 74AE 1524 E7EE



Re: dhcrelay(8): simplify get_interface()

2016-12-07 Thread Rafael Zalamena
On Wed, Dec 07, 2016 at 05:34:05PM +0100, Rafael Zalamena wrote:
> This diff simplifies the get_interface function and makes it more
> straightforward, it also makes dhcrelay(8) throw a more informative error
> message when running layer 3 mode (default) on interfaces without an
> address.
> 
> I'll use this code later to be able to get_interfaces() without an IP address.

I forgot to make it return NULL if no interfaces are found (e.g. invalid
interface name) and then it started failing with a cryptic death message:
"Can't attach interface vip1 to bpf device: Device not configured"

This updated diff fix the problem.

ok?

Index: bpf.c
===
RCS file: /home/obsdcvs/src/usr.sbin/dhcrelay/bpf.c,v
retrieving revision 1.11
diff -u -p -r1.11 bpf.c
--- bpf.c   28 May 2016 07:00:18 -  1.11
+++ bpf.c   7 Dec 2016 17:49:16 -
@@ -75,7 +75,7 @@ if_register_bpf(struct interface_info *i
error("Can't open bpf device: %m");
 
/* Set the BPF device to point at this interface. */
-   if (ioctl(sock, BIOCSETIF, info->ifp) == -1)
+   if (ioctl(sock, BIOCSETIF, >ifr) == -1)
error("Can't attach interface %s to bpf device: %m",
info->name);
 
Index: dhcpd.h
===
RCS file: /home/obsdcvs/src/usr.sbin/dhcrelay/dhcpd.h,v
retrieving revision 1.15
diff -u -p -r1.15 dhcpd.h
--- dhcpd.h 7 Dec 2016 13:19:18 -   1.15
+++ dhcpd.h 7 Dec 2016 17:49:16 -
@@ -76,7 +76,7 @@ struct interface_info {
size_t   rbuf_max;
size_t   rbuf_offset;
size_t   rbuf_len;
-   struct ifreq*ifp;
+   struct ifreq ifr;
int  noifmedia;
int  errors;
int  dead;
Index: dhcrelay.c
===
RCS file: /home/obsdcvs/src/usr.sbin/dhcrelay/dhcrelay.c,v
retrieving revision 1.44
diff -u -p -r1.44 dhcrelay.c
--- dhcrelay.c  7 Dec 2016 13:19:18 -   1.44
+++ dhcrelay.c  7 Dec 2016 17:49:16 -
@@ -165,6 +165,9 @@ main(int argc, char *argv[])
 
if (interfaces == NULL)
error("no interface given");
+   if (interfaces->primary_address.s_addr == 0)
+   error("interface '%s' does not have an address",
+   interfaces->name);
 
/* Default DHCP/BOOTP ports. */
server_port = htons(SERVER_PORT);
Index: dispatch.c
===
RCS file: /home/obsdcvs/src/usr.sbin/dhcrelay/dispatch.c,v
retrieving revision 1.12
diff -u -p -r1.12 dispatch.c
--- dispatch.c  7 Dec 2016 13:19:18 -   1.12
+++ dispatch.c  7 Dec 2016 17:49:16 -
@@ -79,15 +79,15 @@ get_interface(const char *ifname, void (
 {
struct interface_info   *iface;
struct ifaddrs  *ifap, *ifa;
-   struct ifreq*tif;
-   struct sockaddr_in   foo;
+   struct sockaddr_in  *sin;
+   int  found = 0;
 
if ((iface = calloc(1, sizeof(*iface))) == NULL)
error("failed to allocate memory");
 
if (strlcpy(iface->name, ifname, sizeof(iface->name)) >=
sizeof(iface->name))
-   error("interface name too long");
+   error("interface name '%s' too long", ifname);
 
if (getifaddrs() != 0)
error("getifaddrs failed");
@@ -101,6 +101,8 @@ get_interface(const char *ifname, void (
if (strcmp(ifname, ifa->ifa_name))
continue;
 
+   found = 1;
+
/*
 * If we have the capability, extract link information
 * and record it in a linked list.
@@ -120,31 +122,28 @@ get_interface(const char *ifname, void (
memcpy(iface->hw_address.haddr,
LLADDR(foo), foo->sdl_alen);
} else if (ifa->ifa_addr->sa_family == AF_INET) {
-   struct iaddr addr;
+   /* We already have the primary address. */
+   if (iface->primary_address.s_addr != 0)
+   continue;
 
-   memcpy(, ifa->ifa_addr, sizeof(foo));
-   if (foo.sin_addr.s_addr == htonl(INADDR_LOOPBACK))
+   sin = (struct sockaddr_in *)ifa->ifa_addr;
+   if (sin->sin_addr.s_addr == htonl(INADDR_LOOPBACK))
continue;
-   if (!iface->ifp) {
-   int len = IFNAMSIZ + ifa->ifa_addr->sa_len;
 
-   if ((tif = malloc(len)) == NULL)
-   error("no 

Re: Stop watchdog timer during DDB session

2016-12-07 Thread Christian Ludwig
> Deliberately breaking into DDB, e.g. via serial console BREAK, can lead
> to an abrupt end of the debugging session once the hardware watchdog
> reboots the machine. This is because all CPUs are IPL_HIGH. None of them
> tickles the watchdog anymore.
> 
> The same is true on panic, when the system enters DDB. If you really
> want the system to reboot on panic, set ddb.panic to 0.
> 
> So stop the watchdog timer when entering DDB. Restart it after the
> debugging session finished.

mpi@ ok'ed this already. Any more oks? Anyone wants to commit this?

> ---
> 
>  sys/ddb/db_interface.h   |  4 
>  sys/ddb/db_trap.c|  2 ++
>  sys/kern/kern_watchdog.c | 25 +
>  3 files changed, 31 insertions(+)
> 
> diff --git a/sys/ddb/db_interface.h b/sys/ddb/db_interface.h
> index 77602d2..5728764 100644
> --- a/sys/ddb/db_interface.h
> +++ b/sys/ddb/db_interface.h
> @@ -45,6 +45,10 @@ void db_show_all_procs(db_expr_t, int, db_expr_t, char
> *);
> 
>  /* kern/kern_timeout.c */
>  void db_show_callout(db_expr_t, int, db_expr_t, char *);
> 
> +/* kern/kern_watchdog.c */
> +void db_wdog_disable(void);
> +void db_wdog_enable(void);
> +
> 
>  struct mount;
>  
>  /* kern/vfs_subr.c */
> 
> diff --git a/sys/ddb/db_trap.c b/sys/ddb/db_trap.c
> index 85e5c8a..d347ede 100644
> --- a/sys/ddb/db_trap.c
> +++ b/sys/ddb/db_trap.c
> @@ -53,6 +53,7 @@ db_trap(int type, int code)
> 
>   boolean_t   watchpt;
>   
>   db_is_active = 1;
> 
> + db_wdog_disable();
> 
>   bkpt = IS_BREAKPOINT_TRAP(type, code);
>   watchpt = IS_WATCHPOINT_TRAP(type, code);
> 
> @@ -94,5 +95,6 @@ db_trap(int type, int code)
> 
>   }
>   
>   db_restart_at_pc(_regs, watchpt);
> 
> + db_wdog_enable();
> 
>   db_is_active = 0;
>  
>  }
> 
> diff --git a/sys/kern/kern_watchdog.c b/sys/kern/kern_watchdog.c
> index 5c27b17..e848e24 100644
> --- a/sys/kern/kern_watchdog.c
> +++ b/sys/kern/kern_watchdog.c
> @@ -106,3 +106,28 @@ sysctl_wdog(int *name, u_int namelen, void *oldp,
> size_t *oldlenp, void *newp,> 
>   return (error);
>  
>  }
> 
> +
> +#ifdef DDB
> +#include 
> +#include 
> +
> +void
> +db_wdog_disable(void)
> +{
> + if (wdog_ctl_cb == NULL || wdog_period == 0)
> + return;
> +
> + timeout_del(_timeout);
> + (void) (*wdog_ctl_cb)(wdog_ctl_cb_arg, 0);
> +}
> +
> +void
> +db_wdog_enable(void)
> +{
> + if (wdog_ctl_cb == NULL || wdog_period == 0)
> + return;
> +
> + (void) (*wdog_ctl_cb)(wdog_ctl_cb_arg, wdog_period);
> + timeout_add(_timeout, wdog_period * hz / 2);
> +}
> +#endif
> --
> 2.1.4



Modify disklabel(8) manual about possible units

2016-12-07 Thread Jérôme FRGACIC
Hello tech,

While reading disklabel(8) man page I remark that the two possibles
units '%' (percent of total) and '&' (percent of free) are only
mentioned in the description of the 'p' option but not in the section
which list available units.

I would suggest to move the '%' and '&' units description in the later
section.

Index: disklabel.8
===
RCS file: /cvs/src/sbin/disklabel/disklabel.8,v
retrieving revision 1.120
diff -u -r1.120 disklabel.8
--- disklabel.8 3 Dec 2016 07:34:39 -   1.120
+++ disklabel.8 7 Dec 2016 16:32:06 -
@@ -157,11 +157,6 @@
 instead of sectors.
 Valid units are b(ytes), c(ylinders), k(ilobytes), m(egabytes), g
(igabytes) and t(erabytes).
-For operations other than displaying a partition the
-.Ql %
-(percent of total) and
-.Ql &
-(percent of free) units are also accepted.
 .It Fl R
 Restore a disk label that was formatted in a prior operation and
 saved in an
@@ -265,9 +260,13 @@
 for megabytes,
 .Sq g
 for gigabytes,
-and
 .Sq t
-for terabytes.
+for terabytes,
+.Ql %
+for a percent of total
+and
+.Ql &
+for a percent of free.
 If no unit is given, the default is to use sectors
 (usually 512 bytes).
 Quantities will be rounded to the nearest

PS : I haven't subcribe to the tech mailing list, so please add me as
recipient if you reply.

Kind regards,


Jérôme FRGACIC



dhcrelay(8): simplify get_interface()

2016-12-07 Thread Rafael Zalamena
This diff simplifies the get_interface function and makes it more
straightforward, it also makes dhcrelay(8) throw a more informative error
message when running layer 3 mode (default) on interfaces without an
address.

I'll use this code later to be able to get_interfaces() without an IP address.

ok?

Index: bpf.c
===
RCS file: /cvs/src/usr.sbin/dhcrelay/bpf.c,v
retrieving revision 1.11
diff -u -p -r1.11 bpf.c
--- bpf.c   28 May 2016 07:00:18 -  1.11
+++ bpf.c   7 Dec 2016 16:29:14 -
@@ -75,7 +75,7 @@ if_register_bpf(struct interface_info *i
error("Can't open bpf device: %m");
 
/* Set the BPF device to point at this interface. */
-   if (ioctl(sock, BIOCSETIF, info->ifp) == -1)
+   if (ioctl(sock, BIOCSETIF, >ifr) == -1)
error("Can't attach interface %s to bpf device: %m",
info->name);
 
Index: dhcpd.h
===
RCS file: /cvs/src/usr.sbin/dhcrelay/dhcpd.h,v
retrieving revision 1.15
diff -u -p -r1.15 dhcpd.h
--- dhcpd.h 7 Dec 2016 13:19:18 -   1.15
+++ dhcpd.h 7 Dec 2016 16:29:14 -
@@ -76,7 +76,7 @@ struct interface_info {
size_t   rbuf_max;
size_t   rbuf_offset;
size_t   rbuf_len;
-   struct ifreq*ifp;
+   struct ifreq ifr;
int  noifmedia;
int  errors;
int  dead;
Index: dhcrelay.c
===
RCS file: /cvs/src/usr.sbin/dhcrelay/dhcrelay.c,v
retrieving revision 1.44
diff -u -p -r1.44 dhcrelay.c
--- dhcrelay.c  7 Dec 2016 13:19:18 -   1.44
+++ dhcrelay.c  7 Dec 2016 16:29:14 -
@@ -165,6 +165,9 @@ main(int argc, char *argv[])
 
if (interfaces == NULL)
error("no interface given");
+   if (interfaces->primary_address.s_addr == 0)
+   error("interface '%s' does not have an address",
+   interfaces->name);
 
/* Default DHCP/BOOTP ports. */
server_port = htons(SERVER_PORT);
Index: dispatch.c
===
RCS file: /cvs/src/usr.sbin/dhcrelay/dispatch.c,v
retrieving revision 1.12
diff -u -p -r1.12 dispatch.c
--- dispatch.c  7 Dec 2016 13:19:18 -   1.12
+++ dispatch.c  7 Dec 2016 16:29:14 -
@@ -79,15 +79,14 @@ get_interface(const char *ifname, void (
 {
struct interface_info   *iface;
struct ifaddrs  *ifap, *ifa;
-   struct ifreq*tif;
-   struct sockaddr_in   foo;
+   struct sockaddr_in  *sin;
 
if ((iface = calloc(1, sizeof(*iface))) == NULL)
error("failed to allocate memory");
 
if (strlcpy(iface->name, ifname, sizeof(iface->name)) >=
sizeof(iface->name))
-   error("interface name too long");
+   error("interface name '%s' too long", ifname);
 
if (getifaddrs() != 0)
error("getifaddrs failed");
@@ -120,31 +119,23 @@ get_interface(const char *ifname, void (
memcpy(iface->hw_address.haddr,
LLADDR(foo), foo->sdl_alen);
} else if (ifa->ifa_addr->sa_family == AF_INET) {
-   struct iaddr addr;
+   /* We already have the primary address. */
+   if (iface->primary_address.s_addr != 0)
+   continue;
 
-   memcpy(, ifa->ifa_addr, sizeof(foo));
-   if (foo.sin_addr.s_addr == htonl(INADDR_LOOPBACK))
+   sin = (struct sockaddr_in *)ifa->ifa_addr;
+   if (sin->sin_addr.s_addr == htonl(INADDR_LOOPBACK))
continue;
-   if (!iface->ifp) {
-   int len = IFNAMSIZ + ifa->ifa_addr->sa_len;
 
-   if ((tif = malloc(len)) == NULL)
-   error("no space to remember ifp");
-   strlcpy(tif->ifr_name, ifa->ifa_name, IFNAMSIZ);
-   memcpy(>ifr_addr, ifa->ifa_addr,
-   ifa->ifa_addr->sa_len);
-   iface->ifp = tif;
-   iface->primary_address = foo.sin_addr;
-   }
-   addr.len = 4;
-   memcpy(addr.iabuf, _addr.s_addr, addr.len);
+   iface->primary_address = sin->sin_addr;
}
}
 
freeifaddrs(ifap);
 
-   if (!iface->ifp)
-   error("%s: not found", iface->name);
+   if (strlcpy(iface->ifr.ifr_name, ifname,

Re: [PATCH] softraid.4 move wd(4) examples to sd(4)

2016-12-07 Thread Reyk Floeter
On Wed, Dec 07, 2016 at 06:42:51AM -0800, Bryan Vyhmeister wrote:
> On Wed, Dec 07, 2016 at 10:46:44AM +0100, Reyk Floeter wrote:
> > 
> > > Am 05.12.2016 um 23:05 schrieb Bryan Vyhmeister :
> > > 
> > > In responding to a post on misc@, I noticed that bioctl(8) uses all sd(4)
> > > devices in the examples sections while softraid(4) uses wd(4) devices
> > > for the chunks. This patch updates softraid.4 to use sd(4) devices as
> > > well. I have not used a wd(4) device in years and I think it more
> > > confusing to use examples with wd(4) when almost everything these days
> > > is sd(4).
> > > Bryan
> > > 
> > 
> > wd(4) is still alive. For example, we use it on VMs where we don't
> > have a PV disk driver yet (Xen, Hyper-V).
> 
> I did not know that. I've only used OpenBSD under VMware products and
> bhyve. That makes sense.
> 

Actually, with the new xbf(4) we don't need it on Xen anymore (;

Reyk



Re: dhcrelay: pledge(2)

2016-12-07 Thread Rafael Zalamena
On Wed, Dec 07, 2016 at 02:47:25PM +0100, Reyk Floeter wrote:
> Hi,
> 
> dhcrelay drops privs but isn't pledged yet - here it is.
> 
> It is simpler than dhclient: it only needs stdio and route because it
> pre-opens all file descriptors (UDP, bpf), does the bpf ioctls before,
> and only needs "route" for interface status ioctls on runtime.
> 
> OK?

I didn't finish my implementations, but from what I've tested it seems to
be working. I don't expect anything different.

ok rzalamena@

> 
> Reyk
> 
> Index: usr.sbin/dhcrelay/dhcrelay.c
> ===
> RCS file: /cvs/src/usr.sbin/dhcrelay/dhcrelay.c,v
> retrieving revision 1.44
> diff -u -p -u -p -r1.44 dhcrelay.c
> --- usr.sbin/dhcrelay/dhcrelay.c  7 Dec 2016 13:19:18 -   1.44
> +++ usr.sbin/dhcrelay/dhcrelay.c  7 Dec 2016 13:42:07 -
> @@ -248,6 +248,9 @@ main(int argc, char *argv[])
>   log_perror = 0;
>   }
>  
> + if (pledge("stdio route", NULL) == -1)
> + error("pledge");
> +
>   dispatch();
>   /* not reached */
>  
> 



Re: dhcrelay(8): clean up function prototypes

2016-12-07 Thread Rafael Zalamena
On Wed, Dec 07, 2016 at 02:49:55PM +0100, Rafael Zalamena wrote:
> ---snipped---
> 

Actually the code below is not wrong, there are some scenarios where you
need this to make relayed DHCP to work. I'm not touching the part I noted
before.

The diff that I sent before still stands and has nothing to do with this
note.

> ---
> Note:
> While testing this I noticed that even though the server socket is sending
> the wrong source port, the dhcp server doesn't care about it and it works.
> But this can be easily fixed by changing this line in dhcrelay.c:
> ...
> main() {
> ...
>   laddr.sin_port = server_port;
> ...
> 
> to
>   laddr.sin_port = client_port;
> 
> I'll fix this in another diff.
> --



Re: [PATCH] softraid.4 move wd(4) examples to sd(4)

2016-12-07 Thread Bryan Vyhmeister
On Wed, Dec 07, 2016 at 10:46:44AM +0100, Reyk Floeter wrote:
> 
> > Am 05.12.2016 um 23:05 schrieb Bryan Vyhmeister :
> > 
> > In responding to a post on misc@, I noticed that bioctl(8) uses all sd(4)
> > devices in the examples sections while softraid(4) uses wd(4) devices
> > for the chunks. This patch updates softraid.4 to use sd(4) devices as
> > well. I have not used a wd(4) device in years and I think it more
> > confusing to use examples with wd(4) when almost everything these days
> > is sd(4).
> > Bryan
> > 
> 
> wd(4) is still alive. For example, we use it on VMs where we don't
> have a PV disk driver yet (Xen, Hyper-V).

I did not know that. I've only used OpenBSD under VMware products and
bhyve. That makes sense.

Bryan



dhcrelay(8): clean up function prototypes

2016-12-07 Thread Rafael Zalamena
I'm implementing some features for dhcrelay and to make them fit I need
some clean ups in the dhcrelay(8) first. This diff changes most of the
input/output functions prototypes to take one parameter with all addresses
instead of passing multiple parameters.

Basically this will make input functions gather more information (source/
destination MACs, source/destination IPs, source/destination ports) and
use it in the output instead of trying to figure out this information along
the way.

With this we will be able to add IPv6 support and layer 2 relaying.

---
Note:
While testing this I noticed that even though the server socket is sending
the wrong source port, the dhcp server doesn't care about it and it works.
But this can be easily fixed by changing this line in dhcrelay.c:
...
main() {
...
laddr.sin_port = server_port;
...

to
laddr.sin_port = client_port;

I'll fix this in another diff.
--

ok?

Index: bpf.c
===
RCS file: /cvs/src/usr.sbin/dhcrelay/bpf.c,v
retrieving revision 1.11
diff -u -p -r1.11 bpf.c
--- bpf.c   28 May 2016 07:00:18 -  1.11
+++ bpf.c   7 Dec 2016 13:44:35 -
@@ -258,24 +258,23 @@ if_register_receive(struct interface_inf
 
 ssize_t
 send_packet(struct interface_info *interface,
-struct dhcp_packet *raw, size_t len, struct in_addr from,
-struct sockaddr_in *to, struct hardware *hto)
+struct dhcp_packet *raw, size_t len, struct packet_ctx *pc)
 {
unsigned char buf[256];
struct iovec iov[2];
int result, bufp = 0;
 
if (interface->hw_address.htype == HTYPE_IPSEC_TUNNEL) {
-   socklen_t slen = sizeof(*to);
+   socklen_t slen = pc->pc_dss.ss_len;
result = sendto(server_fd, raw, len, 0,
-   (struct sockaddr *)to, slen);
+   (struct sockaddr *)>pc_dss, slen);
goto done;
}
 
/* Assemble the headers... */
-   assemble_hw_header(interface, buf, , hto);
-   assemble_udp_ip_header(interface, buf, , from.s_addr,
-   to->sin_addr.s_addr, to->sin_port, (unsigned char *)raw, len);
+   assemble_hw_header(interface, buf, , pc);
+   assemble_udp_ip_header(interface, buf, , pc,
+   (unsigned char *)raw, len);
 
/* Fire it off */
iov[0].iov_base = (char *)buf;
@@ -292,7 +291,7 @@ send_packet(struct interface_info *inter
 
 ssize_t
 receive_packet(struct interface_info *interface, unsigned char *buf,
-size_t len, struct sockaddr_in *from, struct hardware *hfrom)
+size_t len, struct packet_ctx *pc)
 {
int length = 0, offset = 0;
struct bpf_hdr hdr;
@@ -358,7 +357,7 @@ receive_packet(struct interface_info *in
 
/* Decode the physical header... */
offset = decode_hw_header(interface,
-   interface->rbuf, interface->rbuf_offset, hfrom);
+   interface->rbuf, interface->rbuf_offset, pc);
 
/*
 * If a physical layer checksum failed (dunno of any
@@ -374,7 +373,7 @@ receive_packet(struct interface_info *in
 
/* Decode the IP and UDP headers... */
offset = decode_udp_ip_header(interface, interface->rbuf,
-   interface->rbuf_offset, from, hdr.bh_caplen);
+   interface->rbuf_offset, pc, hdr.bh_caplen);
 
/* If the IP or UDP checksum was bad, skip the packet... */
if (offset < 0) {
Index: dhcpd.h
===
RCS file: /cvs/src/usr.sbin/dhcrelay/dhcpd.h,v
retrieving revision 1.15
diff -u -p -r1.15 dhcpd.h
--- dhcpd.h 7 Dec 2016 13:19:18 -   1.15
+++ dhcpd.h 7 Dec 2016 13:44:35 -
@@ -42,15 +42,28 @@
 #defineSERVER_PORT 67
 #defineCLIENT_PORT 68
 
+/* Maximum size of client hardware address. */
+#define CHADDR_SIZE16
+
+struct packet_ctx {
+   uint8_t  pc_htype;
+   uint8_t  pc_hlen;
+   uint8_t  pc_smac[CHADDR_SIZE];
+   uint8_t  pc_dmac[CHADDR_SIZE];
+
+   struct sockaddr_storage  pc_sss;
+   struct sockaddr_storage  pc_dss;
+};
+
 struct iaddr {
int len;
-   unsigned char iabuf[16];
+   unsigned char iabuf[CHADDR_SIZE];
 };
 
 struct hardware {
u_int8_t htype;
u_int8_t hlen;
-   u_int8_t haddr[16];
+   u_int8_t haddr[CHADDR_SIZE];
 };
 
 /* Possible states in which the client can be. */
@@ -112,15 +125,13 @@ int if_register_bpf(struct interface_inf
 void if_register_send(struct interface_info *);
 void if_register_receive(struct interface_info *);
 ssize_t send_packet(struct interface_info *,
-struct dhcp_packet *, size_t, struct in_addr,
-struct sockaddr_in *, struct hardware *);
+struct dhcp_packet *, size_t, struct 

dhcrelay: pledge(2)

2016-12-07 Thread Reyk Floeter
Hi,

dhcrelay drops privs but isn't pledged yet - here it is.

It is simpler than dhclient: it only needs stdio and route because it
pre-opens all file descriptors (UDP, bpf), does the bpf ioctls before,
and only needs "route" for interface status ioctls on runtime.

OK?

Reyk

Index: usr.sbin/dhcrelay/dhcrelay.c
===
RCS file: /cvs/src/usr.sbin/dhcrelay/dhcrelay.c,v
retrieving revision 1.44
diff -u -p -u -p -r1.44 dhcrelay.c
--- usr.sbin/dhcrelay/dhcrelay.c7 Dec 2016 13:19:18 -   1.44
+++ usr.sbin/dhcrelay/dhcrelay.c7 Dec 2016 13:42:07 -
@@ -248,6 +248,9 @@ main(int argc, char *argv[])
log_perror = 0;
}
 
+   if (pledge("stdio route", NULL) == -1)
+   error("pledge");
+
dispatch();
/* not reached */
 



Re: [PATCH] softraid.4 move wd(4) examples to sd(4)

2016-12-07 Thread Reyk Floeter

> Am 05.12.2016 um 23:05 schrieb Bryan Vyhmeister :
> 
> In responding to a post on misc@, I noticed that bioctl(8) uses all sd(4)
> devices in the examples sections while softraid(4) uses wd(4) devices
> for the chunks. This patch updates softraid.4 to use sd(4) devices as
> well. I have not used a wd(4) device in years and I think it more
> confusing to use examples with wd(4) when almost everything these days
> is sd(4).
> Bryan
> 

wd(4) is still alive. For example, we use it on VMs where we don't have a PV 
disk driver yet (Xen, Hyper-V).

Reyk

> 
> Index: share/man/man4/softraid.4
> ===
> RCS file: /cvs/src/share/man/man4/softraid.4,v
> retrieving revision 1.41
> diff -u -p -r1.41 softraid.4
> --- share/man/man4/softraid.414 Apr 2015 19:10:13 -1.41
> +++ share/man/man4/softraid.45 Dec 2016 21:58:55 -
> @@ -121,41 +121,41 @@ An example to create a 3 chunk RAID 1 fr
> .Pp
> Initialize the partition tables of all disks:
> .Bd -literal -offset indent
> -# fdisk -iy wd1
> -# fdisk -iy wd2
> -# fdisk -iy wd3
> +# fdisk -iy sd1
> +# fdisk -iy sd2
> +# fdisk -iy sd3
> .Ed
> .Pp
> Now create RAID partitions on all disks:
> .Bd -literal -offset indent
> -# printf "a\en\en\en\enRAID\enw\enq\en\en" | disklabel -E wd1
> -# printf "a\en\en\en\enRAID\enw\enq\en\en" | disklabel -E wd2
> -# printf "a\en\en\en\enRAID\enw\enq\en\en" | disklabel -E wd3
> +# printf "a\en\en\en\enRAID\enw\enq\en\en" | disklabel -E sd1
> +# printf "a\en\en\en\enRAID\enw\enq\en\en" | disklabel -E sd2
> +# printf "a\en\en\en\enRAID\enw\enq\en\en" | disklabel -E sd3
> .Ed
> .Pp
> Assemble the RAID volume:
> .Bd -literal -offset indent
> -# bioctl -c 1 -l /dev/wd1a,/dev/wd2a,/dev/wd3a softraid0
> +# bioctl -c 1 -l /dev/sd1a,/dev/sd2a,/dev/sd3a softraid0
> .Ed
> .Pp
> The console will show what device was added to the system:
> .Bd -literal -offset indent
> scsibus0 at softraid0: 1 targets
> -sd0 at scsibus0 targ 0 lun 0:  SCSI2
> -sd0: 1MB, 0 cyl, 255 head, 63 sec, 512 bytes/sec, 3714 sec total
> +sd4 at scsibus0 targ 0 lun 0:  SCSI2
> +sd4: 1MB, 0 cyl, 255 head, 63 sec, 512 bytes/sec, 3714 sec total
> .Ed
> .Pp
> It is good practice to wipe the front of the disk before using it:
> .Bd -literal -offset indent
> -# dd if=/dev/zero of=/dev/rsd0c bs=1m count=1
> +# dd if=/dev/zero of=/dev/rsd4c bs=1m count=1
> .Ed
> .Pp
> Initialize the partition table and create a filesystem on the
> new RAID volume:
> .Bd -literal -offset indent
> -# fdisk -iy sd0
> -# printf "a\en\en\en\en4.2BSD\enw\enq\en\en" | disklabel -E sd0
> -# newfs /dev/rsd0a
> +# fdisk -iy sd4
> +# printf "a\en\en\en\en4.2BSD\enw\enq\en\en" | disklabel -E sd4
> +# newfs /dev/rsd4a
> .Ed
> .Pp
> The RAID volume is now ready to be used as a normal disk device.
> @@ -167,7 +167,7 @@ Install
> .Xr boot 8
> on the RAID volume:
> .Bd -literal -offset indent
> -# installboot sd0
> +# installboot sd4
> .Ed
> .Pp
> At the
>