1 /*
2  * interface_conf.h: interface XML handling entry points
3  *
4  * Copyright (C) 2006-2009, 2013 Red Hat, Inc.
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library.  If not, see
18  * <http://www.gnu.org/licenses/>.
19  */
20 
21 #pragma once
22 
23 #include <libxml/parser.h>
24 #include <libxml/tree.h>
25 #include <libxml/xpath.h>
26 
27 #include "internal.h"
28 #include "virthread.h"
29 #include "device_conf.h"
30 #include "virenum.h"
31 
32 /* There is currently 3 types of interfaces */
33 
34 typedef enum {
35     VIR_INTERFACE_TYPE_ETHERNET,  /* simple ethernet */
36     VIR_INTERFACE_TYPE_BRIDGE,    /* bridge interface */
37     VIR_INTERFACE_TYPE_BOND,      /* bonding interface */
38     VIR_INTERFACE_TYPE_VLAN,      /* vlan description */
39 
40     VIR_INTERFACE_TYPE_LAST,
41 } virInterfaceType;
42 
43 VIR_ENUM_DECL(virInterface);
44 
45 /* types of start mode */
46 
47 typedef enum {
48     VIR_INTERFACE_START_UNSPECIFIED = 0, /* not given in config */
49     VIR_INTERFACE_START_NONE,     /* specified as not defined */
50     VIR_INTERFACE_START_ONBOOT,   /* startup at boot */
51     VIR_INTERFACE_START_HOTPLUG,  /* on hotplug */
52 } virInterfaceStartMode;
53 
54 typedef enum {
55     VIR_INTERFACE_BOND_NONE = 0,
56     VIR_INTERFACE_BOND_BALRR,     /* balance-rr */
57     VIR_INTERFACE_BOND_ABACKUP,   /* active backup */
58     VIR_INTERFACE_BOND_BALXOR,    /* balance-xor */
59     VIR_INTERFACE_BOND_BCAST,     /* broadcast */
60     VIR_INTERFACE_BOND_8023AD,    /* 802.3ad */
61     VIR_INTERFACE_BOND_BALTLB,    /* balance-tlb */
62     VIR_INTERFACE_BOND_BALALB,    /* balance-alb */
63 } virInterfaceBondMode;
64 
65 typedef enum {
66     VIR_INTERFACE_BOND_MONIT_NONE = 0,
67     VIR_INTERFACE_BOND_MONIT_MII, /* mii based monitoring */
68     VIR_INTERFACE_BOND_MONIT_ARP, /* arp based monitoring */
69 } virInterfaceBondMonit;
70 
71 typedef enum {
72     VIR_INTERFACE_BOND_MII_NONE = 0,
73     VIR_INTERFACE_BOND_MII_IOCTL, /* mii/ethtool ioctl */
74     VIR_INTERFACE_BOND_MII_NETIF, /* netif_carrier_ok */
75 } virInterfaceBondMiiCarrier;
76 
77 typedef enum {
78     VIR_INTERFACE_BOND_ARP_NONE = 0,
79     VIR_INTERFACE_BOND_ARP_ACTIVE, /* validate active */
80     VIR_INTERFACE_BOND_ARP_BACKUP, /* validate backup */
81     VIR_INTERFACE_BOND_ARP_ALL,    /* validate all */
82 } virInterfaceBondArpValid;
83 
84 struct _virInterfaceDef; /* forward declaration required for bridge/bond */
85 
86 typedef struct _virInterfaceBridgeDef virInterfaceBridgeDef;
87 struct _virInterfaceBridgeDef {
88     int stp;         /* 0, 1 or -1 if undefined */
89     char *delay;
90     int nbItf;       /* number of defined interfaces */
91     struct _virInterfaceDef **itf;/* interfaces */
92 };
93 
94 typedef struct _virInterfaceBondDef virInterfaceBondDef;
95 struct _virInterfaceBondDef {
96     int mode;                    /* virInterfaceBondMode */
97     int monit;                   /* virInterfaceBondMonit */
98     int frequency;               /* miimon frequency in ms */
99     int downdelay;               /* miimon downdelay */
100     int updelay;                 /* miimon updelay */
101     int carrier;                 /* virInterfaceBondMiiCarrier */
102     int interval;                /* arp monitoring interval */
103     char *target;                /* arp monitoring target */
104     int validate;                /* virInterfaceBondArpmValid */
105     int nbItf;                   /* number of defined interfaces */
106     struct _virInterfaceDef **itf; /* interfaces ethernet only */
107 };
108 
109 typedef struct _virInterfaceVlanDef virInterfaceVlanDef;
110 struct _virInterfaceVlanDef {
111     char *tag;       /* TAG for vlan */
112     char *dev_name;   /* device name for vlan */
113 };
114 
115 typedef struct _virInterfaceIPDef virInterfaceIPDef;
116 struct _virInterfaceIPDef {
117     char *address;   /* ip address */
118     int prefix;      /* ip prefix */
119 };
120 
121 
122 typedef struct _virInterfaceProtocolDef virInterfaceProtocolDef;
123 struct _virInterfaceProtocolDef {
124     char *family;    /* ipv4 or ipv6 */
125     int dhcp;        /* use dhcp */
126     int peerdns;     /* dhcp peerdns ? */
127     int autoconf;    /* only useful if family is ipv6 */
128     int nips;
129     virInterfaceIPDef **ips; /* ptr to array of ips[nips] */
130     char *gateway;   /* route gateway */
131 };
132 
133 
134 typedef struct _virInterfaceDef virInterfaceDef;
135 struct _virInterfaceDef {
136     int type;                /* interface type */
137     char *name;              /* interface name */
138     unsigned int mtu;        /* maximum transmit size in byte */
139     char *mac;               /* MAC address */
140     virNetDevIfLink lnk;    /* interface link info */
141 
142     virInterfaceStartMode startmode; /* how it is started */
143 
144     union {
145         virInterfaceBridgeDef bridge;
146         virInterfaceVlanDef vlan;
147         virInterfaceBondDef bond;
148     } data;
149 
150     int nprotos;
151     virInterfaceProtocolDef **protos; /* ptr to array of protos[nprotos] */
152 };
153 
154 void
155 virInterfaceDefFree(virInterfaceDef *def);
156 G_DEFINE_AUTOPTR_CLEANUP_FUNC(virInterfaceDef, virInterfaceDefFree);
157 
158 virInterfaceDef *
159 virInterfaceDefParseString(const char *xmlStr,
160                            unsigned int flags);
161 
162 virInterfaceDef *
163 virInterfaceDefParseFile(const char *filename);
164 
165 virInterfaceDef *
166 virInterfaceDefParseNode(xmlDocPtr xml,
167                          xmlNodePtr root);
168 
169 char *
170 virInterfaceDefFormat(const virInterfaceDef *def);
171 
172 #define VIR_CONNECT_LIST_INTERFACES_FILTERS_ACTIVE \
173                 (VIR_CONNECT_LIST_INTERFACES_ACTIVE | \
174                  VIR_CONNECT_LIST_INTERFACES_INACTIVE)
175