Page MenuHomeFreeBSD

D23577.diff
No OneTemporary

D23577.diff

Index: share/man/man4/divert.4
===================================================================
--- share/man/man4/divert.4
+++ share/man/man4/divert.4
@@ -155,6 +155,23 @@
.Pp
Binding to port numbers less than 1024 requires super-user access, as does
creating a socket of type SOCK_RAW.
+.Pp
+There are two options for
+.Xr setsockopt 2
+and
+.Xr getsockopt 2
+that can be used to set and get the send and receive buffer sizes.
+.Pp
+The options for send and receive are
+.Dv IP_DIVSENDBUF
+and
+.Dv IP_DIVRECVBUF
+respectively. As an example, to set these buffer sizes in a program:
+.Bd -literal
+unsigned long sndbuf = 8192, rcvbuf = 16384;
+setsockopt(s, IPPROTO_DIVERT, IP_DIVSENDBUF, &sndbuf, sizeof(sndbuf));
+setsockopt(s, IPPROTO_DIVERT, IP_DIVRECVBUF, &rcvbuf, sizeof(rcvbuf));
+.Ed
.Sh ERRORS
Writing to a divert socket can return these errors, along with
the usual errors possible when writing raw packets:
Index: sys/netinet/in.h
===================================================================
--- sys/netinet/in.h
+++ sys/netinet/in.h
@@ -498,6 +498,10 @@
#define IP_RECVFLOWID 93 /* bool; receive IP flowid/flowtype w/ datagram */
#define IP_RECVRSSBUCKETID 94 /* bool; receive IP RSS bucket id w/ datagram */
+/* Divert definitions */
+#define IP_DIVSENDBUF 95 /* u_long; send divert buffer size */
+#define IP_DIVRECVBUF 96 /* u_long; receive divert buffer size */
+
/*
* Defaults and limits for options
*/
Index: sys/netinet/ip_divert.c
===================================================================
--- sys/netinet/ip_divert.c
+++ sys/netinet/ip_divert.c
@@ -561,6 +561,7 @@
{
struct inpcb *inp;
int error;
+ u_long sendspace, recvspace;
inp = sotoinpcb(so);
KASSERT(inp == NULL, ("div_attach: inp != NULL"));
@@ -569,7 +570,9 @@
if (error)
return (error);
}
- error = soreserve(so, div_sendspace, div_recvspace);
+ sendspace = so->divsendspace ? so->divsendspace : div_sendspace;
+ recvspace = so->divrecvspace ? so->divrecvspace : div_recvspace;
+ error = soreserve(so, sendspace, recvspace);
if (error)
return error;
INP_INFO_WLOCK(&V_divcbinfo);
Index: sys/netinet/raw_ip.c
===================================================================
--- sys/netinet/raw_ip.c
+++ sys/netinet/raw_ip.c
@@ -660,6 +660,15 @@
error = ENOPROTOOPT;
break ;
+ case IP_DIVSENDBUF:
+ optval = so->divsendspace;
+ error = sooptcopyout(sopt, &optval, sizeof optval);
+ break;
+ case IP_DIVRECVBUF:
+ optval = so->divrecvspace;
+ error = sooptcopyout(sopt, &optval, sizeof optval);
+ break;
+
case MRT_INIT:
case MRT_DONE:
case MRT_ADD_VIF:
@@ -746,6 +755,21 @@
return (error);
error = ip_rsvp_vif ?
ip_rsvp_vif(so, sopt) : EINVAL;
+ break;
+
+ case IP_DIVSENDBUF:
+ error = sooptcopyin(sopt, &optval, sizeof optval,
+ sizeof optval);
+ if (error)
+ break;
+ so->divsendspace = optval;
+ break;
+ case IP_DIVRECVBUF:
+ error = sooptcopyin(sopt, &optval, sizeof optval,
+ sizeof optval);
+ if (error)
+ break;
+ so->divrecvspace = optval;
break;
case MRT_INIT:
Index: sys/sys/socketvar.h
===================================================================
--- sys/sys/socketvar.h
+++ sys/sys/socketvar.h
@@ -102,6 +102,9 @@
void *so_emuldata; /* (b) private data for emulators */
so_dtor_t *so_dtor; /* (b) optional destructor */
struct osd osd; /* Object Specific extensions */
+ /* divert socket buffer sizes */
+ u_long divsendspace; /* divert send buffer size */
+ u_long divrecvspace; /* divert receive buffer size */
/*
* so_fibnum, so_user_cookie and friends can be used to attach
* some user-specified metadata to a socket, which then can be

File Metadata

Mime Type
text/plain
Expires
Mon, May 18, 1:04 PM (8 h, 19 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
33249550
Default Alt Text
D23577.diff (3 KB)

Event Timeline