network_conf.h 6.9 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
/*
 * network_conf.h: network XML handling
 *
 * Copyright (C) 2006-2008 Red Hat, Inc.
 * Copyright (C) 2006-2008 Daniel P. Berrange
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
 *
 * Author: Daniel P. Berrange <berrange@redhat.com>
 */

#ifndef __NETWORK_CONF_H__
25
# define __NETWORK_CONF_H__
26

27 28 29
# include <libxml/parser.h>
# include <libxml/tree.h>
# include <libxml/xpath.h>
30

31 32
# include "internal.h"
# include "threads.h"
33
# include "network.h"
34
# include "util.h"
35 36 37 38 39 40 41 42 43 44 45 46 47

/* 2 possible types of forwarding */
enum virNetworkForwardType {
    VIR_NETWORK_FORWARD_NONE   = 0,
    VIR_NETWORK_FORWARD_NAT,
    VIR_NETWORK_FORWARD_ROUTE,

    VIR_NETWORK_FORWARD_LAST,
};

typedef struct _virNetworkDHCPRangeDef virNetworkDHCPRangeDef;
typedef virNetworkDHCPRangeDef *virNetworkDHCPRangeDefPtr;
struct _virNetworkDHCPRangeDef {
48 49
    virSocketAddr start;
    virSocketAddr end;
50 51
};

52 53 54 55 56
typedef struct _virNetworkDHCPHostDef virNetworkDHCPHostDef;
typedef virNetworkDHCPHostDef *virNetworkDHCPHostDefPtr;
struct _virNetworkDHCPHostDef {
    char *mac;
    char *name;
57
    virSocketAddr ip;
58 59
};

60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
typedef struct _virNetworkIpDef virNetworkIpDef;
typedef virNetworkIpDef *virNetworkIpDefPtr;
struct _virNetworkIpDef {
    char *family;               /* ipv4 or ipv6 - default is ipv4 */
    virSocketAddr address;      /* Bridge IP address */

    /* One or the other of the following two will be used for a given
     * IP address, but never both. The parser guarantees this.
     * Use virNetworkIpDefPrefix/virNetworkIpDefNetmask rather
     * than accessing the data directly - these utility functions
     * will convert one into the other as necessary.
     */
    unsigned int prefix;        /* ipv6 - only prefix allowed */
    virSocketAddr netmask;      /* ipv4 - either netmask or prefix specified */

    unsigned int nranges;        /* Zero or more dhcp ranges */
    virNetworkDHCPRangeDefPtr ranges;

    unsigned int nhosts;         /* Zero or more dhcp hosts */
    virNetworkDHCPHostDefPtr hosts;

    char *tftproot;
    char *bootfile;
    virSocketAddr bootserver;
   };

86 87 88 89 90 91 92
typedef struct _virNetworkDef virNetworkDef;
typedef virNetworkDef *virNetworkDefPtr;
struct _virNetworkDef {
    unsigned char uuid[VIR_UUID_BUFLEN];
    char *name;

    char *bridge;       /* Name of bridge device */
93
    char *domain;
94
    unsigned long delay;   /* Bridge forward delay (ms) */
95
    unsigned int stp :1; /* Spanning tree protocol */
96 97
    unsigned char mac[VIR_MAC_BUFLEN]; /* mac address of bridge device */
    bool mac_specified;
98 99 100 101

    int forwardType;    /* One of virNetworkForwardType constants */
    char *forwardDev;   /* Destination device for forwarding */

102 103
    size_t nips;
    virNetworkIpDefPtr ips; /* ptr to array of IP addresses on this network */
104 105 106 107 108
};

typedef struct _virNetworkObj virNetworkObj;
typedef virNetworkObj *virNetworkObjPtr;
struct _virNetworkObj {
109
    virMutex lock;
110

111
    pid_t dnsmasqPid;
112
    pid_t radvdPid;
113 114 115 116 117 118
    unsigned int active : 1;
    unsigned int autostart : 1;
    unsigned int persistent : 1;

    virNetworkDefPtr def; /* The current definition */
    virNetworkDefPtr newDef; /* New definition to activate at shutdown */
119
};
120

121 122 123 124 125
typedef struct _virNetworkObjList virNetworkObjList;
typedef virNetworkObjList *virNetworkObjListPtr;
struct _virNetworkObjList {
    unsigned int count;
    virNetworkObjPtr *objs;
126 127 128
};

static inline int
D
Daniel P. Berrange 已提交
129
virNetworkObjIsActive(const virNetworkObjPtr net)
130 131 132 133
{
    return net->active;
}

134
virNetworkObjPtr virNetworkFindByUUID(const virNetworkObjListPtr nets,
135
                                      const unsigned char *uuid);
136
virNetworkObjPtr virNetworkFindByName(const virNetworkObjListPtr nets,
137 138 139 140 141
                                      const char *name);


void virNetworkDefFree(virNetworkDefPtr def);
void virNetworkObjFree(virNetworkObjPtr net);
142
void virNetworkObjListFree(virNetworkObjListPtr vms);
143

144
virNetworkObjPtr virNetworkAssignDef(virNetworkObjListPtr nets,
145
                                     const virNetworkDefPtr def);
146
void virNetworkRemoveInactive(virNetworkObjListPtr nets,
147 148
                              const virNetworkObjPtr net);

149 150 151
virNetworkDefPtr virNetworkDefParseString(const char *xmlStr);
virNetworkDefPtr virNetworkDefParseFile(const char *filename);
virNetworkDefPtr virNetworkDefParseNode(xmlDocPtr xml,
152 153
                                        xmlNodePtr root);

154
char *virNetworkDefFormat(const virNetworkDefPtr def);
155

156 157 158 159 160 161
virNetworkIpDefPtr
virNetworkDefGetIpByIndex(const virNetworkDefPtr def,
                          int family, size_t n);
int virNetworkIpDefPrefix(const virNetworkIpDefPtr def);
int virNetworkIpDefNetmask(const virNetworkIpDefPtr def,
                           virSocketAddrPtr netmask);
162

163
int virNetworkSaveXML(const char *configDir,
164 165 166
                      virNetworkDefPtr def,
                      const char *xml);

167
int virNetworkSaveConfig(const char *configDir,
168
                         virNetworkDefPtr def);
169

170
virNetworkObjPtr virNetworkLoadConfig(virNetworkObjListPtr nets,
171 172 173 174
                                      const char *configDir,
                                      const char *autostartDir,
                                      const char *file);

175
int virNetworkLoadAllConfigs(virNetworkObjListPtr nets,
176 177 178
                             const char *configDir,
                             const char *autostartDir);

179
int virNetworkDeleteConfig(const char *configDir,
180
                           const char *autostartDir,
181 182
                           virNetworkObjPtr net);

183
char *virNetworkConfigFile(const char *dir,
184 185
                           const char *name);

186 187 188 189
int virNetworkBridgeInUse(const virNetworkObjListPtr nets,
                          const char *bridge,
                          const char *skipname);

190
char *virNetworkAllocateBridge(const virNetworkObjListPtr nets,
191
                               const char *template);
192

193
int virNetworkSetBridgeName(const virNetworkObjListPtr nets,
194 195
                            virNetworkDefPtr def,
                            int check_collision);
196

197 198
void virNetworkSetBridgeMacAddr(virNetworkDefPtr def);

199 200 201 202
int virNetworkObjIsDuplicate(virNetworkObjListPtr doms,
                             virNetworkDefPtr def,
                             unsigned int check_active);

D
Daniel P. Berrange 已提交
203 204 205
void virNetworkObjLock(virNetworkObjPtr obj);
void virNetworkObjUnlock(virNetworkObjPtr obj);

206
#endif /* __NETWORK_CONF_H__ */