X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=lib%2Fsocket-util.c;h=4edf956b555f69beaaabbfd54eefc0837bc615c4;hb=bc7a5acdff087b7e7a162da42ae608a83f3cf902;hp=5fe9f98ba2fd9bc2c71793891f9a2fa876fbc503;hpb=fd94a42c43ff4a0e57a44bdc9ded1b7e1e63faaa;p=openvswitch diff --git a/lib/socket-util.c b/lib/socket-util.c index 5fe9f98b..4edf956b 100644 --- a/lib/socket-util.c +++ b/lib/socket-util.c @@ -30,6 +30,7 @@ #include #include #include +#include #include #include #include "dynamic-string.h" @@ -38,7 +39,7 @@ #include "poll-loop.h" #include "util.h" #include "vlog.h" -#if AF_PACKET && __linux__ +#if AF_PACKET && LINUX_DATAPATH #include #endif #ifdef HAVE_NETLINK @@ -50,11 +51,9 @@ VLOG_DEFINE_THIS_MODULE(socket_util); /* #ifdefs make it a pain to maintain code: you have to try to build both ways. * Thus, this file compiles all of the code regardless of the target, by - * writing "if (LINUX)" instead of "#ifdef __linux__". */ -#ifdef __linux__ -#define LINUX 1 -#else -#define LINUX 0 + * writing "if (LINUX_DATAPATH)" instead of "#ifdef __linux__". */ +#ifndef LINUX_DATAPATH +#define LINUX_DATAPATH 0 #endif #ifndef O_DIRECTORY @@ -91,15 +90,17 @@ xset_nonblocking(int fd) } } -static int +int set_dscp(int fd, uint8_t dscp) { + int val; + if (dscp > 63) { return EINVAL; } - dscp = dscp << 2; - if (setsockopt(fd, IPPROTO_IP, IP_TOS, &dscp, sizeof dscp)) { + val = dscp << 2; + if (setsockopt(fd, IPPROTO_IP, IP_TOS, &val, sizeof val)) { return errno; } @@ -180,7 +181,7 @@ lookup_ipv6(const char *host_name, struct in6_addr *addr) * Most Open vSwitch code should not use this because it causes deadlocks: * gethostbyname() sends out a DNS request but that starts a new flow for which * OVS must set up a flow, but it can't because it's waiting for a DNS reply. - * The synchronous lookup also delays other activty. (Of course we can solve + * The synchronous lookup also delays other activity. (Of course we can solve * this but it doesn't seem worthwhile quite yet.) */ int lookup_hostname(const char *host_name, struct in_addr *addr) @@ -263,7 +264,7 @@ drain_rcvbuf(int fd) * * On other Unix-like OSes, MSG_TRUNC has no effect in the flags * argument. */ - char buffer[LINUX ? 1 : 2048]; + char buffer[LINUX_DATAPATH ? 1 : 2048]; ssize_t n_bytes = recv(fd, buffer, sizeof buffer, MSG_TRUNC | MSG_DONTWAIT); if (n_bytes <= 0 || n_bytes >= rcvbuf) { @@ -332,7 +333,7 @@ make_sockaddr_un(const char *name, struct sockaddr_un *un, socklen_t *un_len, if (strlen(name) > MAX_UN_LEN) { static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 1); - if (LINUX) { + if (LINUX_DATAPATH) { /* 'name' is too long to fit in a sockaddr_un, but we have a * workaround for that on Linux: shorten it by opening a file * descriptor for the directory part of the name and indirecting @@ -611,6 +612,7 @@ exit: } } else if (fd >= 0) { close(fd); + fd = -1; } *fdp = fd; return error; @@ -890,6 +892,14 @@ xpipe(int fds[2]) } } +void +xpipe_nonblocking(int fds[2]) +{ + xpipe(fds); + xset_nonblocking(fds[0]); + xset_nonblocking(fds[1]); +} + void xsocketpair(int domain, int type, int protocol, int fds[2]) { @@ -977,7 +987,7 @@ describe_sockaddr(struct ds *string, int fd, } } #endif -#if AF_PACKET && __linux__ +#if AF_PACKET && LINUX_DATAPATH else if (ss.ss_family == AF_PACKET) { struct sockaddr_ll sll; @@ -1007,7 +1017,7 @@ describe_sockaddr(struct ds *string, int fd, } -#ifdef __linux__ +#ifdef LINUX_DATAPATH static void put_fd_filename(struct ds *string, int fd) { @@ -1051,7 +1061,7 @@ describe_fd(int fd) : S_ISFIFO(s.st_mode) ? "FIFO" : S_ISLNK(s.st_mode) ? "symbolic link" : "unknown")); -#ifdef __linux__ +#ifdef LINUX_DATAPATH put_fd_filename(&string, fd); #endif }