2009-10-22 14:34:43 +00:00
|
|
|
/*
|
|
|
|
* network.h: network helper APIs for libvirt
|
|
|
|
*
|
|
|
|
* Copyright (C) 2009-2009 Red Hat, Inc.
|
|
|
|
*
|
|
|
|
* See COPYING.LIB for the License of this software
|
|
|
|
*
|
|
|
|
* Daniel Veillard <veillard@redhat.com>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __VIR_NETWORK_H__
|
2010-03-09 18:22:22 +00:00
|
|
|
# define __VIR_NETWORK_H__
|
2009-10-22 14:34:43 +00:00
|
|
|
|
2010-03-09 18:22:22 +00:00
|
|
|
# include "internal.h"
|
2009-10-22 14:34:43 +00:00
|
|
|
|
2010-03-09 18:22:22 +00:00
|
|
|
# include <sys/types.h>
|
|
|
|
# include <sys/socket.h>
|
2010-10-21 14:45:12 +00:00
|
|
|
# ifdef HAVE_SYS_UN_H
|
|
|
|
# include <sys/un.h>
|
|
|
|
# endif
|
2010-03-09 18:22:22 +00:00
|
|
|
# include <netdb.h>
|
2010-11-13 13:07:53 +00:00
|
|
|
# include <netinet/in.h>
|
2009-10-22 14:34:43 +00:00
|
|
|
|
2010-10-20 13:21:15 +00:00
|
|
|
typedef struct {
|
|
|
|
union {
|
2010-10-20 14:13:00 +00:00
|
|
|
struct sockaddr sa;
|
2010-10-20 13:21:15 +00:00
|
|
|
struct sockaddr_storage stor;
|
|
|
|
struct sockaddr_in inet4;
|
|
|
|
struct sockaddr_in6 inet6;
|
2010-10-21 14:45:12 +00:00
|
|
|
# ifdef HAVE_SYS_UN_H
|
|
|
|
struct sockaddr_un un;
|
|
|
|
# endif
|
2010-10-20 13:21:15 +00:00
|
|
|
} data;
|
|
|
|
socklen_t len;
|
2009-10-22 14:34:43 +00:00
|
|
|
} virSocketAddr;
|
2010-10-20 13:21:15 +00:00
|
|
|
|
Convert virNetwork to use virSocketAddr everywhere
Instead of storing the IP address string in virNetwork related
structs, store the parsed virSocketAddr. This will make it
easier to add IPv6 support in the future, by letting driver
code directly check what address family is present
* src/conf/network_conf.c, src/conf/network_conf.h,
src/network/bridge_driver.c: Convert to use virSocketAddr
in virNetwork, instead of char *.
* src/util/bridge.c, src/util/bridge.h,
src/util/dnsmasq.c, src/util/dnsmasq.h,
src/util/iptables.c, src/util/iptables.h: Convert to
take a virSocketAddr instead of char * for any IP
address parameters
* src/util/network.h: Add macros to determine if an address
is set, and what address family is set.
2010-10-21 12:14:33 +00:00
|
|
|
# define VIR_SOCKET_HAS_ADDR(s) \
|
|
|
|
((s)->data.sa.sa_family != AF_UNSPEC)
|
|
|
|
|
|
|
|
# define VIR_SOCKET_IS_FAMILY(s, f) \
|
|
|
|
((s)->data.sa.sa_family == f)
|
|
|
|
|
2010-11-26 18:51:44 +00:00
|
|
|
# define VIR_SOCKET_FAMILY(s) \
|
|
|
|
((s)->data.sa.sa_family)
|
|
|
|
|
2009-10-22 14:34:43 +00:00
|
|
|
typedef virSocketAddr *virSocketAddrPtr;
|
|
|
|
|
|
|
|
int virSocketParseAddr (const char *val,
|
|
|
|
virSocketAddrPtr addr,
|
|
|
|
int hint);
|
|
|
|
|
|
|
|
int virSocketParseIpv4Addr(const char *val,
|
|
|
|
virSocketAddrPtr addr);
|
|
|
|
|
|
|
|
int virSocketParseIpv6Addr(const char *val,
|
|
|
|
virSocketAddrPtr addr);
|
|
|
|
|
2009-11-02 14:42:47 +00:00
|
|
|
char * virSocketFormatAddr(virSocketAddrPtr addr);
|
2010-10-20 14:13:00 +00:00
|
|
|
char * virSocketFormatAddrFull(virSocketAddrPtr addr,
|
|
|
|
bool withService,
|
|
|
|
const char *separator);
|
2009-11-02 14:42:47 +00:00
|
|
|
|
|
|
|
int virSocketSetPort(virSocketAddrPtr addr, int port);
|
|
|
|
|
|
|
|
int virSocketGetPort(virSocketAddrPtr addr);
|
|
|
|
|
2009-10-22 14:34:43 +00:00
|
|
|
int virSocketGetRange (virSocketAddrPtr start,
|
|
|
|
virSocketAddrPtr end);
|
|
|
|
|
|
|
|
int virSocketAddrIsNetmask(virSocketAddrPtr netmask);
|
|
|
|
|
|
|
|
int virSocketCheckNetmask (virSocketAddrPtr addr1,
|
|
|
|
virSocketAddrPtr addr2,
|
|
|
|
virSocketAddrPtr netmask);
|
2010-12-31 11:20:43 +00:00
|
|
|
int virSocketAddrMask (const virSocketAddrPtr addr,
|
|
|
|
const virSocketAddrPtr netmask,
|
|
|
|
virSocketAddrPtr network);
|
|
|
|
int virSocketAddrMaskByPrefix(const virSocketAddrPtr addr,
|
|
|
|
unsigned int prefix,
|
|
|
|
virSocketAddrPtr network);
|
2010-12-31 02:33:24 +00:00
|
|
|
int virSocketAddrBroadcast(const virSocketAddrPtr addr,
|
|
|
|
const virSocketAddrPtr netmask,
|
|
|
|
virSocketAddrPtr broadcast);
|
|
|
|
int virSocketAddrBroadcastByPrefix(const virSocketAddrPtr addr,
|
|
|
|
unsigned int prefix,
|
|
|
|
virSocketAddrPtr broadcast);
|
2010-03-30 15:18:04 +00:00
|
|
|
|
|
|
|
int virSocketGetNumNetmaskBits(const virSocketAddrPtr netmask);
|
2010-11-26 18:51:44 +00:00
|
|
|
int virSocketAddrPrefixToNetmask(unsigned int prefix,
|
|
|
|
virSocketAddrPtr netmask,
|
|
|
|
int family);
|
2010-03-30 15:18:04 +00:00
|
|
|
|
2009-10-22 14:34:43 +00:00
|
|
|
#endif /* __VIR_NETWORK_H__ */
|