network_conf.h 6.7 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 35 36 37 38 39 40 41 42 43 44 45 46

/* 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 {
47 48
    virSocketAddr start;
    virSocketAddr end;
49 50
};

51 52 53 54 55
typedef struct _virNetworkDHCPHostDef virNetworkDHCPHostDef;
typedef virNetworkDHCPHostDef *virNetworkDHCPHostDefPtr;
struct _virNetworkDHCPHostDef {
    char *mac;
    char *name;
56
    virSocketAddr ip;
57 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
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;
   };

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

    char *bridge;       /* Name of bridge device */
92
    char *domain;
93
    unsigned long delay;   /* Bridge forward delay (ms) */
94
    unsigned int stp :1; /* Spanning tree protocol */
95 96 97 98

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

99 100
    size_t nips;
    virNetworkIpDefPtr ips; /* ptr to array of IP addresses on this network */
101 102 103 104 105
};

typedef struct _virNetworkObj virNetworkObj;
typedef virNetworkObj *virNetworkObjPtr;
struct _virNetworkObj {
106
    virMutex lock;
107

108 109 110 111 112 113 114
    pid_t dnsmasqPid;
    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 */
115
};
116

117 118 119 120 121
typedef struct _virNetworkObjList virNetworkObjList;
typedef virNetworkObjList *virNetworkObjListPtr;
struct _virNetworkObjList {
    unsigned int count;
    virNetworkObjPtr *objs;
122 123 124
};

static inline int
D
Daniel P. Berrange 已提交
125
virNetworkObjIsActive(const virNetworkObjPtr net)
126 127 128 129
{
    return net->active;
}

130
virNetworkObjPtr virNetworkFindByUUID(const virNetworkObjListPtr nets,
131
                                      const unsigned char *uuid);
132
virNetworkObjPtr virNetworkFindByName(const virNetworkObjListPtr nets,
133 134 135 136 137
                                      const char *name);


void virNetworkDefFree(virNetworkDefPtr def);
void virNetworkObjFree(virNetworkObjPtr net);
138
void virNetworkObjListFree(virNetworkObjListPtr vms);
139

140
virNetworkObjPtr virNetworkAssignDef(virNetworkObjListPtr nets,
141
                                     const virNetworkDefPtr def);
142
void virNetworkRemoveInactive(virNetworkObjListPtr nets,
143 144
                              const virNetworkObjPtr net);

145 146 147
virNetworkDefPtr virNetworkDefParseString(const char *xmlStr);
virNetworkDefPtr virNetworkDefParseFile(const char *filename);
virNetworkDefPtr virNetworkDefParseNode(xmlDocPtr xml,
148 149
                                        xmlNodePtr root);

150
char *virNetworkDefFormat(const virNetworkDefPtr def);
151

152 153 154 155 156 157
virNetworkIpDefPtr
virNetworkDefGetIpByIndex(const virNetworkDefPtr def,
                          int family, size_t n);
int virNetworkIpDefPrefix(const virNetworkIpDefPtr def);
int virNetworkIpDefNetmask(const virNetworkIpDefPtr def,
                           virSocketAddrPtr netmask);
158

159
int virNetworkSaveXML(const char *configDir,
160 161 162
                      virNetworkDefPtr def,
                      const char *xml);

163
int virNetworkSaveConfig(const char *configDir,
164
                         virNetworkDefPtr def);
165

166
virNetworkObjPtr virNetworkLoadConfig(virNetworkObjListPtr nets,
167 168 169 170
                                      const char *configDir,
                                      const char *autostartDir,
                                      const char *file);

171
int virNetworkLoadAllConfigs(virNetworkObjListPtr nets,
172 173 174
                             const char *configDir,
                             const char *autostartDir);

175
int virNetworkDeleteConfig(const char *configDir,
176
                           const char *autostartDir,
177 178
                           virNetworkObjPtr net);

179
char *virNetworkConfigFile(const char *dir,
180 181
                           const char *name);

182 183 184 185
int virNetworkBridgeInUse(const virNetworkObjListPtr nets,
                          const char *bridge,
                          const char *skipname);

186
char *virNetworkAllocateBridge(const virNetworkObjListPtr nets,
187
                               const char *template);
188

189
int virNetworkSetBridgeName(const virNetworkObjListPtr nets,
190 191
                            virNetworkDefPtr def,
                            int check_collision);
192

193 194 195 196
int virNetworkObjIsDuplicate(virNetworkObjListPtr doms,
                             virNetworkDefPtr def,
                             unsigned int check_active);

D
Daniel P. Berrange 已提交
197 198 199
void virNetworkObjLock(virNetworkObjPtr obj);
void virNetworkObjUnlock(virNetworkObjPtr obj);

200
#endif /* __NETWORK_CONF_H__ */