Add defines needed to compile netlink-socket.c and netlink.c. Add wrappers for the functions sendmsg and recvmsg. They can also be added to another file instead of defining them inlined.
Add a wrapper and the functionality behind it for syconf. Add the newly created files to the noinst_HEADERS in windows/automake.mk Signed-off-by: Alin Gabriel Serdean <aserd...@cloudbasesolutions.com> --- include/windows/automake.mk | 2 + include/windows/linux/rtnetlink.h | 260 +++++++++++++++++++++++++++++++++++++ include/windows/net/if.h | 50 +++++++ include/windows/netpacket/packet.h | 76 +++++++++++ include/windows/sys/socket.h | 4 + include/windows/sys/uio.h | 22 ++++ include/windows/unistd.h | 50 +++++++ 7 files changed, 464 insertions(+) create mode 100644 include/windows/linux/rtnetlink.h create mode 100644 include/windows/netpacket/packet.h diff --git a/include/windows/automake.mk b/include/windows/automake.mk index 4d5a42c..db87ff3 100644 --- a/include/windows/automake.mk +++ b/include/windows/automake.mk @@ -7,8 +7,10 @@ noinst_HEADERS += \ include/windows/arpa/inet.h \ + include/windows/netpacket/packet.h \ include/windows/dirent.h \ include/windows/getopt.h \ + include/windows/linux/rtnetlink.h \ include/windows/net/if.h \ include/windows/netdb.h \ include/windows/netinet/icmp6.h \ diff --git a/include/windows/linux/rtnetlink.h b/include/windows/linux/rtnetlink.h new file mode 100644 index 0000000..8eeb69a --- /dev/null +++ b/include/windows/linux/rtnetlink.h @@ -0,0 +1,260 @@ +/* + * Copyright 2014 Cloudbase Solutions Srl + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef __LINUX_RTNETLINK_H +#define __LINUX_RTNETLINK_H 1 + +enum { + RTM_BASE = 16, +#define RTM_BASE RTM_BASE + + RTM_NEWLINK = 16, +#define RTM_NEWLINK RTM_NEWLINK + RTM_DELLINK, +#define RTM_DELLINK RTM_DELLINK + RTM_GETLINK, +#define RTM_GETLINK RTM_GETLINK + RTM_SETLINK, +#define RTM_SETLINK RTM_SETLINK + + RTM_NEWADDR = 20, +#define RTM_NEWADDR RTM_NEWADDR + RTM_DELADDR, +#define RTM_DELADDR RTM_DELADDR + RTM_GETADDR, +#define RTM_GETADDR RTM_GETADDR + + RTM_NEWROUTE = 24, +#define RTM_NEWROUTE RTM_NEWROUTE + RTM_DELROUTE, +#define RTM_DELROUTE RTM_DELROUTE + RTM_GETROUTE, +#define RTM_GETROUTE RTM_GETROUTE + + RTM_NEWNEIGH = 28, +#define RTM_NEWNEIGH RTM_NEWNEIGH + RTM_DELNEIGH, +#define RTM_DELNEIGH RTM_DELNEIGH + RTM_GETNEIGH, +#define RTM_GETNEIGH RTM_GETNEIGH + + RTM_NEWRULE = 32, +#define RTM_NEWRULE RTM_NEWRULE + RTM_DELRULE, +#define RTM_DELRULE RTM_DELRULE + RTM_GETRULE, +#define RTM_GETRULE RTM_GETRULE + + RTM_NEWQDISC = 36, +#define RTM_NEWQDISC RTM_NEWQDISC + RTM_DELQDISC, +#define RTM_DELQDISC RTM_DELQDISC + RTM_GETQDISC, +#define RTM_GETQDISC RTM_GETQDISC + + RTM_NEWTCLASS = 40, +#define RTM_NEWTCLASS RTM_NEWTCLASS + RTM_DELTCLASS, +#define RTM_DELTCLASS RTM_DELTCLASS + RTM_GETTCLASS, +#define RTM_GETTCLASS RTM_GETTCLASS + + RTM_NEWTFILTER = 44, +#define RTM_NEWTFILTER RTM_NEWTFILTER + RTM_DELTFILTER, +#define RTM_DELTFILTER RTM_DELTFILTER + RTM_GETTFILTER, +#define RTM_GETTFILTER RTM_GETTFILTER + + RTM_NEWACTION = 48, +#define RTM_NEWACTION RTM_NEWACTION + RTM_DELACTION, +#define RTM_DELACTION RTM_DELACTION + RTM_GETACTION, +#define RTM_GETACTION RTM_GETACTION + + RTM_NEWPREFIX = 52, +#define RTM_NEWPREFIX RTM_NEWPREFIX + + RTM_GETMULTICAST = 58, +#define RTM_GETMULTICAST RTM_GETMULTICAST + + RTM_GETANYCAST = 62, +#define RTM_GETANYCAST RTM_GETANYCAST + + RTM_NEWNEIGHTBL = 64, +#define RTM_NEWNEIGHTBL RTM_NEWNEIGHTBL + RTM_GETNEIGHTBL = 66, +#define RTM_GETNEIGHTBL RTM_GETNEIGHTBL + RTM_SETNEIGHTBL, +#define RTM_SETNEIGHTBL RTM_SETNEIGHTBL + + RTM_NEWNDUSEROPT = 68, +#define RTM_NEWNDUSEROPT RTM_NEWNDUSEROPT + RTM_NEWADDRLABEL = 72, +#define RTM_NEWADDRLABEL RTM_NEWADDRLABEL + RTM_DELADDRLABEL, +#define RTM_DELADDRLABEL RTM_DELADDRLABEL + RTM_GETADDRLABEL, +#define RTM_GETADDRLABEL RTM_GETADDRLABEL + + RTM_GETDCB = 78, +#define RTM_GETDCB RTM_GETDCB + RTM_SETDCB, +#define RTM_SETDCB RTM_SETDCB + + RTM_NEWNETCONF = 80, +#define RTM_NEWNETCONF RTM_NEWNETCONF + RTM_GETNETCONF = 82, +#define RTM_GETNETCONF RTM_GETNETCONF + + RTM_NEWMDB = 84, +#define RTM_NEWMDB RTM_NEWMDB + RTM_DELMDB = 85, +#define RTM_DELMDB RTM_DELMDB + RTM_GETMDB = 86, +#define RTM_GETMDB RTM_GETMDB + + __RTM_MAX, +#define RTM_MAX (((__RTM_MAX + 3) & ~3) - 1) +}; + +enum rtnetlink_groups { + RTNLGRP_NONE, +#define RTNLGRP_NONE RTNLGRP_NONE + RTNLGRP_LINK, +#define RTNLGRP_LINK RTNLGRP_LINK + RTNLGRP_NOTIFY, +#define RTNLGRP_NOTIFY RTNLGRP_NOTIFY + RTNLGRP_NEIGH, +#define RTNLGRP_NEIGH RTNLGRP_NEIGH + RTNLGRP_TC, +#define RTNLGRP_TC RTNLGRP_TC + RTNLGRP_IPV4_IFADDR, +#define RTNLGRP_IPV4_IFADDR RTNLGRP_IPV4_IFADDR + RTNLGRP_IPV4_MROUTE, +#define RTNLGRP_IPV4_MROUTE RTNLGRP_IPV4_MROUTE + RTNLGRP_IPV4_ROUTE, +#define RTNLGRP_IPV4_ROUTE RTNLGRP_IPV4_ROUTE + RTNLGRP_IPV4_RULE, +#define RTNLGRP_IPV4_RULE RTNLGRP_IPV4_RULE + RTNLGRP_IPV6_IFADDR, +#define RTNLGRP_IPV6_IFADDR RTNLGRP_IPV6_IFADDR + RTNLGRP_IPV6_MROUTE, +#define RTNLGRP_IPV6_MROUTE RTNLGRP_IPV6_MROUTE + RTNLGRP_IPV6_ROUTE, +#define RTNLGRP_IPV6_ROUTE RTNLGRP_IPV6_ROUTE + RTNLGRP_IPV6_IFINFO, +#define RTNLGRP_IPV6_IFINFO RTNLGRP_IPV6_IFINFO + RTNLGRP_DECnet_IFADDR, +#define RTNLGRP_DECnet_IFADDR RTNLGRP_DECnet_IFADDR + RTNLGRP_NOP2, + RTNLGRP_DECnet_ROUTE, +#define RTNLGRP_DECnet_ROUTE RTNLGRP_DECnet_ROUTE + RTNLGRP_DECnet_RULE, +#define RTNLGRP_DECnet_RULE RTNLGRP_DECnet_RULE + RTNLGRP_NOP4, + RTNLGRP_IPV6_PREFIX, +#define RTNLGRP_IPV6_PREFIX RTNLGRP_IPV6_PREFIX + RTNLGRP_IPV6_RULE, +#define RTNLGRP_IPV6_RULE RTNLGRP_IPV6_RULE + RTNLGRP_ND_USEROPT, +#define RTNLGRP_ND_USEROPT RTNLGRP_ND_USEROPT + RTNLGRP_PHONET_IFADDR, +#define RTNLGRP_PHONET_IFADDR RTNLGRP_PHONET_IFADDR + RTNLGRP_PHONET_ROUTE, +#define RTNLGRP_PHONET_ROUTE RTNLGRP_PHONET_ROUTE + RTNLGRP_DCB, +#define RTNLGRP_DCB RTNLGRP_DCB + __RTNLGRP_MAX +}; + +enum rtattr_type_t { + RTA_UNSPEC, + RTA_DST, + RTA_SRC, + RTA_IIF, + RTA_OIF, + RTA_GATEWAY, + RTA_PRIORITY, + RTA_PREFSRC, + RTA_METRICS, + RTA_MULTIPATH, + RTA_PROTOINFO, + RTA_FLOW, + RTA_CACHEINFO, + RTA_SESSION, + RTA_MP_ALGO, + RTA_TABLE, + RTA_MARK, + RTA_MFC_STATS, + __RTA_MAX +}; + +enum { + RTN_UNSPEC, + RTN_UNICAST, + RTN_LOCAL, + RTN_BROADCAST, + RTN_ANYCAST, + RTN_MULTICAST, + RTN_BLACKHOLE, + RTN_UNREACHABLE, + RTN_PROHIBIT, + RTN_THROW, + RTN_NAT, + RTN_XRESOLVE, + __RTN_MAX +}; +#define RTN_MAX (__RTN_MAX - 1) + +enum rt_scope_t { + RT_SCOPE_UNIVERSE=0, + RT_SCOPE_SITE=200, + RT_SCOPE_LINK=253, + RT_SCOPE_HOST=254, + RT_SCOPE_NOWHERE=255 +}; + +struct rtmsg { + unsigned char rtm_family; + unsigned char rtm_dst_len; + unsigned char rtm_src_len; + unsigned char rtm_tos; + + unsigned char rtm_table; + unsigned char rtm_protocol; + unsigned char rtm_scope; + unsigned char rtm_type; + + unsigned rtm_flags; +}; +#define RTA_MAX (__RTA_MAX - 1) + +struct ifinfomsg { + unsigned char ifi_family; + unsigned char __ifi_pad; + unsigned short ifi_type; + int ifi_index; + unsigned ifi_flags; + unsigned ifi_change; +}; + +struct rtgenmsg { + unsigned char rtgen_family; +}; + +#endif /* linux/rtnetlink.h */ diff --git a/include/windows/net/if.h b/include/windows/net/if.h index 893ffe4..3a064ae 100644 --- a/include/windows/net/if.h +++ b/include/windows/net/if.h @@ -21,4 +21,54 @@ #define IFNAMSIZ IF_NAMESIZE +enum { + IFLA_UNSPEC, + IFLA_ADDRESS, + IFLA_BROADCAST, + IFLA_IFNAME, + IFLA_MTU, + IFLA_LINK, + IFLA_QDISC, + IFLA_STATS, + IFLA_COST, +#define IFLA_COST IFLA_COST + IFLA_PRIORITY, +#define IFLA_PRIORITY IFLA_PRIORITY + IFLA_MASTER, +#define IFLA_MASTER IFLA_MASTER + IFLA_WIRELESS, +#define IFLA_WIRELESS IFLA_WIRELESS + IFLA_PROTINFO, +#define IFLA_PROTINFO IFLA_PROTINFO + IFLA_TXQLEN, +#define IFLA_TXQLEN IFLA_TXQLEN + IFLA_MAP, +#define IFLA_MAP IFLA_MAP + IFLA_WEIGHT, +#define IFLA_WEIGHT IFLA_WEIGHT + IFLA_OPERSTATE, + IFLA_LINKMODE, + IFLA_LINKINFO, +#define IFLA_LINKINFO IFLA_LINKINFO + IFLA_NET_NS_PID, + IFLA_IFALIAS, + IFLA_NUM_VF, + IFLA_VFINFO_LIST, + IFLA_STATS64, + IFLA_VF_PORTS, + IFLA_PORT_SELF, + IFLA_AF_SPEC, + IFLA_GROUP, + IFLA_NET_NS_FD, + IFLA_EXT_MASK, + IFLA_PROMISCUITY, +#define IFLA_PROMISCUITY IFLA_PROMISCUITY + IFLA_NUM_TX_QUEUES, + IFLA_NUM_RX_QUEUES, + IFLA_CARRIER, + IFLA_PHYS_PORT_ID, + __IFLA_MAX +}; +#define IFLA_MAX (__IFLA_MAX - 1) + #endif /* net/if.h */ diff --git a/include/windows/netpacket/packet.h b/include/windows/netpacket/packet.h new file mode 100644 index 0000000..40cb86b --- /dev/null +++ b/include/windows/netpacket/packet.h @@ -0,0 +1,76 @@ +/* + * Copyright 2014 Cloudbase Solutions Srl + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef __NETPACKET_PACKET_H +#define __NETPACKET_PACKET_H 1 + +struct iovec +{ + void *iov_base; + unsigned int iov_len; +}; + +struct msghdr + { + void *msg_name; + socklen_t msg_namelen; + + struct iovec *msg_iov; + size_t msg_iovlen; + + void *msg_control; + size_t msg_controllen; + + int msg_flags; + }; + +__inline unsigned int recvmsg(HANDLE handle, struct msghdr *msg, int flags) +{ + INT error = 0, retval = 0; + error = ReadFile(handle, msg->msg_iov[0].iov_base, + msg->msg_iov[0].iov_len, &retval, NULL); + DWORD last_error = GetLastError(); + + if (last_error != ERROR_IO_PENDING && !retval) { + retval = -1; + _set_errno(EAGAIN); + } + else { + _set_errno(EAGAIN); + } + return retval; +} + +__inline unsigned int sendmsg(HANDLE handle, const struct msghdr *msg, int flags) +{ + int error = 0, retval = 0; + DWORD last_error = 0; + for (int i = 0; i < msg->msg_iovlen; i++) { + do { + error = WriteFile(handle, msg->msg_iov[i].iov_base, + msg->msg_iov[i].iov_len, NULL, NULL); + last_error = GetLastError(); + } while ((error == 0) && (last_error == ERROR_IO_PENDING)); + if(!error) { + _set_errno(EAGAIN); + return -1; + } + + } + return 0; +} + +#endif /* netpacket/packet.h */ diff --git a/include/windows/sys/socket.h b/include/windows/sys/socket.h index ab6e822..1685ae2 100644 --- a/include/windows/sys/socket.h +++ b/include/windows/sys/socket.h @@ -19,4 +19,8 @@ typedef unsigned short int sa_family_t; +#define AF_NETLINK 16 +#define SO_RCVBUFFORCE 33 +#define MSG_DONTWAIT MSG_DONTROUTE + #endif /* sys/socket.h */ diff --git a/include/windows/sys/uio.h b/include/windows/sys/uio.h index e69de29..e92a772 100644 --- a/include/windows/sys/uio.h +++ b/include/windows/sys/uio.h @@ -0,0 +1,22 @@ +/* + * Copyright 2014 Cloudbase Solutions Srl + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef __SYS_UIO_H +#define __SYS_UIO_H 1 + +#include <netpacket/packet.h> + +#endif /* sys/uio.h */ diff --git a/include/windows/unistd.h b/include/windows/unistd.h index d9ded5a..f802e00 100644 --- a/include/windows/unistd.h +++ b/include/windows/unistd.h @@ -16,6 +16,9 @@ #ifndef _UNISTD_H #define _UNISTD_H 1 +#define WIN32_LEAN_AND_MEAN +#include <windows.h> + #define fsync _commit /* Standard file descriptors. */ @@ -23,4 +26,51 @@ #define STDOUT_FILENO 1 /* Standard output. */ #define STDERR_FILENO 2 /* Standard error output. */ +#define _SC_UIO_MAXIOV 2 +#define _XOPEN_IOV_MAX 16 + +#define _SC_PAGESIZE 0x1 +#define _SC_NPROCESSORS_ONLN 0x2 +#define _SC_PHYS_PAGES 0x4 + +__inline int GetNumLogicalProcessors(void) +{ + SYSTEM_INFO info_temp; + GetSystemInfo(&info_temp); + long int n_cores = info_temp.dwNumberOfProcessors; + return n_cores; +} + +__inline long sysconf(int name) +{ + long value = -1; + long page_size = -1; + SYSTEM_INFO sysInfo; + MEMORYSTATUSEX status; + + switch (name) + { + case _SC_NPROCESSORS_ONLN: + value = GetNumLogicalProcessors(); + break; + + case _SC_PAGESIZE: + GetSystemInfo(&sysInfo); + value = sysInfo.dwPageSize; + break; + + case _SC_PHYS_PAGES: + status.dwLength = sizeof(status); + page_size = sysconf(_SC_PAGESIZE); + if (GlobalMemoryStatusEx(&status) && page_size != -1) { + value = status.ullTotalPhys / page_size; + } + break; + default: + break; + } + + return value; +} + #endif /* unistd.h */ -- 1.9.0.msysgit.0 _______________________________________________ dev mailing list dev@openvswitch.org http://openvswitch.org/mailman/listinfo/dev