add --mark option to set SO_MARK sockopt
PATCH 1/1 add --mark option to set SO_MARK sockopt
--- init.c | 1 + openvpn.8 | 6 ++++++ options.c | 14 ++++++++++++++ options.h | 3 +++ socket.c | 13 +++++++++++++ socket.h | 1 + 6 files changed, 38 insertions(+), 0 deletions(-)
init.c +1 -0
@@ -2640,6 +2640,7 @@ do_init_socket_1 (struct context *c, const int mode) c->options.mtu_discover_type, c->options.rcvbuf, c->options.sndbuf, + c->options.mark, sockflags); }
openvpn.8 +6 -0
@@ -1371,6 +1371,12 @@ Set the TCP/UDP socket receive buffer size. Currently defaults to 65536 bytes. .\"********************************************************* .TP +.B \-\-mark value +Mark encrypted packets being sent with value. The mark value can be +matched in policy routing and packetfilter rules. This option is +only supported in Linux and does nothing on other operating systems. +.\"********************************************************* +.TP .B \-\-socket-flags flags... Apply the given flags to the OpenVPN transport socket. Currently, only
options.c +14 -0
@@ -280,6 +280,10 @@ static const char usage_message[] = " or --fragment max value, whichever is lower.\n" "--sndbuf size : Set the TCP/UDP send buffer size.\n" "--rcvbuf size : Set the TCP/UDP receive buffer size.\n" +#ifdef TARGET_LINUX + "--mark value : Mark encrypted packets being sent with value. The mark value\n" + " can be matched in policy routing and packetfilter rules.\n" +#endif"--txqueuelen n : Set the tun/tap TX queue length to n (Linux only).\n" "--mlock : Disable Paging -- ensures key material and tunnel\n" " data will never be written to disk.\n"
@@ -1473,6 +1477,9 @@ show_settings (const struct options *o)#endif SHOW_INT (rcvbuf);SHOW_INT (sndbuf); +#ifdef TARGET_LINUX +SHOW_INT (mark); +#endif SHOW_INT (sockflags);SHOW_BOOL (fast_io);
@@ -4520,6 +4527,13 @@ add_option (struct options *options,VERIFY_PERMISSION (OPT_P_SOCKBUF ); options->sndbuf =positive_atoi (p[1 ]); } +else if (streq (p[0 ],"mark" ) && p[1 ]) + { +#ifdef TARGET_LINUX +VERIFY_PERMISSION (OPT_P_GENERAL ); + options->mark =atoi (p[1 ]); +#endif + }else if (streq (p[0 ],"socket-flags" )) {int j;
options.h +3 -0
@@ -342,6 +342,9 @@ struct optionsint rcvbuf;int sndbuf; +/* mark value */ +int mark; +/* socket flags */ unsigned int sockflags;
socket.c +13 -0
@@ -779,6 +779,15 @@ socket_set_tcp_nodelay (int sd, int state)#endif } +static void +socket_set_mark (int sd,int mark) +{ +#ifdef TARGET_LINUX +if (mark &&setsockopt (sd,SOL_SOCKET ,SO_MARK , &mark,sizeof (mark)) !=0 ) +msg (M_WARN ,"NOTE: setsockopt SO_MARK=%d failed" , mark); +#endif +} +static bool socket_set_flags (int sd,unsigned int sockflags) {
@@ -1599,6 +1608,7 @@ link_socket_init_phase1 (struct link_socket *sock,int mtu_discover_type, int rcvbuf, int sndbuf, + int mark, unsigned int sockflags) {ASSERT (sock );
@@ -1716,6 +1726,9 @@ link_socket_init_phase1 (struct link_socket *sock,/* set socket buffers based on --sndbuf and --rcvbuf options */ socket_set_buffers (sock->sd, &sock->socket_buffer_sizes); +/* set socket to --mark packets with given value */ +socket_set_mark (sock->sd, mark); +resolve_bind_local (sock);resolve_remote (sock,1 ,NULL ,NULL ); }
socket.h +1 -0
@@ -324,6 +324,7 @@ link_socket_init_phase1 (struct link_socket *sock,int mtu_discover_type, int rcvbuf, int sndbuf, + int mark, unsigned int sockflags); void link_socket_init_phase2 (struct link_socket *sock,
Signature · 1 line
1.7.4.1
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Quoted 10 lines · Heiko Hund
Signed-off-by Heiko Hund <[email protected]...>--- init.c | 1 + openvpn.8 | 6 ++++++ options.c | 14 ++++++++++++++ options.h | 3 +++ socket.c | 13 +++++++++++++ socket.h | 1 + 6 files changed, 38 insertions(+), 0 deletions(-)
ACK! This makes sense. Should probably be noted that you need a kernel which is 2.6.25 or newer (unless some distros have backported it). Upstream kernel commit 4a19ec5800fc3bb64e2d87c4d9fdd9e636086fe0 [1] contains this feature.
Applied to master braches in testing and stable. Commit d90428d141102a646a20b1310de1716621e32bd6
kind regards,
David Sommerseth
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (GNU/Linux)
Comment: Using GnuPG with Fedora - http://enigmail.mozdev.org/
iEYEARECAAYFAk5efDIACgkQDC186MBRfrrkhQCfdS2weWvTSC/YWa5otp0K4R+e AUkAn3Kl65yoRxoEkeUJnw8V2HlPZMkD
=Z0UP
-----END PGP SIGNATURE-----
Maybe should extend the usage of parameter "socket-flags"?
Quoted 157 lines · Heiko Hund
Signed-off-by Heiko Hund <[email protected]...>---
init.c | 1 +openvpn.8 | 6 ++++++ options.c | 14 ++++++++++++++ options.h | 3 +++ socket.c | 13 +++++++++++++ socket.h | 1 + 6 files changed, 38 insertions(+), 0 deletions(-)init.c +1
-0@@ -2640,6 +2640,7 @@ do_init_socket_1 (struct context *c, const int mode) c->options.mtu_discover_type, c->options.rcvbuf, c->options.sndbuf, + c->options.mark, sockflags); }openvpn.8 +0
-0@@ -1371,6 +1371,12 @@ Set the TCP/UDP socket receive buffer size.Currently defaults to 65536 bytes. .\"********************************************************* .TP
+.B \-\-mark valueopenvpn.8 +5
-0+Mark encrypted packets being sent with value. The mark value can be +matched in policy routing and packetfilter rules. This option is +only supported in Linux and does nothing on other operating systems. +.\"********************************************************* +.TP.B \-\-socket-flags flags...
Apply the given flags to the OpenVPN transport socket. Currently, onlyoptions.c +0
-0@@ -280,6 +280,10 @@ static const char usage_message[] =" or --fragment max value, whichever is lower.\n" "--sndbuf size : Set the TCP/UDP send buffer size.\n" "--rcvbuf size : Set the TCP/UDP receive buffer size.\n"
options.c +4
-0+#ifdef TARGET_LINUX + "--mark value : Mark encrypted packets being sent with value. The mark value\n" + " can be matched in policy routing and packetfilter rules.\n" +#endif "--txqueuelen n : Set the tun/tap TX queue length to n (Linux only).\n" "--mlock : Disable Paging -- ensures key material and tunnel\n" " data will never be written to disk.\n"
options.c +10
-0@@ -1473,6 +1477,9 @@ show_settings (const struct options *o) #endif SHOW_INT (rcvbuf); SHOW_INT (sndbuf); +#ifdef TARGET_LINUX + SHOW_INT (mark); +#endif SHOW_INT (sockflags); SHOW_BOOL (fast_io);@@ -4520,6 +4527,13 @@ add_option (struct options *options, VERIFY_PERMISSION (OPT_P_SOCKBUF); options->sndbuf = positive_atoi (p[1]); } + else if (streq (p[0], "mark") && p[1]) + { +#ifdef TARGET_LINUX + VERIFY_PERMISSION (OPT_P_GENERAL); + options->mark = atoi(p[1]); +#endif + } else if (streq (p[0], "socket-flags")) { int j;options.h +3
-0@@ -342,6 +342,9 @@ struct options int rcvbuf; int sndbuf; + /* mark value */ + int mark; + /* socket flags */ unsigned int sockflags;socket.c +9
-0@@ -779,6 +779,15 @@ socket_set_tcp_nodelay (int sd, int state) #endif } +static void +socket_set_mark (int sd,int mark) +{ +#ifdef TARGET_LINUX + if (mark && setsockopt (sd, SOL_SOCKET, SO_MARK, &mark, sizeof (mark)) != 0) + msg (M_WARN, "NOTE: setsockopt SO_MARK=%d failed", mark); +#endif +} +static bool
socket_set_flags (int sd, unsigned int sockflags) {socket.c +4
-0@@ -1599,6 +1608,7 @@ link_socket_init_phase1 (struct link_socket *sock, int mtu_discover_type, int rcvbuf, int sndbuf, + int mark, unsigned int sockflags) { ASSERT (sock);@@ -1716,6 +1726,9 @@ link_socket_init_phase1 (struct link_socket *sock, /* set socket buffers based on --sndbuf and --rcvbuf options */ socket_set_buffers (sock->sd, &sock->socket_buffer_sizes); + /* set socket to --mark packets with given value */ + socket_set_mark (sock->sd, mark); + resolve_bind_local (sock); resolve_remote (sock, 1, NULL, NULL); }socket.h +1
-1@@ -324,6 +324,7 @@ link_socket_init_phase1 (struct link_socket *sock, int mtu_discover_type, int rcvbuf, int sndbuf, + int mark, unsigned int sockflags); void link_socket_init_phase2 (struct link_socket *sock, --1.7.4.1
------------------------------------------------------------------------------
Special Offer -- Download ArcSight Logger for FREE! Finally, a world-class log management solution at an even better price-free! And you'll get a free "Love Thy Logs" t-shirt when you download Logger. Secure your free ArcSight Logger TODAY!
http://p.sf.net/sfu/arcsisghtdev2dev
_______________________________________________
Openvpn-devel mailing list [email protected]
https://lists.sourceforge.net/lists/listinfo/openvpn-devel
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Quoted 1 line · Alon Bar-Lev
Maybe should extend the usage of parameter "socket-flags"?
I considered that too, but that would require a bigger rewrite of the
- --socket-flags parser. Currently it only is doing "boolean flags". And as
- --mark takes an argument, it's not a traditional flag but more a socket option.
But changing --socket-flags and --mark to --socket-opts, making it understand TCP_NODELAY and MARK=integer ... that would be a nice step forward. Such a move should deprecate --socket-flags via a warning in 2.3, though - and be removed in 2.4.
kind regards,
David Sommerseth
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (GNU/Linux)
Comment: Using GnuPG with Fedora - http://enigmail.mozdev.org/
iEYEARECAAYFAk5ef5UACgkQDC186MBRfrrlswCeO8AgU4L58h9sL1XE358dQ2Tb yO8An0zfR+jb2ciW3WbCarIId0K5Vq/x
=Kt9e
-----END PGP SIGNATURE-----
Not only Mark is usable, there is also TOS, MSS and other flags that may be interesting.
So having separate parameter for each makes configuration more complex.
Quoted 29 lines · David Sommerseth
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1Quoted 1 line · Alon Bar-Lev
Maybe should extend the usage of parameter "socket-flags"?
I considered that too, but that would require a bigger rewrite of the
- --socket-flags parser. Currently it only is doing "boolean flags". And as
- --mark takes an argument, it's not a traditional flag but more a socket option.But changing --socket-flags and --mark to --socket-opts, making it understand
TCP_NODELAYand MARK=integer ... that would be a nice step forward. Such a move should deprecate --socket-flags via a warning in 2.3, though - and be removed in 2.4.kind regards,
David Sommerseth
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (GNU/Linux)
Comment: Using GnuPG with Fedora - http://enigmail.mozdev.org/iEYEARECAAYFAk5ef5UACgkQDC186MBRfrrlswCeO8AgU4L58h9sL1XE358dQ2Tb yO8An0zfR+jb2ciW3WbCarIId0K5Vq/x
=Kt9e
-----END PGP SIGNATURE-----