[ovs-dev] [PATCH 3/5] lib/netlink-socket.c: packet subscribe functionality on Windows
Eitan Eliahu
eliahue at vmware.com
Tue Oct 21 23:28:29 UTC 2014
Hi Nithin,
Please remove the following line:
sock->read_ioctl = OVS_IOCTL_READ_PACKET; // XXX:
The socket type changes only if the IOCTL is successful. (otherwise user mode could call unsubscribe)
Thanks,
Eitan
-----Original Message-----
From: dev [mailto:dev-bounces at openvswitch.org] On Behalf Of Nithin Raju
Sent: Tuesday, October 21, 2014 4:11 PM
To: dev at openvswitch.org
Subject: [ovs-dev] [PATCH 3/5] lib/netlink-socket.c: packet subscribe functionality on Windows
In this patch, we add support in userspace for packet subscribe API similar to the join/leave MC group API that is used for port events.
The kernel code has already been commited.
Acked-by: Nithin Raju <nithin at vmware.com>
---
lib/netlink-socket.c | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 59 insertions(+), 0 deletions(-)
diff --git a/lib/netlink-socket.c b/lib/netlink-socket.c index 68e81d1..56f4fef 100644
--- a/lib/netlink-socket.c
+++ b/lib/netlink-socket.c
@@ -396,6 +396,65 @@ nl_sock_join_mcgroup(struct nl_sock *sock, unsigned int multicast_group)
return 0;
}
+int
+nl_sock_subscribe_packets(struct nl_sock *sock) {
+ if (sock->read_ioctl != OVS_IOCTL_READ) {
+ return EINVAL;
+ }
+
+ sock->read_ioctl = OVS_IOCTL_READ_PACKET; // XXX:
+ int error = nl_sock_subscribe_packet__(sock, true);
+ if (error) {
+ VLOG_WARN("could not unsubscribe packets (%s)",
+ ovs_strerror(errno));
+ return error;
+ }
+ sock->read_ioctl = OVS_IOCTL_READ_PACKET;
+
+ return 0;
+}
+
+int
+nl_sock_unsubscribe_packets(struct nl_sock *sock) {
+ ovs_assert(sock->read_ioctl == OVS_IOCTL_READ_PACKET);
+
+ int error = nl_sock_subscribe_packet__(sock, false);
+ if (error) {
+ VLOG_WARN("could not subscribe to packets (%s)",
+ ovs_strerror(errno));
+ return error;
+ }
+
+ sock->read_ioctl = OVS_IOCTL_READ;
+ return 0;
+}
+
+int
+nl_sock_subscribe_packet__(struct nl_sock *sock, bool subscribe) {
+ struct ofpbuf request;
+ uint64_t request_stub[128];
+ struct ovs_header *ovs_header;
+ struct nlmsghdr *nlmsg;
+ int error;
+
+ ofpbuf_use_stub(&request, request_stub, sizeof request_stub);
+ nl_msg_put_genlmsghdr(&request, 0, OVS_WIN_NL_CTRL_FAMILY_ID, 0,
+ OVS_CTRL_CMD_PACKET_SUBSCRIBE_REQ,
+ OVS_WIN_CONTROL_VERSION);
+
+ ovs_header = ofpbuf_put_uninit(&request, sizeof *ovs_header);
+ ovs_header->dp_ifindex = 0;
+ nl_msg_put_u8(&request, OVS_NL_ATTR_PACKET_SUBSCRIBE, subscribe ? 1 : 0);
+ nl_msg_put_u32(&request, OVS_NL_ATTR_PACKET_PID, sock->pid);
+
+ error = nl_sock_send(sock, &request, true);
+ ofpbuf_uninit(&request);
+ return error;
+}
+
/* Tries to make 'sock' stop listening to 'multicast_group'. Returns 0 if
* successful, otherwise a positive errno value.
*
--
1.7.4.1
_______________________________________________
dev mailing list
dev at openvswitch.org
https://urldefense.proofpoint.com/v1/url?u=http://openvswitch.org/mailman/listinfo/dev&k=oIvRg1%2BdGAgOoM1BIlLLqw%3D%3D%0A&r=yTvML8OxA42Jb6ViHe7fUXbvPVOYDPVq87w43doxtlY%3D%0A&m=%2FLUzvupTi%2FgeIM%2FGuiCIZknRr7lxWQCu8%2B6vQiYVIeg%3D%0A&s=85e249a1db8c5965688819ca90eeb1c0f5df6df3e63ef58deb6bc17b970679ca
More information about the dev
mailing list