All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH net-next 1/2] sock: support per-packet fwmark
@ 2015-10-08 21:56 Edward Hyunkoo Jee
  2015-10-08 21:56 ` [PATCH net-next 2/2] packet: support per-packet fwmark for af_packet sendmsg Edward Hyunkoo Jee
  2015-10-13  2:25 ` [PATCH net-next 1/2] sock: support per-packet fwmark David Miller
  0 siblings, 2 replies; 4+ messages in thread
From: Edward Hyunkoo Jee @ 2015-10-08 21:56 UTC (permalink / raw)
  To: netdev; +Cc: edumazet, willemb, Edward Hyunkoo Jee

It's useful to allow users to set fwmark for an individual packet,
without changing the socket state. The function this patch adds in
sock layer can be used by the protocols that need such a feature.

Signed-off-by: Edward Hyunkoo Jee <edjee@google.com>
Signed-off-by: Eric Dumazet <edumazet@google.com>
Cc: Willem de Bruijn <willemb@google.com>
---
 include/net/sock.h |  7 +++++++
 net/core/sock.c    | 26 ++++++++++++++++++++++++++
 2 files changed, 33 insertions(+)

diff --git a/include/net/sock.h b/include/net/sock.h
index dfe2eb8..03ca20f 100644
--- a/include/net/sock.h
+++ b/include/net/sock.h
@@ -1514,6 +1514,13 @@ void sock_kfree_s(struct sock *sk, void *mem, int size);
 void sock_kzfree_s(struct sock *sk, void *mem, int size);
 void sk_send_sigurg(struct sock *sk);
 
+struct sockcm_cookie {
+	u32 mark;
+};
+
+int sock_cmsg_send(struct sock *sk, struct msghdr *msg,
+		   struct sockcm_cookie *sockc);
+
 /*
  * Functions to fill in entries in struct proto_ops when a protocol
  * does not implement a particular function.
diff --git a/net/core/sock.c b/net/core/sock.c
index 7dd1263..3395777 100644
--- a/net/core/sock.c
+++ b/net/core/sock.c
@@ -1852,6 +1852,32 @@ struct sk_buff *sock_alloc_send_skb(struct sock *sk, unsigned long size,
 }
 EXPORT_SYMBOL(sock_alloc_send_skb);
 
+int sock_cmsg_send(struct sock *sk, struct msghdr *msg,
+		   struct sockcm_cookie *sockc)
+{
+	struct cmsghdr *cmsg;
+
+	for_each_cmsghdr(cmsg, msg) {
+		if (!CMSG_OK(msg, cmsg))
+			return -EINVAL;
+		if (cmsg->cmsg_level != SOL_SOCKET)
+			continue;
+		switch (cmsg->cmsg_type) {
+		case SO_MARK:
+			if (!ns_capable(sock_net(sk)->user_ns, CAP_NET_ADMIN))
+				return -EPERM;
+			if (cmsg->cmsg_len != CMSG_LEN(sizeof(u32)))
+				return -EINVAL;
+			sockc->mark = *(u32 *)CMSG_DATA(cmsg);
+			break;
+		default:
+			return -EINVAL;
+		}
+	}
+	return 0;
+}
+EXPORT_SYMBOL(sock_cmsg_send);
+
 /* On 32bit arches, an skb frag is limited to 2^15 */
 #define SKB_FRAG_PAGE_ORDER	get_order(32768)
 
-- 
2.6.0.rc2.230.g3dd15c0

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH net-next 2/2] packet: support per-packet fwmark for af_packet sendmsg
  2015-10-08 21:56 [PATCH net-next 1/2] sock: support per-packet fwmark Edward Hyunkoo Jee
@ 2015-10-08 21:56 ` Edward Hyunkoo Jee
  2015-10-13  2:25   ` David Miller
  2015-10-13  2:25 ` [PATCH net-next 1/2] sock: support per-packet fwmark David Miller
  1 sibling, 1 reply; 4+ messages in thread
From: Edward Hyunkoo Jee @ 2015-10-08 21:56 UTC (permalink / raw)
  To: netdev; +Cc: edumazet, willemb, Edward Hyunkoo Jee

Signed-off-by: Edward Hyunkoo Jee <edjee@google.com>
Signed-off-by: Eric Dumazet <edumazet@google.com>
Cc: Willem de Bruijn <willemb@google.com>
---
 net/packet/af_packet.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c
index 81c900f..9d8c7fa 100644
--- a/net/packet/af_packet.c
+++ b/net/packet/af_packet.c
@@ -2630,6 +2630,7 @@ static int packet_snd(struct socket *sock, struct msghdr *msg, size_t len)
 	__be16 proto;
 	unsigned char *addr;
 	int err, reserve = 0;
+	struct sockcm_cookie sockc;
 	struct virtio_net_hdr vnet_hdr = { 0 };
 	int offset = 0;
 	int vnet_hdr_len;
@@ -2665,6 +2666,13 @@ static int packet_snd(struct socket *sock, struct msghdr *msg, size_t len)
 	if (unlikely(!(dev->flags & IFF_UP)))
 		goto out_unlock;
 
+	sockc.mark = sk->sk_mark;
+	if (msg->msg_controllen) {
+		err = sock_cmsg_send(sk, msg, &sockc);
+		if (unlikely(err))
+			goto out_unlock;
+	}
+
 	if (sock->type == SOCK_RAW)
 		reserve = dev->hard_header_len;
 	if (po->has_vnet_hdr) {
@@ -2774,7 +2782,7 @@ static int packet_snd(struct socket *sock, struct msghdr *msg, size_t len)
 	skb->protocol = proto;
 	skb->dev = dev;
 	skb->priority = sk->sk_priority;
-	skb->mark = sk->sk_mark;
+	skb->mark = sockc.mark;
 
 	packet_pick_tx_queue(dev, skb);
 
-- 
2.6.0.rc2.230.g3dd15c0

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH net-next 1/2] sock: support per-packet fwmark
  2015-10-08 21:56 [PATCH net-next 1/2] sock: support per-packet fwmark Edward Hyunkoo Jee
  2015-10-08 21:56 ` [PATCH net-next 2/2] packet: support per-packet fwmark for af_packet sendmsg Edward Hyunkoo Jee
@ 2015-10-13  2:25 ` David Miller
  1 sibling, 0 replies; 4+ messages in thread
From: David Miller @ 2015-10-13  2:25 UTC (permalink / raw)
  To: edjee; +Cc: netdev, edumazet, willemb

From: Edward Hyunkoo Jee <edjee@google.com>
Date: Thu,  8 Oct 2015 14:56:48 -0700

> It's useful to allow users to set fwmark for an individual packet,
> without changing the socket state. The function this patch adds in
> sock layer can be used by the protocols that need such a feature.
> 
> Signed-off-by: Edward Hyunkoo Jee <edjee@google.com>
> Signed-off-by: Eric Dumazet <edumazet@google.com>

Applied.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH net-next 2/2] packet: support per-packet fwmark for af_packet sendmsg
  2015-10-08 21:56 ` [PATCH net-next 2/2] packet: support per-packet fwmark for af_packet sendmsg Edward Hyunkoo Jee
@ 2015-10-13  2:25   ` David Miller
  0 siblings, 0 replies; 4+ messages in thread
From: David Miller @ 2015-10-13  2:25 UTC (permalink / raw)
  To: edjee; +Cc: netdev, edumazet, willemb

From: Edward Hyunkoo Jee <edjee@google.com>
Date: Thu,  8 Oct 2015 14:56:49 -0700

> Signed-off-by: Edward Hyunkoo Jee <edjee@google.com>
> Signed-off-by: Eric Dumazet <edumazet@google.com>

Applied.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2015-10-13  2:09 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-10-08 21:56 [PATCH net-next 1/2] sock: support per-packet fwmark Edward Hyunkoo Jee
2015-10-08 21:56 ` [PATCH net-next 2/2] packet: support per-packet fwmark for af_packet sendmsg Edward Hyunkoo Jee
2015-10-13  2:25   ` David Miller
2015-10-13  2:25 ` [PATCH net-next 1/2] sock: support per-packet fwmark David Miller

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.