Re: ospf6d: convert sendto() to sendmsg()
On Wed, Dec 11, 2019 at 04:52:53PM +0100, Denis Fondras wrote: > Use sendmsg() instead of sendto() like ospfd(8) does. > > Index: database.c > === > RCS file: /cvs/src/usr.sbin/ospf6d/database.c,v > retrieving revision 1.16 > diff -u -p -r1.16 database.c > --- database.c10 May 2019 13:50:34 - 1.16 > +++ database.c8 Dec 2019 14:55:57 - > @@ -147,7 +147,7 @@ send_db_description(struct nbr *nbr) > goto fail; > > /* transmit packet */ > - ret = send_packet(nbr->iface, buf->buf, buf->wpos, &dst); > + ret = send_packet(nbr->iface, buf, &dst); > done: > ibuf_free(buf); > return (ret); > Index: hello.c > === > RCS file: /cvs/src/usr.sbin/ospf6d/hello.c,v > retrieving revision 1.18 > diff -u -p -r1.18 hello.c > --- hello.c 22 Feb 2018 07:43:29 - 1.18 > +++ hello.c 8 Dec 2019 14:55:57 - > @@ -104,7 +104,7 @@ send_hello(struct iface *iface) > if (upd_ospf_hdr(buf, iface)) > goto fail; > > - ret = send_packet(iface, buf->buf, buf->wpos, &dst); > + ret = send_packet(iface, buf, &dst); > > ibuf_free(buf); > return (ret); > Index: lsack.c > === > RCS file: /cvs/src/usr.sbin/ospf6d/lsack.c,v > retrieving revision 1.6 > diff -u -p -r1.6 lsack.c > --- lsack.c 25 Oct 2014 03:23:49 - 1.6 > +++ lsack.c 8 Dec 2019 14:55:57 - > @@ -55,7 +55,7 @@ send_ls_ack(struct iface *iface, struct > if (upd_ospf_hdr(buf, iface)) > goto fail; > > - ret = send_packet(iface, buf->buf, buf->wpos, &addr); > + ret = send_packet(iface, buf, &addr); > > ibuf_free(buf); > return (ret); > Index: lsreq.c > === > RCS file: /cvs/src/usr.sbin/ospf6d/lsreq.c,v > retrieving revision 1.9 > diff -u -p -r1.9 lsreq.c > --- lsreq.c 10 May 2019 13:50:34 - 1.9 > +++ lsreq.c 8 Dec 2019 14:55:58 - > @@ -77,7 +77,7 @@ send_ls_req(struct nbr *nbr) > if (upd_ospf_hdr(buf, nbr->iface)) > goto fail; > > - ret = send_packet(nbr->iface, buf->buf, buf->wpos, &dst); > + ret = send_packet(nbr->iface, buf, &dst); > > ibuf_free(buf); > return (ret); > Index: lsupdate.c > === > RCS file: /cvs/src/usr.sbin/ospf6d/lsupdate.c,v > retrieving revision 1.13 > diff -u -p -r1.13 lsupdate.c > --- lsupdate.c28 Jan 2015 22:03:17 - 1.13 > +++ lsupdate.c8 Dec 2019 14:55:58 - > @@ -227,7 +227,7 @@ send_ls_update(struct ibuf *buf, struct > if (upd_ospf_hdr(buf, iface)) > goto fail; > > - ret = send_packet(iface, buf->buf, buf->wpos, &addr); > + ret = send_packet(iface, buf, &addr); > > ibuf_free(buf); > return (ret); > Index: ospfe.h > === > RCS file: /cvs/src/usr.sbin/ospf6d/ospfe.h,v > retrieving revision 1.19 > diff -u -p -r1.19 ospfe.h > --- ospfe.h 25 Oct 2014 03:23:49 - 1.19 > +++ ospfe.h 8 Dec 2019 14:55:58 - > @@ -228,7 +228,7 @@ struct lsa_hdr*lsa_hdr_new(void); > /* packet.c */ > int gen_ospf_hdr(struct ibuf *, struct iface *, u_int8_t); > int upd_ospf_hdr(struct ibuf *, struct iface *); > -int send_packet(struct iface *, void *, size_t, struct in6_addr *); > +int send_packet(struct iface *, struct ibuf *, struct in6_addr *); > void recv_packet(int, short, void *); > > char *pkt_ptr; /* packet buffer */ > Index: packet.c > === > RCS file: /cvs/src/usr.sbin/ospf6d/packet.c,v > retrieving revision 1.15 > diff -u -p -r1.15 packet.c > --- packet.c 10 May 2019 01:29:31 - 1.15 > +++ packet.c 8 Dec 2019 14:55:58 - > @@ -78,10 +78,12 @@ upd_ospf_hdr(struct ibuf *buf, struct if > > /* send and receive packets */ > int > -send_packet(struct iface *iface, void *pkt, size_t len, > +send_packet(struct iface *iface, struct ibuf *buf, > struct in6_addr *dst) > { > - struct sockaddr_in6 sa6; > + struct sockaddr_in6 sa6; > + struct msghdr msg; > + struct ioveciov[2]; There is only one iov in use so make this iov[1]; > > /* setup buffer */ > bzero(&sa6, sizeof(sa6)); > @@ -102,8 +104,15 @@ send_packet(struct iface *iface, void *p > return (-1); > } > > - if (sendto(iface->fd, pkt, len, 0, (struct sockaddr *)&sa6, > - sizeof(sa6)) == -1) { > + bzero(&msg, sizeof(msg)); > + msg.msg_name = &sa6; > + msg.msg_namelen = sizeof(sa6); > + iov[0].iov_base = buf->buf; > + iov[0].iov_len = ibuf_size(buf); > + msg.msg_iov = iov; > + msg.msg_iov
Re: ospf6d: convert sendto() to sendmsg()
On Wed, Dec 11, 2019 at 07:06:26PM +0100, Claudio Jeker wrote: > While it makes sense to pass the ibuf like in ospfd I see no reason to > switch to sendmsg(). In ospfd this is done to prepend the IP header but > that seems not needed here. Is there another reason to switch to > sendmsg()? > Nothing more than what deraadt@ said, just make the code look similar to ospfd. > -- > :wq Claudio
Re: ospf6d: convert sendto() to sendmsg()
Claudio Jeker wrote: > On Wed, Dec 11, 2019 at 04:52:53PM +0100, Denis Fondras wrote: > > Use sendmsg() instead of sendto() like ospfd(8) does. > > > > Index: database.c > > === > > RCS file: /cvs/src/usr.sbin/ospf6d/database.c,v > > retrieving revision 1.16 > > diff -u -p -r1.16 database.c > > --- database.c 10 May 2019 13:50:34 - 1.16 > > +++ database.c 8 Dec 2019 14:55:57 - > > @@ -147,7 +147,7 @@ send_db_description(struct nbr *nbr) > > goto fail; > > > > /* transmit packet */ > > - ret = send_packet(nbr->iface, buf->buf, buf->wpos, &dst); > > + ret = send_packet(nbr->iface, buf, &dst); > > done: > > ibuf_free(buf); > > return (ret); > > Index: hello.c > > === > > RCS file: /cvs/src/usr.sbin/ospf6d/hello.c,v > > retrieving revision 1.18 > > diff -u -p -r1.18 hello.c > > --- hello.c 22 Feb 2018 07:43:29 - 1.18 > > +++ hello.c 8 Dec 2019 14:55:57 - > > @@ -104,7 +104,7 @@ send_hello(struct iface *iface) > > if (upd_ospf_hdr(buf, iface)) > > goto fail; > > > > - ret = send_packet(iface, buf->buf, buf->wpos, &dst); > > + ret = send_packet(iface, buf, &dst); > > > > ibuf_free(buf); > > return (ret); > > Index: lsack.c > > === > > RCS file: /cvs/src/usr.sbin/ospf6d/lsack.c,v > > retrieving revision 1.6 > > diff -u -p -r1.6 lsack.c > > --- lsack.c 25 Oct 2014 03:23:49 - 1.6 > > +++ lsack.c 8 Dec 2019 14:55:57 - > > @@ -55,7 +55,7 @@ send_ls_ack(struct iface *iface, struct > > if (upd_ospf_hdr(buf, iface)) > > goto fail; > > > > - ret = send_packet(iface, buf->buf, buf->wpos, &addr); > > + ret = send_packet(iface, buf, &addr); > > > > ibuf_free(buf); > > return (ret); > > Index: lsreq.c > > === > > RCS file: /cvs/src/usr.sbin/ospf6d/lsreq.c,v > > retrieving revision 1.9 > > diff -u -p -r1.9 lsreq.c > > --- lsreq.c 10 May 2019 13:50:34 - 1.9 > > +++ lsreq.c 8 Dec 2019 14:55:58 - > > @@ -77,7 +77,7 @@ send_ls_req(struct nbr *nbr) > > if (upd_ospf_hdr(buf, nbr->iface)) > > goto fail; > > > > - ret = send_packet(nbr->iface, buf->buf, buf->wpos, &dst); > > + ret = send_packet(nbr->iface, buf, &dst); > > > > ibuf_free(buf); > > return (ret); > > Index: lsupdate.c > > === > > RCS file: /cvs/src/usr.sbin/ospf6d/lsupdate.c,v > > retrieving revision 1.13 > > diff -u -p -r1.13 lsupdate.c > > --- lsupdate.c 28 Jan 2015 22:03:17 - 1.13 > > +++ lsupdate.c 8 Dec 2019 14:55:58 - > > @@ -227,7 +227,7 @@ send_ls_update(struct ibuf *buf, struct > > if (upd_ospf_hdr(buf, iface)) > > goto fail; > > > > - ret = send_packet(iface, buf->buf, buf->wpos, &addr); > > + ret = send_packet(iface, buf, &addr); > > > > ibuf_free(buf); > > return (ret); > > Index: ospfe.h > > === > > RCS file: /cvs/src/usr.sbin/ospf6d/ospfe.h,v > > retrieving revision 1.19 > > diff -u -p -r1.19 ospfe.h > > --- ospfe.h 25 Oct 2014 03:23:49 - 1.19 > > +++ ospfe.h 8 Dec 2019 14:55:58 - > > @@ -228,7 +228,7 @@ struct lsa_hdr *lsa_hdr_new(void); > > /* packet.c */ > > int gen_ospf_hdr(struct ibuf *, struct iface *, u_int8_t); > > int upd_ospf_hdr(struct ibuf *, struct iface *); > > -int send_packet(struct iface *, void *, size_t, struct in6_addr *); > > +int send_packet(struct iface *, struct ibuf *, struct in6_addr *); > > voidrecv_packet(int, short, void *); > > > > char *pkt_ptr; /* packet buffer */ > > Index: packet.c > > === > > RCS file: /cvs/src/usr.sbin/ospf6d/packet.c,v > > retrieving revision 1.15 > > diff -u -p -r1.15 packet.c > > --- packet.c10 May 2019 01:29:31 - 1.15 > > +++ packet.c8 Dec 2019 14:55:58 - > > @@ -78,10 +78,12 @@ upd_ospf_hdr(struct ibuf *buf, struct if > > > > /* send and receive packets */ > > int > > -send_packet(struct iface *iface, void *pkt, size_t len, > > +send_packet(struct iface *iface, struct ibuf *buf, > > struct in6_addr *dst) > > { > > - struct sockaddr_in6 sa6; > > + struct sockaddr_in6 sa6; > > + struct msghdr msg; > > + struct ioveciov[2]; > > > > /* setup buffer */ > > bzero(&sa6, sizeof(sa6)); > > @@ -102,8 +104,15 @@ send_packet(struct iface *iface, void *p > > return (-1); > > } > > > > - if (sendto(iface->fd, pkt, len, 0, (struct sockaddr *)&sa6, > > - sizeof(sa6)) == -1) { > > + bzero(&msg, sizeof(msg)); > > + msg.msg_name = &
Re: ospf6d: convert sendto() to sendmsg()
On Wed, Dec 11, 2019 at 04:52:53PM +0100, Denis Fondras wrote: > Use sendmsg() instead of sendto() like ospfd(8) does. > > Index: database.c > === > RCS file: /cvs/src/usr.sbin/ospf6d/database.c,v > retrieving revision 1.16 > diff -u -p -r1.16 database.c > --- database.c10 May 2019 13:50:34 - 1.16 > +++ database.c8 Dec 2019 14:55:57 - > @@ -147,7 +147,7 @@ send_db_description(struct nbr *nbr) > goto fail; > > /* transmit packet */ > - ret = send_packet(nbr->iface, buf->buf, buf->wpos, &dst); > + ret = send_packet(nbr->iface, buf, &dst); > done: > ibuf_free(buf); > return (ret); > Index: hello.c > === > RCS file: /cvs/src/usr.sbin/ospf6d/hello.c,v > retrieving revision 1.18 > diff -u -p -r1.18 hello.c > --- hello.c 22 Feb 2018 07:43:29 - 1.18 > +++ hello.c 8 Dec 2019 14:55:57 - > @@ -104,7 +104,7 @@ send_hello(struct iface *iface) > if (upd_ospf_hdr(buf, iface)) > goto fail; > > - ret = send_packet(iface, buf->buf, buf->wpos, &dst); > + ret = send_packet(iface, buf, &dst); > > ibuf_free(buf); > return (ret); > Index: lsack.c > === > RCS file: /cvs/src/usr.sbin/ospf6d/lsack.c,v > retrieving revision 1.6 > diff -u -p -r1.6 lsack.c > --- lsack.c 25 Oct 2014 03:23:49 - 1.6 > +++ lsack.c 8 Dec 2019 14:55:57 - > @@ -55,7 +55,7 @@ send_ls_ack(struct iface *iface, struct > if (upd_ospf_hdr(buf, iface)) > goto fail; > > - ret = send_packet(iface, buf->buf, buf->wpos, &addr); > + ret = send_packet(iface, buf, &addr); > > ibuf_free(buf); > return (ret); > Index: lsreq.c > === > RCS file: /cvs/src/usr.sbin/ospf6d/lsreq.c,v > retrieving revision 1.9 > diff -u -p -r1.9 lsreq.c > --- lsreq.c 10 May 2019 13:50:34 - 1.9 > +++ lsreq.c 8 Dec 2019 14:55:58 - > @@ -77,7 +77,7 @@ send_ls_req(struct nbr *nbr) > if (upd_ospf_hdr(buf, nbr->iface)) > goto fail; > > - ret = send_packet(nbr->iface, buf->buf, buf->wpos, &dst); > + ret = send_packet(nbr->iface, buf, &dst); > > ibuf_free(buf); > return (ret); > Index: lsupdate.c > === > RCS file: /cvs/src/usr.sbin/ospf6d/lsupdate.c,v > retrieving revision 1.13 > diff -u -p -r1.13 lsupdate.c > --- lsupdate.c28 Jan 2015 22:03:17 - 1.13 > +++ lsupdate.c8 Dec 2019 14:55:58 - > @@ -227,7 +227,7 @@ send_ls_update(struct ibuf *buf, struct > if (upd_ospf_hdr(buf, iface)) > goto fail; > > - ret = send_packet(iface, buf->buf, buf->wpos, &addr); > + ret = send_packet(iface, buf, &addr); > > ibuf_free(buf); > return (ret); > Index: ospfe.h > === > RCS file: /cvs/src/usr.sbin/ospf6d/ospfe.h,v > retrieving revision 1.19 > diff -u -p -r1.19 ospfe.h > --- ospfe.h 25 Oct 2014 03:23:49 - 1.19 > +++ ospfe.h 8 Dec 2019 14:55:58 - > @@ -228,7 +228,7 @@ struct lsa_hdr*lsa_hdr_new(void); > /* packet.c */ > int gen_ospf_hdr(struct ibuf *, struct iface *, u_int8_t); > int upd_ospf_hdr(struct ibuf *, struct iface *); > -int send_packet(struct iface *, void *, size_t, struct in6_addr *); > +int send_packet(struct iface *, struct ibuf *, struct in6_addr *); > void recv_packet(int, short, void *); > > char *pkt_ptr; /* packet buffer */ > Index: packet.c > === > RCS file: /cvs/src/usr.sbin/ospf6d/packet.c,v > retrieving revision 1.15 > diff -u -p -r1.15 packet.c > --- packet.c 10 May 2019 01:29:31 - 1.15 > +++ packet.c 8 Dec 2019 14:55:58 - > @@ -78,10 +78,12 @@ upd_ospf_hdr(struct ibuf *buf, struct if > > /* send and receive packets */ > int > -send_packet(struct iface *iface, void *pkt, size_t len, > +send_packet(struct iface *iface, struct ibuf *buf, > struct in6_addr *dst) > { > - struct sockaddr_in6 sa6; > + struct sockaddr_in6 sa6; > + struct msghdr msg; > + struct ioveciov[2]; > > /* setup buffer */ > bzero(&sa6, sizeof(sa6)); > @@ -102,8 +104,15 @@ send_packet(struct iface *iface, void *p > return (-1); > } > > - if (sendto(iface->fd, pkt, len, 0, (struct sockaddr *)&sa6, > - sizeof(sa6)) == -1) { > + bzero(&msg, sizeof(msg)); > + msg.msg_name = &sa6; > + msg.msg_namelen = sizeof(sa6); > + iov[0].iov_base = buf->buf; > + iov[0].iov_len = ibuf_size(buf); > + msg.msg_iov = iov; > + msg.msg_iovlen = 1; > + > + if (sendmsg(iface->fd, &msg, 0)
ospf6d: convert sendto() to sendmsg()
Use sendmsg() instead of sendto() like ospfd(8) does. Index: database.c === RCS file: /cvs/src/usr.sbin/ospf6d/database.c,v retrieving revision 1.16 diff -u -p -r1.16 database.c --- database.c 10 May 2019 13:50:34 - 1.16 +++ database.c 8 Dec 2019 14:55:57 - @@ -147,7 +147,7 @@ send_db_description(struct nbr *nbr) goto fail; /* transmit packet */ - ret = send_packet(nbr->iface, buf->buf, buf->wpos, &dst); + ret = send_packet(nbr->iface, buf, &dst); done: ibuf_free(buf); return (ret); Index: hello.c === RCS file: /cvs/src/usr.sbin/ospf6d/hello.c,v retrieving revision 1.18 diff -u -p -r1.18 hello.c --- hello.c 22 Feb 2018 07:43:29 - 1.18 +++ hello.c 8 Dec 2019 14:55:57 - @@ -104,7 +104,7 @@ send_hello(struct iface *iface) if (upd_ospf_hdr(buf, iface)) goto fail; - ret = send_packet(iface, buf->buf, buf->wpos, &dst); + ret = send_packet(iface, buf, &dst); ibuf_free(buf); return (ret); Index: lsack.c === RCS file: /cvs/src/usr.sbin/ospf6d/lsack.c,v retrieving revision 1.6 diff -u -p -r1.6 lsack.c --- lsack.c 25 Oct 2014 03:23:49 - 1.6 +++ lsack.c 8 Dec 2019 14:55:57 - @@ -55,7 +55,7 @@ send_ls_ack(struct iface *iface, struct if (upd_ospf_hdr(buf, iface)) goto fail; - ret = send_packet(iface, buf->buf, buf->wpos, &addr); + ret = send_packet(iface, buf, &addr); ibuf_free(buf); return (ret); Index: lsreq.c === RCS file: /cvs/src/usr.sbin/ospf6d/lsreq.c,v retrieving revision 1.9 diff -u -p -r1.9 lsreq.c --- lsreq.c 10 May 2019 13:50:34 - 1.9 +++ lsreq.c 8 Dec 2019 14:55:58 - @@ -77,7 +77,7 @@ send_ls_req(struct nbr *nbr) if (upd_ospf_hdr(buf, nbr->iface)) goto fail; - ret = send_packet(nbr->iface, buf->buf, buf->wpos, &dst); + ret = send_packet(nbr->iface, buf, &dst); ibuf_free(buf); return (ret); Index: lsupdate.c === RCS file: /cvs/src/usr.sbin/ospf6d/lsupdate.c,v retrieving revision 1.13 diff -u -p -r1.13 lsupdate.c --- lsupdate.c 28 Jan 2015 22:03:17 - 1.13 +++ lsupdate.c 8 Dec 2019 14:55:58 - @@ -227,7 +227,7 @@ send_ls_update(struct ibuf *buf, struct if (upd_ospf_hdr(buf, iface)) goto fail; - ret = send_packet(iface, buf->buf, buf->wpos, &addr); + ret = send_packet(iface, buf, &addr); ibuf_free(buf); return (ret); Index: ospfe.h === RCS file: /cvs/src/usr.sbin/ospf6d/ospfe.h,v retrieving revision 1.19 diff -u -p -r1.19 ospfe.h --- ospfe.h 25 Oct 2014 03:23:49 - 1.19 +++ ospfe.h 8 Dec 2019 14:55:58 - @@ -228,7 +228,7 @@ struct lsa_hdr *lsa_hdr_new(void); /* packet.c */ int gen_ospf_hdr(struct ibuf *, struct iface *, u_int8_t); int upd_ospf_hdr(struct ibuf *, struct iface *); -int send_packet(struct iface *, void *, size_t, struct in6_addr *); +int send_packet(struct iface *, struct ibuf *, struct in6_addr *); voidrecv_packet(int, short, void *); char *pkt_ptr; /* packet buffer */ Index: packet.c === RCS file: /cvs/src/usr.sbin/ospf6d/packet.c,v retrieving revision 1.15 diff -u -p -r1.15 packet.c --- packet.c10 May 2019 01:29:31 - 1.15 +++ packet.c8 Dec 2019 14:55:58 - @@ -78,10 +78,12 @@ upd_ospf_hdr(struct ibuf *buf, struct if /* send and receive packets */ int -send_packet(struct iface *iface, void *pkt, size_t len, +send_packet(struct iface *iface, struct ibuf *buf, struct in6_addr *dst) { - struct sockaddr_in6 sa6; + struct sockaddr_in6 sa6; + struct msghdr msg; + struct ioveciov[2]; /* setup buffer */ bzero(&sa6, sizeof(sa6)); @@ -102,8 +104,15 @@ send_packet(struct iface *iface, void *p return (-1); } - if (sendto(iface->fd, pkt, len, 0, (struct sockaddr *)&sa6, - sizeof(sa6)) == -1) { + bzero(&msg, sizeof(msg)); + msg.msg_name = &sa6; + msg.msg_namelen = sizeof(sa6); + iov[0].iov_base = buf->buf; + iov[0].iov_len = ibuf_size(buf); + msg.msg_iov = iov; + msg.msg_iovlen = 1; + + if (sendmsg(iface->fd, &msg, 0) == -1) { log_warn("send_packet: error sending packet on interface %s", iface->name); return (-1);