typedef int (*virNWFilterRuleDisplayInstanceData)(virConnectPtr conn,
void *_inst);
+typedef int (*virNWFilterCanApplyBasicRules)(void);
+
+typedef int (*virNWFilterApplyBasicRules)(const char *ifname,
+ const unsigned char *macaddr);
+
+typedef int (*virNWFilterApplyDHCPOnlyRules)(const char *ifname,
+ const unsigned char *macaddr,
+ const char *dhcpserver);
+
+typedef int (*virNWFilterRemoveBasicRules)(const char *ifname);
+
enum techDrvFlags {
TECHDRV_FLAG_INITIALIZED = (1 << 0),
};
virNWFilterRuleAllTeardown allTeardown;
virNWFilterRuleFreeInstanceData freeRuleInstance;
virNWFilterRuleDisplayInstanceData displayRuleInstance;
+
+ virNWFilterCanApplyBasicRules canApplyBasicRules;
+ virNWFilterApplyBasicRules applyBasicRules;
+ virNWFilterApplyDHCPOnlyRules applyDHCPOnlyRules;
+ virNWFilterRemoveBasicRules removeBasicRules;
};
#define MATCH_PHYSDEV_OUT m_physdev_out_str
+static int ebtablesRemoveBasicRules(const char *ifname);
static int ebiptablesDriverInit(void);
static void ebiptablesDriverShutdown(void);
}
+/**
+ * ebiptablesCanApplyBasicRules
+ *
+ * Determine whether this driver can apply the basic rules, meaning
+ * run ebtablesApplyBasicRules and ebtablesApplyDHCPOnlyRules.
+ * In case of this driver we need the ebtables tool available.
+ */
+static int
+ebiptablesCanApplyBasicRules(void) {
+ return (ebtables_cmd_path != NULL);
+}
+
/**
* ebtablesApplyBasicRules
*
* - filtering for MAC address spoofing
* - allowing IPv4 & ARP traffic
*/
-int
+static int
ebtablesApplyBasicRules(const char *ifname,
const unsigned char *macaddr)
{
* Apply filtering rules so that the VM can only send and receive
* DHCP traffic and nothing else.
*/
-int
+static int
ebtablesApplyDHCPOnlyRules(const char *ifname,
const unsigned char *macaddr,
const char *dhcpserver)
}
-int
+static int
ebtablesRemoveBasicRules(const char *ifname)
{
virBuffer buf = VIR_BUFFER_INITIALIZER;
.removeRules = ebiptablesRemoveRules,
.freeRuleInstance = ebiptablesFreeRuleInstance,
.displayRuleInstance = ebiptablesDisplayRuleInstance,
+
+ .canApplyBasicRules = ebiptablesCanApplyBasicRules,
+ .applyBasicRules = ebtablesApplyBasicRules,
+ .applyDHCPOnlyRules = ebtablesApplyDHCPOnlyRules,
+ .removeBasicRules = ebtablesRemoveBasicRules,
};
# define EBIPTABLES_DRIVER_ID "ebiptables"
-
-int ebtablesApplyBasicRules(const char *ifname,
- const unsigned char *macaddr);
-int ebtablesApplyDHCPOnlyRules(const char *ifname,
- const unsigned char *macaddr,
- const char *dhcpServer);
-int ebtablesRemoveBasicRules(const char *ifname);
-
#endif
if (virHashLookup(missing_vars->hashTable,
NWFILTER_STD_VAR_IP) != NULL) {
if (virNWFilterLookupLearnReq(ifname) == NULL) {
- rc = virNWFilterLearnIPAddress(ifname,
+ rc = virNWFilterLearnIPAddress(techdriver,
+ ifname,
linkdev,
nettype, macaddr,
filter->name,
char *filter= NULL;
uint16_t etherType;
enum howDetect howDetected = 0;
+ virNWFilterTechDriverPtr techdriver = req->techdriver;
req->status = 0;
if (handle)
pcap_close(handle);
- ebtablesRemoveBasicRules(req->ifname);
+ techdriver->removeBasicRules(req->ifname);
if (req->status == 0) {
int ret;
/**
* virNWFilterLearnIPAddress
- * @conn: pointer to virConnect object
+ * @techdriver : driver to build firewalls
* @ifname: the name of the interface
* @linkdev : the name of the link device; currently only used in case of a
* macvtap device
* firewall rules on the interface.
*/
int
-virNWFilterLearnIPAddress(const char *ifname,
+virNWFilterLearnIPAddress(virNWFilterTechDriverPtr techdriver,
+ const char *ifname,
const char *linkdev,
enum virDomainNetType nettype,
const unsigned char *macaddr,
req->filterparams = ht;
ht = NULL;
req->howDetect = howDetect;
+ req->techdriver = techdriver;
rc = virNWFilterRegisterLearnReq(req);
switch (howDetect) {
case DETECT_DHCP:
- if (ebtablesApplyDHCPOnlyRules(ifname,
- macaddr,
- NULL))
+ if (techdriver->applyDHCPOnlyRules(ifname,
+ macaddr,
+ NULL))
goto err_free_ht;
break;
default:
- if (ebtablesApplyBasicRules(ifname,
- macaddr))
+ if (techdriver->applyBasicRules(ifname,
+ macaddr))
goto err_free_ht;
}
return 0;
err_remove_rules:
- ebtablesRemoveBasicRules(ifname);
+ techdriver->removeBasicRules(ifname);
err_free_ht:
virNWFilterHashTableFree(ht);
err_no_ht:
#else
int
-virNWFilterLearnIPAddress(const char *ifname ATTRIBUTE_UNUSED,
+virNWFilterLearnIPAddress(virNWFilterTechDriverPtr techdriver ATTRIBUTE_UNUSED,
+ const char *ifname ATTRIBUTE_UNUSED,
const char *linkdev ATTRIBUTE_UNUSED,
enum virDomainNetType nettype ATTRIBUTE_UNUSED,
const unsigned char *macaddr ATTRIBUTE_UNUSED,
typedef struct _virNWFilterIPAddrLearnReq virNWFilterIPAddrLearnReq;
typedef virNWFilterIPAddrLearnReq *virNWFilterIPAddrLearnReqPtr;
struct _virNWFilterIPAddrLearnReq {
+ virNWFilterTechDriverPtr techdriver;
char ifname[IF_NAMESIZE];
char linkdev[IF_NAMESIZE];
enum virDomainNetType nettype;
pthread_t thread;
};
-int virNWFilterLearnIPAddress(const char *ifname,
+int virNWFilterLearnIPAddress(virNWFilterTechDriverPtr techdriver,
+ const char *ifname,
const char *linkdev,
enum virDomainNetType nettype,
const unsigned char *macaddr,