Re: fsync(2) and I/O errors

2019-02-15 Thread Maximilian Lorlacks


‐‐‐ Original Message ‐‐‐
On Thursday, January 31, 2019 11:31 PM, Alexander Bluhm 
 wrote:

> On Thu, Jan 31, 2019 at 04:26:45PM -0500, Ted Unangst wrote:
>
> > Instead, we note that the write failed and mark a flag in the vnode. Future
> > calls to fsync will then return EIO when this flag is set. We clear the flag
> > when the vnode is released.
>
> Sounds reasonable.
>
> OK bluhm@

People may object to errors being lost when the vnode is released,
as that would lose errors in a scenario like write -> close -> open
-> fsync.  I do not claim to know if anyone actually does that in the
wild, however.

If the above diff is accepted, it may be worth to also add the
following diff to fsync.2 to document the behavior:

diff --git lib/libc/sys/fsync.2 lib/libc/sys/fsync.2
index c9831ca09..5ee765986 100644
--- lib/libc/sys/fsync.2
+++ lib/libc/sys/fsync.2
@@ -66,6 +66,19 @@ and
 .Fn fdatasync
 should be used by programs that require a file to be in a known state,
 for example, in building a simple transaction facility.
+.Pp
+If
+.Fn fsync
+or
+.Fn fdatasync
+fails with
+.Er EIO ,
+the state of the on-disk data may only have been partially written.
+Future attempts to call these functions will continue failing with
+.Er EIO
+until the all copies of the underlying
+.Fa fd
+have been closed.
 .Sh RETURN VALUES
 .Rv -std fsync fdatasync
 .Sh ERRORS



minor changes to isakmpd(8)

2019-02-15 Thread Sevan Janiyan
Use an It tag to label the additional steps referred to at the beginning
of step 2:
"This step, as well as the next one, needs to be done for every peer.
Furthermore the last step will need to be done once for each ID you want
the peer to have"

Change the file name passed to openssl for extfile to indicate cloned
file is used.

For FQDN certificates use change the CERTFQDN field.

Add instructions on how to check the subjectAltName field of a certificate.

s/fashion/convention.


Sevan
Index: sbin/isakmpd/isakmpd.8
===
RCS file: /cvs/src/sbin/isakmpd/isakmpd.8,v
retrieving revision 1.120
diff -u -p -r1.120 isakmpd.8
--- sbin/isakmpd/isakmpd.8  17 Apr 2018 12:13:29 -  1.120
+++ sbin/isakmpd/isakmpd.8  16 Feb 2019 02:27:13 -
@@ -607,6 +607,8 @@ Encoding the ID in the common name is re
 # openssl req -new -key /etc/isakmpd/private/local.key \e
-out /etc/isakmpd/private/10.0.0.1.csr
 .Ed
+.It
+Generate signed certificates from Certificate Signing Requests (CSRs)
 .Pp
 Now take these certificate signing requests to your CA and process
 them as below.
@@ -626,12 +628,12 @@ with 10.0.0.1, then run:
 # openssl x509 -req \e
-days 365 -in 10.0.0.1.csr \e
-CA /etc/ssl/ca.crt -CAkey /etc/ssl/private/ca.key \e
-   -CAcreateserial -extfile /etc/ssl/x509v3.cnf \e
+   -CAcreateserial -extfile ~/tmp_x509v3.cnf \e
-extensions x509v3_IPAddr -out 10.0.0.1.crt
 .Ed
 .Pp
 For a FQDN certificate, replace
-.Dv $ENV::CERTIP
+.Dv $ENV::CERTFQDN
 with the hostname and run:
 .Bd -literal -offset indent
 # openssl x509 -req \e
@@ -651,6 +653,18 @@ in
 A similar setup will be required if
 .Xr isakmpd.conf 5
 is being used instead.
+To verify the
+.Va subjectAltName
+of the certificate matches the
+.Ic srcid
+referenced in
+.Xr ipsec.conf 5
+use:
+.Bd -literal -offset indent
+# openssl x509 -noout -text -in somehost.somedomain.crt
+.Ed
+.It
+Copy certificates into place
 .Pp
 Put the certificate (the file ending in .crt) in
 .Pa /etc/isakmpd/certs/
@@ -721,7 +735,7 @@ has the same mode requirements as
 .Pa isakmpd.conf .
 .It Pa /etc/isakmpd/pubkeys/
 The directory in which trusted public keys are kept.
-The keys must be named in the fashion described above.
+The keys must be named in the convention described above.
 .It Pa /var/run/isakmpd.fifo
 The FIFO used to manually control
 .Nm isakmpd .


Re: bgpd, protability and sockaddr sa_len

2019-02-15 Thread William Ahern
On Fri, Feb 15, 2019 at 03:07:15PM +0100, Claudio Jeker wrote:
> Another diff to ease portability of bgpd. The sa_len field in struct
> sockaddr does not exist on Linux so instead of using it pass a length to
> the function (e.g. like bind(2) and connect(2) and do the same when
> passing around struct sockaddr_storage in the listener case.
> The remaining sa_len, sin_len, sin6_len and ss_len usages are in very
> OpenBSD specific files.
> 
> -- 
> :wq Claudio
> 
> Index: bgpd.h
> ===
> RCS file: /cvs/src/usr.sbin/bgpd/bgpd.h,v
> retrieving revision 1.369
> diff -u -p -r1.369 bgpd.h
> --- bgpd.h15 Feb 2019 11:38:06 -  1.369
> +++ bgpd.h15 Feb 2019 13:51:28 -
> @@ -220,11 +220,12 @@ struct bgpd_addr {
>  #define  LISTENER_LISTENING  0x02
>  
>  struct listen_addr {
> - TAILQ_ENTRY(listen_addr) entry;
> - struct sockaddr_storage  sa;
> - int  fd;
> - enum reconf_action   reconf;
> - u_int8_t flags;
> + TAILQ_ENTRY(listen_addr)entry;
> + struct sockaddr_storage sa;
> + int fd;
> + enum reconf_action  reconf;
> + socklen_t   sa_len;
> + u_int8_tflags;
>  };

What's the use of maintaining and passing around sa_len if the sa member is
a fixed size? (Well, other than being a more straightforward patch.)

AFAIK the only variably sized sockaddr structure is sockaddr_un. Domain
socket paths can be longer than what sockaddr_un (or sockaddr_storage) can
nominally fit, but if the sa member is a fixed size then it's irrelevant and
you can always derive the sa object size from .sa_family or .sun_family +
.sun_path.



Re: dd conv=fsync

2019-02-15 Thread Ted Unangst
Alexander Bluhm wrote:
> We should not implement the magic which device allows fsync(2) into
> dd(1).  Just do what the user says, if it is nonsense, give him an
> error.

sure. ok.



Re: futex(2) based pthread_rwlock*

2019-02-15 Thread Paul Irofti

On 13.02.2019 15:08, Martin Pieuchot wrote:

+   val = rwlock->value;
+   if (val == UNLOCKED || (val & WAITING))
+   break;
+
+   SPIN_WAIT();
+   }
+
+   while ((error = _rthread_rwlock_tryrdlock(rwlock)) == EBUSY) {
+   val = rwlock->value;
+   if (val == UNLOCKED || (COUNT(val)) != WRITER)
+   continue;
+   new = val | WAITING;
+   if (atomic_cas_uint(>value, val, new) == val) {

Don't you need a membar_after_atomic() here?

Why?  The lock hasn't been acquired here.


Right, but you are possibly changing the value of, erm, rwlock->value 
which will be read in rthread_rwlock_unlock(). But I guess this will be 
taken care of by the membar_exit_before_atomic() call before taking the 
lock.





+   error = _twait(>value, new, CLOCK_REALTIME,
+   abs);
+   }
+   if (error == ETIMEDOUT)
+   break;
}
-   _spinunlock(>lock);
  
  	return (error);

+
  int
-pthread_rwlock_unlock(pthread_rwlock_t *lockp)
+pthread_rwlock_unlock(pthread_rwlock_t *rwlockp)
  {
+   pthread_t self = pthread_self();
+   pthread_rwlock_t rwlock;
+   unsigned int val, new;
+
+   rwlock = *rwlockp;
+   _rthread_debug(5, "%p: rwlock_unlock %p\n", self, (void *)rwlock);
+
+   membar_exit_before_atomic();

Wouldn't this membar need to be inside the loop? Or perhaps a
corresponding membar_enter() after exiting the loop?

Why?

The membar is here to enforce that writes done during the critical
section are visible before the lock is released.  Such that another
thread wont grab the lock and see outdated data inside the critical
section.


Can't another thread grab the lock right after cas() and before _wake()?

I thought after my semaphore implementation I managed to grasp how these 
membars are supposed to be used, but here I am half a year later (or 
more?) and I forgot or (most probably) never really understood them :)


Eitherway, please go ahead and commit this. OK pirofti@



Re: locate.mklocatedb broken with LC_ALL!=C

2019-02-15 Thread Marc Espie
On Fri, Feb 15, 2019 at 07:58:48PM +0100, Giovanni Bechis wrote:
> ping...
> any possible issue with millert@ diff ?
>  Giovanni
> 
> On Sun, Oct 07, 2018 at 08:35:28PM -0600, Todd C. Miller wrote:
> > On Sun, 07 Oct 2018 17:08:06 +0200, Marc Espie wrote:
> > 
> > > Specifically, the only part that cares about
> > > locale is sort, and it's definitely correct in fixing
> > > it's not run on an utf-8 file.
> > 
> > Agreed.  How about the following?
> > 
> >  - todd
> > 
> > Index: usr.bin/locate/locate/mklocatedb.sh
> > ===
> > RCS file: /cvs/src/usr.bin/locate/locate/mklocatedb.sh,v
> > retrieving revision 1.13
> > diff -u -p -u -r1.13 mklocatedb.sh
> > --- usr.bin/locate/locate/mklocatedb.sh 18 Mar 2007 20:13:49 -  
> > 1.13
> > +++ usr.bin/locate/locate/mklocatedb.sh 8 Oct 2018 02:34:52 -
> > @@ -66,7 +66,8 @@ filelist=`mktemp ${TMPDIR=/tmp}/_filelis
> >  }
> >  trap 'rm -f $bigrams $filelist' 0 1 2 3 5 10 15
> >  
> > -if $sortcmd $sortopt > $filelist; then
> > +# Run sort in the C locale or binary data may be interpreted as UTF-8
> > +if LC_ALL=C $sortcmd $sortopt > $filelist; then
> >  $bigram < $filelist | $sort -nr | 
> >  awk -Ft 'BEGIN { ORS = "" } NR <= 128 { print $2 }' > 
> > $bigrams &&
> >  $code $bigrams < $filelist 


Oh, I thought it had been committed ages ago



Re: bgpd, protability and sockaddr sa_len

2019-02-15 Thread Sebastian Benoit
ok

Claudio Jeker(cje...@diehard.n-r-g.com) on 2019.02.15 15:07:15 +0100:
> Another diff to ease portability of bgpd. The sa_len field in struct
> sockaddr does not exist on Linux so instead of using it pass a length to
> the function (e.g. like bind(2) and connect(2) and do the same when
> passing around struct sockaddr_storage in the listener case.
> The remaining sa_len, sin_len, sin6_len and ss_len usages are in very
> OpenBSD specific files.
> 
> -- 
> :wq Claudio
> 
> Index: bgpd.h
> ===
> RCS file: /cvs/src/usr.sbin/bgpd/bgpd.h,v
> retrieving revision 1.369
> diff -u -p -r1.369 bgpd.h
> --- bgpd.h15 Feb 2019 11:38:06 -  1.369
> +++ bgpd.h15 Feb 2019 13:51:28 -
> @@ -220,11 +220,12 @@ struct bgpd_addr {
>  #define  LISTENER_LISTENING  0x02
>  
>  struct listen_addr {
> - TAILQ_ENTRY(listen_addr) entry;
> - struct sockaddr_storage  sa;
> - int  fd;
> - enum reconf_action   reconf;
> - u_int8_t flags;
> + TAILQ_ENTRY(listen_addr)entry;
> + struct sockaddr_storage sa;
> + int fd;
> + enum reconf_action  reconf;
> + socklen_t   sa_len;
> + u_int8_tflags;
>  };
>  
>  TAILQ_HEAD(listen_addrs, listen_addr);
> @@ -1254,7 +1255,7 @@ int  set_equal(const struct 
> set_table 
>  /* util.c */
>  const char   *log_addr(const struct bgpd_addr *);
>  const char   *log_in6addr(const struct in6_addr *);
> -const char   *log_sockaddr(struct sockaddr *);
> +const char   *log_sockaddr(struct sockaddr *, socklen_t);
>  const char   *log_as(u_int32_t);
>  const char   *log_rd(u_int64_t);
>  const char   *log_ext_subtype(u_int8_t, u_int8_t);
> @@ -1288,7 +1289,7 @@ int  aid2afi(u_int8_t, u_int16_t *, u_i
>  int   afi2aid(u_int16_t, u_int8_t, u_int8_t *);
>  sa_family_t   aid2af(u_int8_t);
>  int   af2aid(sa_family_t, u_int8_t, u_int8_t *);
> -struct sockaddr  *addr2sa(struct bgpd_addr *, u_int16_t);
> +struct sockaddr  *addr2sa(struct bgpd_addr *, u_int16_t, socklen_t *);
>  void  sa2addr(struct sockaddr *, struct bgpd_addr *);
>  uint64_t  ift2ifm(uint8_t);
>  const char *  get_media_descr(uint64_t);
> Index: config.c
> ===
> RCS file: /cvs/src/usr.sbin/bgpd/config.c,v
> retrieving revision 1.81
> diff -u -p -r1.81 config.c
> --- config.c  12 Feb 2019 09:00:21 -  1.81
> +++ config.c  15 Feb 2019 13:43:42 -
> @@ -397,7 +397,7 @@ prepare_listeners(struct bgpd_config *co
>   la->fd = -1;
>   la->flags = DEFAULT_LISTENER;
>   la->reconf = RECONF_REINIT;
> - la->sa.ss_len = sizeof(struct sockaddr_in);
> + la->sa_len = sizeof(struct sockaddr_in);
>   ((struct sockaddr_in *)>sa)->sin_family = AF_INET;
>   ((struct sockaddr_in *)>sa)->sin_addr.s_addr =
>   htonl(INADDR_ANY);
> @@ -409,7 +409,7 @@ prepare_listeners(struct bgpd_config *co
>   la->fd = -1;
>   la->flags = DEFAULT_LISTENER;
>   la->reconf = RECONF_REINIT;
> - la->sa.ss_len = sizeof(struct sockaddr_in6);
> + la->sa_len = sizeof(struct sockaddr_in6);
>   ((struct sockaddr_in6 *)>sa)->sin6_family = AF_INET6;
>   ((struct sockaddr_in6 *)>sa)->sin6_port = htons(BGP_PORT);
>   TAILQ_INSERT_TAIL(conf->listen_addrs, la, entry);
> @@ -437,24 +437,25 @@ prepare_listeners(struct bgpd_config *co
>   , sizeof(opt)) == -1)
>   fatal("setsockopt SO_REUSEADDR");
>  
> - if (bind(la->fd, (struct sockaddr *)>sa, la->sa.ss_len) ==
> + if (bind(la->fd, (struct sockaddr *)>sa, la->sa_len) ==
>   -1) {
>   switch (la->sa.ss_family) {
>   case AF_INET:
>   log_warn("cannot bind to %s:%u",
> - log_sockaddr((struct sockaddr *)>sa),
> - ntohs(((struct sockaddr_in *)
> + log_sockaddr((struct sockaddr *)>sa,
> + la->sa_len), ntohs(((struct sockaddr_in *)
>   >sa)->sin_port));
>   break;
>   case AF_INET6:
>   log_warn("cannot bind to [%s]:%u",
> - log_sockaddr((struct sockaddr *)>sa),
> - ntohs(((struct sockaddr_in6 *)
> + log_sockaddr((struct sockaddr *)>sa,
> + la->sa_len), ntohs(((struct sockaddr_in6 *)
>   

Re: bgpd 'depend on' refactor

2019-02-15 Thread Sebastian Benoit
ok

Claudio Jeker(cje...@diehard.n-r-g.com) on 2019.02.15 12:01:20 +0100:
> To make bgpd more portable it is better to move all the link state code
> into kroute.c. Especially for something as simple as a single up / down
> flag.  This is doing that and removes the net/if_types.h include from
> session.c. Result should be the same just computation is moved.
> 
> OK?
> -- 
> :wq Claudio
> 
> Index: bgpd.h
> ===
> RCS file: /cvs/src/usr.sbin/bgpd/bgpd.h,v
> retrieving revision 1.368
> diff -u -p -r1.368 bgpd.h
> --- bgpd.h14 Feb 2019 13:13:33 -  1.368
> +++ bgpd.h15 Feb 2019 10:40:59 -
> @@ -638,6 +638,7 @@ struct kif {
>   u_int8_t if_type;
>   u_int8_t link_state;
>   u_int8_t nh_reachable;  /* for nexthop verification */
> + u_int8_t depend_state;  /* for session depend on */
>  };
>  
>  struct session_up {
> Index: kroute.c
> ===
> RCS file: /cvs/src/usr.sbin/bgpd/kroute.c,v
> retrieving revision 1.230
> diff -u -p -r1.230 kroute.c
> --- kroute.c  11 Feb 2019 15:44:25 -  1.230
> +++ kroute.c  15 Feb 2019 10:50:24 -
> @@ -25,6 +25,7 @@
>  #include 
>  #include 
>  #include 
> +#include 
>  #include 
>  #include 
>  #include 
> @@ -154,7 +155,6 @@ intkif_kr_remove(struct 
> kroute_node 
>  int   kif_kr6_insert(struct kroute6_node *);
>  int   kif_kr6_remove(struct kroute6_node *);
>  
> -int   kif_validate(struct kif *);
>  int   kroute_validate(struct kroute *);
>  int   kroute6_validate(struct kroute6 *);
>  void  knexthop_validate(struct ktable *,
> @@ -2235,7 +2235,7 @@ kif_kr6_remove(struct kroute6_node *kr)
>   * nexthop validation
>   */
>  
> -int
> +static int
>  kif_validate(struct kif *kif)
>  {
>   if (!(kif->flags & IFF_UP))
> @@ -2253,6 +2253,26 @@ kif_validate(struct kif *kif)
>   return (1);
>  }
>  
> +/*
> + * return 1 when the interface is up and the link state is up or unknwown
> + * except when this is a carp interface, then return 1 only when link state
> + * is up
> + */
> +static int
> +kif_depend_state(struct kif *kif)
> +{
> + if (!(kif->flags & IFF_UP))
> + return (0);
> +
> +
> + if (kif->if_type == IFT_CARP &&
> + kif->link_state == LINK_STATE_UNKNOWN)
> + return (0);
> +
> + return LINK_STATE_IS_UP(kif->link_state);
> +}
> +
> +
>  int
>  kroute_validate(struct kroute *kr)
>  {
> @@ -2654,6 +2674,7 @@ if_change(u_short ifindex, int flags, st
>   kif->k.if_type = ifd->ifi_type;
>   kif->k.rdomain = ifd->ifi_rdomain;
>   kif->k.baudrate = ifd->ifi_baudrate;
> + kif->k.depend_state = kif_depend_state(>k);
>  
>   send_imsg_session(IMSG_IFINFO, 0, >k, sizeof(kif->k));
>  
> @@ -3255,6 +3276,7 @@ fetchifs(int ifindex)
>   kif->k.rdomain = ifm.ifm_data.ifi_rdomain;
>   kif->k.baudrate = ifm.ifm_data.ifi_baudrate;
>   kif->k.nh_reachable = kif_validate(>k);
> + kif->k.depend_state = kif_depend_state(>k);
>  
>   if ((sa = rti_info[RTAX_IFP]) != NULL)
>   if (sa->sa_family == AF_LINK) {
> Index: session.c
> ===
> RCS file: /cvs/src/usr.sbin/bgpd/session.c,v
> retrieving revision 1.371
> diff -u -p -r1.371 session.c
> --- session.c 20 Jan 2019 23:27:48 -  1.371
> +++ session.c 15 Feb 2019 10:52:13 -
> @@ -24,7 +24,6 @@
>  #include 
>  #include 
>  #include 
> -#include 
>  #include 
>  #include 
>  #include 
> @@ -96,7 +95,6 @@ voidsession_up(struct peer *);
>  void session_down(struct peer *);
>  int  imsg_rde(int, u_int32_t, void *, u_int16_t);
>  void session_demote(struct peer *, int);
> -int  session_link_state_is_up(int, int, int);
>  
>  int   la_cmp(struct listen_addr *, struct listen_addr *);
>  struct peer  *getpeerbyip(struct sockaddr *);
> @@ -2812,8 +2810,7 @@ session_dispatch_imsg(struct imsgbuf *ib
>   sizeof(struct kif))
>   fatalx("IFINFO imsg with wrong len");
>   kif = imsg.data;
> - depend_ok = session_link_state_is_up(kif->flags,
> - kif->if_type, kif->link_state);
> + depend_ok = kif->depend_state;
>  
>   for (p = peers; p != NULL; p = p->next)
>   if (!strcmp(p->conf.if_depend, kif->ifname)) {
> @@ -3319,23 +3316,4 @@ session_stop(struct peer *peer, u_int8_t
>   break;
>   }
>   bgp_fsm(peer, EVNT_STOP);
> -}
> -
> -/*
> - * return 1 when the interface is up
> - * and the link state is up or unknwown
> - * except when this is a carp interface, then
> - * return 1 only 

Re: locate.mklocatedb broken with LC_ALL!=C

2019-02-15 Thread Giovanni Bechis
ping...
any possible issue with millert@ diff ?
 Giovanni

On Sun, Oct 07, 2018 at 08:35:28PM -0600, Todd C. Miller wrote:
> On Sun, 07 Oct 2018 17:08:06 +0200, Marc Espie wrote:
> 
> > Specifically, the only part that cares about
> > locale is sort, and it's definitely correct in fixing
> > it's not run on an utf-8 file.
> 
> Agreed.  How about the following?
> 
>  - todd
> 
> Index: usr.bin/locate/locate/mklocatedb.sh
> ===
> RCS file: /cvs/src/usr.bin/locate/locate/mklocatedb.sh,v
> retrieving revision 1.13
> diff -u -p -u -r1.13 mklocatedb.sh
> --- usr.bin/locate/locate/mklocatedb.sh   18 Mar 2007 20:13:49 -  
> 1.13
> +++ usr.bin/locate/locate/mklocatedb.sh   8 Oct 2018 02:34:52 -
> @@ -66,7 +66,8 @@ filelist=`mktemp ${TMPDIR=/tmp}/_filelis
>  }
>  trap 'rm -f $bigrams $filelist' 0 1 2 3 5 10 15
>  
> -if $sortcmd $sortopt > $filelist; then
> +# Run sort in the C locale or binary data may be interpreted as UTF-8
> +if LC_ALL=C $sortcmd $sortopt > $filelist; then
>  $bigram < $filelist | $sort -nr | 
>  awk -Ft 'BEGIN { ORS = "" } NR <= 128 { print $2 }' > 
> $bigrams &&
>  $code $bigrams < $filelist 


signature.asc
Description: PGP signature


bgpd, protability and sockaddr sa_len

2019-02-15 Thread Claudio Jeker
Another diff to ease portability of bgpd. The sa_len field in struct
sockaddr does not exist on Linux so instead of using it pass a length to
the function (e.g. like bind(2) and connect(2) and do the same when
passing around struct sockaddr_storage in the listener case.
The remaining sa_len, sin_len, sin6_len and ss_len usages are in very
OpenBSD specific files.

-- 
:wq Claudio

Index: bgpd.h
===
RCS file: /cvs/src/usr.sbin/bgpd/bgpd.h,v
retrieving revision 1.369
diff -u -p -r1.369 bgpd.h
--- bgpd.h  15 Feb 2019 11:38:06 -  1.369
+++ bgpd.h  15 Feb 2019 13:51:28 -
@@ -220,11 +220,12 @@ struct bgpd_addr {
 #defineLISTENER_LISTENING  0x02
 
 struct listen_addr {
-   TAILQ_ENTRY(listen_addr) entry;
-   struct sockaddr_storage  sa;
-   int  fd;
-   enum reconf_action   reconf;
-   u_int8_t flags;
+   TAILQ_ENTRY(listen_addr)entry;
+   struct sockaddr_storage sa;
+   int fd;
+   enum reconf_action  reconf;
+   socklen_t   sa_len;
+   u_int8_tflags;
 };
 
 TAILQ_HEAD(listen_addrs, listen_addr);
@@ -1254,7 +1255,7 @@ intset_equal(const struct 
set_table 
 /* util.c */
 const char *log_addr(const struct bgpd_addr *);
 const char *log_in6addr(const struct in6_addr *);
-const char *log_sockaddr(struct sockaddr *);
+const char *log_sockaddr(struct sockaddr *, socklen_t);
 const char *log_as(u_int32_t);
 const char *log_rd(u_int64_t);
 const char *log_ext_subtype(u_int8_t, u_int8_t);
@@ -1288,7 +1289,7 @@ intaid2afi(u_int8_t, u_int16_t *, u_i
 int afi2aid(u_int16_t, u_int8_t, u_int8_t *);
 sa_family_t aid2af(u_int8_t);
 int af2aid(sa_family_t, u_int8_t, u_int8_t *);
-struct sockaddr*addr2sa(struct bgpd_addr *, u_int16_t);
+struct sockaddr*addr2sa(struct bgpd_addr *, u_int16_t, socklen_t *);
 voidsa2addr(struct sockaddr *, struct bgpd_addr *);
 uint64_tift2ifm(uint8_t);
 const char *get_media_descr(uint64_t);
Index: config.c
===
RCS file: /cvs/src/usr.sbin/bgpd/config.c,v
retrieving revision 1.81
diff -u -p -r1.81 config.c
--- config.c12 Feb 2019 09:00:21 -  1.81
+++ config.c15 Feb 2019 13:43:42 -
@@ -397,7 +397,7 @@ prepare_listeners(struct bgpd_config *co
la->fd = -1;
la->flags = DEFAULT_LISTENER;
la->reconf = RECONF_REINIT;
-   la->sa.ss_len = sizeof(struct sockaddr_in);
+   la->sa_len = sizeof(struct sockaddr_in);
((struct sockaddr_in *)>sa)->sin_family = AF_INET;
((struct sockaddr_in *)>sa)->sin_addr.s_addr =
htonl(INADDR_ANY);
@@ -409,7 +409,7 @@ prepare_listeners(struct bgpd_config *co
la->fd = -1;
la->flags = DEFAULT_LISTENER;
la->reconf = RECONF_REINIT;
-   la->sa.ss_len = sizeof(struct sockaddr_in6);
+   la->sa_len = sizeof(struct sockaddr_in6);
((struct sockaddr_in6 *)>sa)->sin6_family = AF_INET6;
((struct sockaddr_in6 *)>sa)->sin6_port = htons(BGP_PORT);
TAILQ_INSERT_TAIL(conf->listen_addrs, la, entry);
@@ -437,24 +437,25 @@ prepare_listeners(struct bgpd_config *co
, sizeof(opt)) == -1)
fatal("setsockopt SO_REUSEADDR");
 
-   if (bind(la->fd, (struct sockaddr *)>sa, la->sa.ss_len) ==
+   if (bind(la->fd, (struct sockaddr *)>sa, la->sa_len) ==
-1) {
switch (la->sa.ss_family) {
case AF_INET:
log_warn("cannot bind to %s:%u",
-   log_sockaddr((struct sockaddr *)>sa),
-   ntohs(((struct sockaddr_in *)
+   log_sockaddr((struct sockaddr *)>sa,
+   la->sa_len), ntohs(((struct sockaddr_in *)
>sa)->sin_port));
break;
case AF_INET6:
log_warn("cannot bind to [%s]:%u",
-   log_sockaddr((struct sockaddr *)>sa),
-   ntohs(((struct sockaddr_in6 *)
+   log_sockaddr((struct sockaddr *)>sa,
+   la->sa_len), ntohs(((struct sockaddr_in6 *)
>sa)->sin6_port));
break;
default:
log_warn("cannot bind to 

Re: PKG_SIGN(1) - D argument

2019-02-15 Thread Marc Espie
On Fri, Feb 15, 2019 at 11:55:59AM +0100, Oleg Pahl wrote:
> Hi @all,
> 
> Is it ok, that on man page *PKG_SIGN(1)* there is*[-D name=[value]]*
> argument,
> 
> but there is no info about value of arg. below ... (I mean what kind of
> value's is possible to use with -D)
> 
> I think, that its will be better to put this Info on man page. Not just for
> me =)

There are options intentionally left undocumented in a lot of places.
Sometimes they are not intended for public consumption for instance (non
regress test comes to mind) but they're part of the command syntax anyway.

Have fun finding all the places where this happens, pkg_sign(1) is definitely
not the only command with undocumented options.



Re: dd conv=fsync

2019-02-15 Thread Klemens Nanni
On Fri, Feb 15, 2019 at 01:28:15PM +0100, Alexander Bluhm wrote:
> We should not implement the magic which device allows fsync(2) into
> dd(1).  Just do what the user says, if it is nonsense, give him an
> error.
Seems reasonable to me.

> > I know this wording is similar to fsync(2), but I think I'd prefer just a
> > reference. The output may not be permanent storage.
I agree with tedu.

OK kn



Re: dd conv=fsync

2019-02-15 Thread Alexander Bluhm
On Thu, Feb 14, 2019 at 05:20:13PM -0500, Ted Unangst wrote:
> What does gnu dd do if the output is stdout? Is it an error?

On Linux it fails with an error.

linux$ yes | dd count=4 bs=1 conv=fsync
y
y
dd: fsync failed for 'standard output': Invalid argument
4+0 records in
4+0 records out
4 bytes copied, 0.0004733 s, 8.5 kB/s
linux$ echo $?
1

On OpenBSD calling fsync(2) with a terminal works fine, but it fails
with a pipe.

openbsd$ yes | dd count=4 bs=1 conv=fsync  
y
y
4+0 records in
4+0 records out
4 bytes transferred in 0.001 secs (2400 bytes/sec)

openbsd$ yes | dd count=4 bs=1 conv=fsync | cat
dd: fsync stdout: Invalid argument
4+0 records in
4+0 records out
4 bytes transferred in 0.000 secs (4796 bytes/sec)
y
y

> Should there be an fstat check to make sure
> it's a regular file?

We should not implement the magic which device allows fsync(2) into
dd(1).  Just do what the user says, if it is nonsense, give him an
error.

> I know this wording is similar to fsync(2), but I think I'd prefer just a
> reference. The output may not be permanent storage. What about
> 
> Call
> .Xr fsync 2
> on the output file before exiting.

Sure, new diff.

ok?

bluhm

Index: bin/dd/args.c
===
RCS file: /data/mirror/openbsd/cvs/src/bin/dd/args.c,v
retrieving revision 1.30
diff -u -p -r1.30 args.c
--- bin/dd/args.c   25 Jul 2018 15:09:48 -  1.30
+++ bin/dd/args.c   14 Feb 2019 15:05:18 -
@@ -274,6 +274,7 @@ static const struct conv {
{ "ascii",  C_ASCII,C_EBCDIC,   e2a_POSIX },
{ "block",  C_BLOCK,C_UNBLOCK,  NULL },
{ "ebcdic", C_EBCDIC,   C_ASCII,a2e_POSIX },
+   { "fsync",  C_FSYNC,0,  NULL },
{ "ibm",C_EBCDIC,   C_ASCII,a2ibm_POSIX },
{ "lcase",  C_LCASE,C_UCASE,NULL },
{ "osync",  C_OSYNC,C_BS,   NULL },
Index: bin/dd/dd.1
===
RCS file: /data/mirror/openbsd/cvs/src/bin/dd/dd.1,v
retrieving revision 1.33
diff -u -p -r1.33 dd.1
--- bin/dd/dd.1 17 Aug 2016 21:23:01 -  1.33
+++ bin/dd/dd.1 15 Feb 2019 12:17:29 -
@@ -203,6 +203,10 @@ is a slightly different mapping, which i
 .At V
 .Cm ibm
 value.
+.It Cm fsync
+Call
+.Xr fsync 2
+on the output file before exiting.
 .It Cm lcase
 Transform uppercase characters into lowercase characters.
 .It Cm noerror
Index: bin/dd/dd.c
===
RCS file: /data/mirror/openbsd/cvs/src/bin/dd/dd.c,v
retrieving revision 1.25
diff -u -p -r1.25 dd.c
--- bin/dd/dd.c 23 Jul 2018 23:09:37 -  1.25
+++ bin/dd/dd.c 14 Feb 2019 18:13:55 -
@@ -347,6 +347,10 @@ dd_close(void)
}
if (out.dbcnt)
dd_out(1);
+   if (ddflags & C_FSYNC) {
+   if (fsync(out.fd) == -1)
+   err(1, "fsync %s", out.name);
+   }
 }
 
 void
Index: bin/dd/dd.h
===
RCS file: /data/mirror/openbsd/cvs/src/bin/dd/dd.h,v
retrieving revision 1.8
diff -u -p -r1.8 dd.h
--- bin/dd/dd.h 13 Aug 2017 02:06:42 -  1.8
+++ bin/dd/dd.h 14 Feb 2019 15:05:18 -
@@ -96,3 +96,4 @@ typedef struct {
 #defineC_STATUS0x20
 #defineC_NOXFER0x40
 #defineC_NOINFO0x80
+#defineC_FSYNC 0x100



bgpd 'depend on' refactor

2019-02-15 Thread Claudio Jeker
To make bgpd more portable it is better to move all the link state code
into kroute.c. Especially for something as simple as a single up / down
flag.  This is doing that and removes the net/if_types.h include from
session.c. Result should be the same just computation is moved.

OK?
-- 
:wq Claudio

Index: bgpd.h
===
RCS file: /cvs/src/usr.sbin/bgpd/bgpd.h,v
retrieving revision 1.368
diff -u -p -r1.368 bgpd.h
--- bgpd.h  14 Feb 2019 13:13:33 -  1.368
+++ bgpd.h  15 Feb 2019 10:40:59 -
@@ -638,6 +638,7 @@ struct kif {
u_int8_t if_type;
u_int8_t link_state;
u_int8_t nh_reachable;  /* for nexthop verification */
+   u_int8_t depend_state;  /* for session depend on */
 };
 
 struct session_up {
Index: kroute.c
===
RCS file: /cvs/src/usr.sbin/bgpd/kroute.c,v
retrieving revision 1.230
diff -u -p -r1.230 kroute.c
--- kroute.c11 Feb 2019 15:44:25 -  1.230
+++ kroute.c15 Feb 2019 10:50:24 -
@@ -25,6 +25,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -154,7 +155,6 @@ int  kif_kr_remove(struct kroute_node 
 int kif_kr6_insert(struct kroute6_node *);
 int kif_kr6_remove(struct kroute6_node *);
 
-int kif_validate(struct kif *);
 int kroute_validate(struct kroute *);
 int kroute6_validate(struct kroute6 *);
 voidknexthop_validate(struct ktable *,
@@ -2235,7 +2235,7 @@ kif_kr6_remove(struct kroute6_node *kr)
  * nexthop validation
  */
 
-int
+static int
 kif_validate(struct kif *kif)
 {
if (!(kif->flags & IFF_UP))
@@ -2253,6 +2253,26 @@ kif_validate(struct kif *kif)
return (1);
 }
 
+/*
+ * return 1 when the interface is up and the link state is up or unknwown
+ * except when this is a carp interface, then return 1 only when link state
+ * is up
+ */
+static int
+kif_depend_state(struct kif *kif)
+{
+   if (!(kif->flags & IFF_UP))
+   return (0);
+
+
+   if (kif->if_type == IFT_CARP &&
+   kif->link_state == LINK_STATE_UNKNOWN)
+   return (0);
+
+   return LINK_STATE_IS_UP(kif->link_state);
+}
+
+
 int
 kroute_validate(struct kroute *kr)
 {
@@ -2654,6 +2674,7 @@ if_change(u_short ifindex, int flags, st
kif->k.if_type = ifd->ifi_type;
kif->k.rdomain = ifd->ifi_rdomain;
kif->k.baudrate = ifd->ifi_baudrate;
+   kif->k.depend_state = kif_depend_state(>k);
 
send_imsg_session(IMSG_IFINFO, 0, >k, sizeof(kif->k));
 
@@ -3255,6 +3276,7 @@ fetchifs(int ifindex)
kif->k.rdomain = ifm.ifm_data.ifi_rdomain;
kif->k.baudrate = ifm.ifm_data.ifi_baudrate;
kif->k.nh_reachable = kif_validate(>k);
+   kif->k.depend_state = kif_depend_state(>k);
 
if ((sa = rti_info[RTAX_IFP]) != NULL)
if (sa->sa_family == AF_LINK) {
Index: session.c
===
RCS file: /cvs/src/usr.sbin/bgpd/session.c,v
retrieving revision 1.371
diff -u -p -r1.371 session.c
--- session.c   20 Jan 2019 23:27:48 -  1.371
+++ session.c   15 Feb 2019 10:52:13 -
@@ -24,7 +24,6 @@
 #include 
 #include 
 #include 
-#include 
 #include 
 #include 
 #include 
@@ -96,7 +95,6 @@ void  session_up(struct peer *);
 void   session_down(struct peer *);
 intimsg_rde(int, u_int32_t, void *, u_int16_t);
 void   session_demote(struct peer *, int);
-intsession_link_state_is_up(int, int, int);
 
 int la_cmp(struct listen_addr *, struct listen_addr *);
 struct peer*getpeerbyip(struct sockaddr *);
@@ -2812,8 +2810,7 @@ session_dispatch_imsg(struct imsgbuf *ib
sizeof(struct kif))
fatalx("IFINFO imsg with wrong len");
kif = imsg.data;
-   depend_ok = session_link_state_is_up(kif->flags,
-   kif->if_type, kif->link_state);
+   depend_ok = kif->depend_state;
 
for (p = peers; p != NULL; p = p->next)
if (!strcmp(p->conf.if_depend, kif->ifname)) {
@@ -3319,23 +3316,4 @@ session_stop(struct peer *peer, u_int8_t
break;
}
bgp_fsm(peer, EVNT_STOP);
-}
-
-/*
- * return 1 when the interface is up
- * and the link state is up or unknwown
- * except when this is a carp interface, then
- * return 1 only when link state is up
- */
-int
-session_link_state_is_up(int flags, int type, int link_state)
-{
-   if (!(flags & IFF_UP))
-   return (0);
-
-   if (type == IFT_CARP &&
-   link_state == LINK_STATE_UNKNOWN)
-   return (0);
-
-   

PKG_SIGN(1) - D argument

2019-02-15 Thread Oleg Pahl

Hi @all,

Is it ok, that on man page *PKG_SIGN(1)* there is*[-D name=[value]]* 
argument,


but there is no info about value of arg. below ... (I mean what kind of 
value's is possible to use with -D)


I think, that its will be better to put this Info on man page. Not just 
for me =)


Many thx for all.

BR,

Oleg Pahl



Re: man -> vim

2019-02-15 Thread Andreas Kusalananda Kähäri
On Fri, Feb 15, 2019 at 11:19:57AM +0100, Oleg Pahl wrote:
> Hi @all,
> 
> Today I try to work with man pages using *vim*.
> 
> *# man man | vim -*
> 
> why i see raw (a lot of special char.) data by default? is it ok?
> 
> *# ma man | less *
> 
> I see no special characters. looks very good.
> 
> Is it possible to convert *raw* data of man page to normal format (for
> *vim*) with one command?
> 
> BR,
> 
> -op

man man | col -b | vim -

See the col(1) manual.  This is also mentioned in the mandoc(1) manual,
in the "ASCII Output" section.


-- 
Andreas Kusalananda Kähäri,
National Bioinformatics Infrastructure Sweden (NBIS),
Uppsala University, Sweden.



Re: man -> vim

2019-02-15 Thread Oleg Pahl

Perfect !

Thanks all !

On 2/15/19 11:35 AM, Otto Moerbeek wrote:

On Fri, Feb 15, 2019 at 11:19:57AM +0100, Oleg Pahl wrote:


Hi @all,

Today I try to work with man pages using *vim*.

*# man man | vim -*

why i see raw (a lot of special char.) data by default? is it ok?

*# ma man | less *

I see no special characters. looks very good.

Is it possible to convert *raw* data of man page to normal format (for
*vim*) with one command?

BR,

-op


Pipe through col -b

-Otto




Re: man -> vim

2019-02-15 Thread Otto Moerbeek
On Fri, Feb 15, 2019 at 11:19:57AM +0100, Oleg Pahl wrote:

> Hi @all,
> 
> Today I try to work with man pages using *vim*.
> 
> *# man man | vim -*
> 
> why i see raw (a lot of special char.) data by default? is it ok?
> 
> *# ma man | less *
> 
> I see no special characters. looks very good.
> 
> Is it possible to convert *raw* data of man page to normal format (for
> *vim*) with one command?
> 
> BR,
> 
> -op
> 

Pipe through col -b

-Otto



Re: man -> vim

2019-02-15 Thread Martijn van Duren
On 2/15/19 11:19 AM, Oleg Pahl wrote:
> Hi @all,
> 
> Today I try to work with man pages using *vim*.

What do you mean with work with? Do you mean you want to edit them, or
you want to read them?
If you want to edit them, just edit the source
/usr/src/usr.bin/mandoc/man.1 (you need to have a local copy of the
repo).
> 
> *# man man | vim -*
> 
> why i see raw (a lot of special char.) data by default? is it ok?

Yes, those chars are used to create the pretty formatting (e.g. bold
printing or underlining).
> 
> *# ma man | less *
> 
> I see no special characters. looks very good.

less doesn't interpret those characters and blindly forwards them to
the terminal, allow you to see nicely formatted text.
> 
> Is it possible to convert *raw* data of man page to normal format (for *vim*) 
> with one command?
> 
I'm not 100% sure what you want to do, but if you want it to be a
little more readable in vim, the following command helps:
:%s/.^H//g
Note that ^H can be achieved via control+v+h
> BR,
> 
> -op
> 
martijn@



man -> vim

2019-02-15 Thread Oleg Pahl

Hi @all,

Today I try to work with man pages using *vim*.

*# man man | vim -*

why i see raw (a lot of special char.) data by default? is it ok?

*# ma man | less *

I see no special characters. looks very good.

Is it possible to convert *raw* data of man page to normal format (for 
*vim*) with one command?


BR,

-op



Re: dd conv=fsync

2019-02-15 Thread Brent Cook
On Thu, Feb 14, 2019 at 4:21 PM Ted Unangst  wrote:

> Alexander Bluhm wrote:
> > GNU dd has the conv=fsync feature which does an fsync(2) after final
> > write to output.  I find this useful for write performance measurement
> > through the file system without buffer cache optimization.  Others
> > may like the reliable storage guarantee of fsync(2).
> >
> > Do we want dd conv=fsync in OpenBSD?
>
> What does gnu dd do if the output is stdout? Is it an error?
>

> With this patch, I get dd: fsync stdout: Invalid argument
>

gnu dd prints something similar to stderr, and returns exit code 1.

dd: fsync failed for 'standard output': Invalid argument
3+1 records in
3+1 records out
1784 bytes (1.8 kB, 1.7 KiB) copied, 9.4827e-05 s, 18.8 MB/s



> after the transfer is complete. Should there be an fstat check to make sure
> it's a regular file?
>
> > +.It Cm fsync
> > +Write output to permanent storage device before finishing.
>
> I know this wording is similar to fsync(2), but I think I'd prefer just a
> reference. The output may not be permanent storage. What about
>
> Call
> .Xr fsync 2
> on the output file before exiting.
>
>
>