The nova.network.linux_net Module

Implements vlans, bridges, and iptables rules using linux utilities.

class IptablesManager(execute=None)

Bases: object

Wrapper for iptables.

See IptablesTable for some usage docs

A number of chains are set up to begin with.

First, nova-filter-top. It’s added at the top of FORWARD and OUTPUT. Its name is not wrapped, so it’s shared between the various nova workers. It’s intended for rules that need to live at the top of the FORWARD and OUTPUT chains. It’s in both the ipv4 and ipv6 set of tables.

For ipv4 and ipv6, the built-in INPUT, OUTPUT, and FORWARD filter chains are wrapped, meaning that the “real” INPUT chain has a rule that jumps to the wrapped INPUT chain, etc. Additionally, there’s a wrapped chain named “local” which is jumped to from nova-filter-top.

For ipv4, the built-in PREROUTING, OUTPUT, and POSTROUTING nat chains are wrapped in the same was as the built-in filter chains. Additionally, there’s a snat chain that is applied after the POSTROUTING chain.

apply()
defer_apply_off()
defer_apply_on()
dirty()
class IptablesRule(chain, rule, wrap=True, top=False)

Bases: object

An iptables rule.

You shouldn’t need to use this class directly, it’s only used by IptablesManager.

class IptablesTable

Bases: object

An iptables table.

add_chain(name, wrap=True)

Adds a named chain to the table.

The chain name is wrapped to be unique for the component creating it, so different components of Nova can safely create identically named chains without interfering with one another.

At the moment, its wrapped name is <binary name>-<chain name>, so if nova-compute creates a chain named ‘OUTPUT’, it’ll actually end up named ‘nova-compute-OUTPUT’.

add_rule(chain, rule, wrap=True, top=False)

Add a rule to the table.

This is just like what you’d feed to iptables, just without the ‘-A <chain name>’ bit at the start.

However, if you need to jump to one of your wrapped chains, prepend its name with a ‘$’ which will ensure the wrapping is applied correctly.

empty_chain(chain, wrap=True)

Remove all rules from a chain.

has_chain(name, wrap=True)
remove_chain(name, wrap=True)

Remove named chain.

This removal “cascades”. All rule in the chain are removed, as are all rules in other chains that jump to it.

If the chain is not found, this is merely logged.

remove_rule(chain, rule, wrap=True, top=False)

Remove a rule from a chain.

Note: The rule must be exactly identical to the one that was added. You cannot switch arguments around like you can with the iptables CLI tool.

remove_rules_regex(regex)

Remove all rules matching regex.

class LinuxBridgeInterfaceDriver

Bases: nova.network.linux_net.LinuxNetInterfaceDriver

static ensure_bridge(*args, **kwargs)

Create a bridge unless it already exists.

Parameters:
  • interface – the interface to create the bridge on.
  • net_attrs – dictionary with attributes used to create bridge.
  • gateway – whether or not the bridge is a gateway.
  • filtering – whether or not to create filters on the bridge.

If net_attrs is set, it will add the net_attrs[‘gateway’] to the bridge using net_attrs[‘broadcast’] and net_attrs[‘cidr’]. It will also add the ip_v6 address specified in net_attrs[‘cidr_v6’] if use_ipv6 is set.

The code will attempt to move any IPs that already exist on the interface onto the bridge and reset the default gateway if necessary.

static ensure_vlan(*args, **kwargs)

Create a vlan unless it already exists.

static ensure_vlan_bridge(vlan_num, bridge, bridge_interface, net_attrs=None, mac_address=None, mtu=None)

Create a vlan and bridge unless they already exist.

get_dev(network)
plug(network, mac_address, gateway=True)
static remove_bridge(*args, **kwargs)

Delete a bridge.

static remove_vlan(*args, **kwargs)

Delete a vlan.

static remove_vlan_bridge(vlan_num, bridge)

Delete a bridge and vlan.

unplug(network, gateway=True)
class LinuxNetInterfaceDriver

Bases: object

Abstract class that defines generic network host API for all Linux interface drivers.

get_dev(network)

Get device name.

plug(network, mac_address)

Create Linux device, return device name.

unplug(network)

Destroy Linux device, return device name.

class LinuxOVSInterfaceDriver

Bases: nova.network.linux_net.LinuxNetInterfaceDriver

get_dev(network)
plug(network, mac_address, gateway=True)
unplug(network)
class NeutronLinuxBridgeInterfaceDriver

Bases: nova.network.linux_net.LinuxNetInterfaceDriver

BRIDGE_NAME_PREFIX = 'brq'
GATEWAY_INTERFACE_PREFIX = 'gw-'
get_bridge(network)
get_dev(network)
plug(network, mac_address, gateway=True)
unplug(network)
add_snat_rule(ip_range, is_external=False)
bind_floating_ip(floating_ip, device)

Bind IP to public interface.

clean_conntrack(fixed_ip)
create_fp_dev(dev, sockpath, sockmode)
create_ivs_vif_port(dev, iface_id, mac, instance_id)
create_ovs_vif_port(bridge, dev, iface_id, mac, instance_id, mtu=None, interface_type=None)
create_tap_dev(dev, mac_address=None)
delete_bridge_dev(dev)

Delete a network bridge.

delete_fp_dev(dev)
delete_ivs_vif_port(dev)
delete_net_dev(dev)

Delete a network device only if it exists.

delete_ovs_vif_port(bridge, dev, delete_dev=True)
device_exists(device)

Check if ethernet device exists.

ensure_ebtables_rules(*args, **kwargs)
ensure_floating_forward(floating_ip, fixed_ip, device, network)

Ensure floating IP forwarding rule.

ensure_metadata_ip()

Sets up local metadata IP.

ensure_vpn_forward(public_ip, port, private_ip)

Sets up forwarding rules for vlan.

floating_ebtables_rules(fixed_ip, network)

Makes sure only in-network traffic is bridged.

floating_forward_rules(floating_ip, fixed_ip, device)
get_binary_name()

Grab the name of the binary we’re running in.

get_dev(network)
get_dhcp_hosts(context, network_ref, fixedips)

Get network’s hosts config in dhcp-host format.

get_dhcp_leases(context, network_ref)

Return a network’s hosts config in dnsmasq leasefile format.

get_dhcp_opts(context, network_ref, fixedips)

Get network’s hosts config in dhcp-opts format.

get_dns_hosts(context, network_ref)

Get network’s DNS hosts in hosts format.

get_gateway_rules(bridge)
init_host(ip_range, is_external=False)

Basic networking setup goes here.

initialize_gateway_device(*args, **kwargs)
is_pid_cmdline_correct(pid, match)

Ensure that the cmdline for a pid seems sane

Because pids are recycled, blindly killing by pid is something to avoid. This provides the ability to include a substring that is expected in the cmdline as a safety check.

isolate_dhcp_address(interface, address)
kill_dhcp(dev)
metadata_accept()

Create the filter accept rule for metadata.

metadata_forward()

Create forwarding rule for metadata.

plug(network, mac_address, gateway=True)
release_dhcp(dev, address, mac_address)
remove_ebtables_rules(*args, **kwargs)
remove_floating_forward(floating_ip, fixed_ip, device, network)

Remove forwarding for floating IP.

remove_isolate_dhcp_address(interface, address)
restart_dhcp(*args, **kwargs)

(Re)starts a dnsmasq server for a given network.

If a dnsmasq instance is already running then send a HUP signal causing it to reload, otherwise spawn a new instance.

send_arp_for_ip(ip, device, count)
set_vf_interface_vlan(pci_addr, mac_addr, vlan=0)
unbind_floating_ip(floating_ip, device)

Unbind a public IP from public interface.

unplug(network)
update_dhcp(context, dev, network_ref)
update_dns(context, dev, network_ref)
update_ra(*args, **kwargs)
write_to_file(file, data, mode='w')

Previous topic

The nova.network.ldapdns Module

Next topic

The nova.network.manager Module

Project Source

This Page