paradrop.core.config package

Submodules

paradrop.core.config.airshark module

class AirsharkInterfaceManager[source]

Bases: object

add_observer(observer)[source]
interface_available()[source]
remove_observer(observer)[source]
reset_interface()[source]
set_interface(interface)[source]
configure(update)[source]

Configure an Airshark interface.

paradrop.core.config.configservice module

configservice module:
This module is responsible for “poking” the proper host OS services to change the host OS config. This would include things like changing the networking, DHCP server settings, wifi, etc..
reloadAll(update)[source]

Reload pdconf configuration files.

reload_placeholder(update)[source]

This function successfully does nothing.

It serves as a placeholder so that we can attach an abort function to a specific point in the update pipeline.

paradrop.core.config.devices module

Detect physical devices that can be used by chutes.

This module detects physical devices (for now just network interfaces) that can be used by chutes. This includes WAN interfaces for Internet connectivity and WiFi interfaces which can host APs.

It also makes sure certain entries exist in the system UCI files for these devices, for example “wifi-device” sections. These are shared between chutes, so they only need to be added when missing.

class SysReader(phy)[source]

Bases: object

PCI_BUS_ID = <_sre.SRE_Pattern object>
USB_BUS_ID = <_sre.SRE_Pattern object>
getDeviceId(default='????')[source]

Return the device ID for the device.

This is a four-digit hexadecimal number. For example, our Qualcomm 802.11n chips have device ID 002a.

getSlotName(default='????')[source]

Return the PCI/USB slot name for the device.

Example: “pci/0000:04:00.0” or “usb/1-1:1.0”

getVendorId(default='????')[source]

Return the vendor ID for the device.

This is a four-digit hexadecimal number. For example, our Qualcomm 802.11n chips have vendor ID 168c.

read_uevent()[source]

Read the device uevent file and return the contents as a dictionary.

class UCIBuilder[source]

Bases: object

UCIBuilder helps aggregate UCI configuration sections for writing to files.

FILES = ['dhcp', 'network', 'firewall', 'wireless', 'qos']
add(file_, type_, options, name=None)[source]

Add a new configuration section.

getSections(file_)[source]

Get sections associated with a single file.

Returns: list of tuples, [(config, options)]

write()[source]

Write all of the configuration sections to files.

checkSystemDevices(update)[source]

Check whether expected devices are present.

This may reboot the machine if devices are missing and the host config is set to do that.

detectSystemDevices()[source]

Detect devices on the system.

The result is three lists stored in a dictionary. The three lists are indexed by ‘wan’, ‘wifi’, and ‘lan’. Other devices may be supported by adding additional lists.

Within each list, a device is represented by a dictionary. For all devices, the ‘name’ and ‘mac’ fields are defined. For WiFi devices, the ‘phy’ is defined in addition. Later, we may fill in more device information (e.g. what channels a WiFi card supports).

flushWirelessInterfaces(phy)[source]

Remove all virtual interfaces associated with a wireless device.

This should be used before giving a chute exclusive access to a device (e.g. monitor mode), so that it does not inherit unexpected interfaces.

getMACAddress(ifname)[source]
getPhyMACAddress(phy)[source]
getSystemDevices(update)[source]

Detect devices on the system.

Store device information in cache key “networkDevices” as well as “networkDevicesByName”.

getWirelessPhyName(ifname)[source]
get_hardware_serial()[source]

Get hardware serial number.

The most reliable way we have that works across many hardware platforms is to check the eth0 MAC address.

Returns a numeric serial number.

get_machine_id()[source]

Return unique machine identifier.

This is software-based but fairly standardized from the /etc/machine-id file. We can potentially rely on this for uniquely identifying a node.

handleMissingWiFi(hostConfig)[source]

Take appropriate action in response to missing WiFi devices.

Depending on the host configuration, we may either emit a warning or reboot the system.

isVirtual(ifname)[source]

Test if an interface is a virtual one.

FIXME: This just tests for the presence of certain strings in the interface name, so it is not very robust.

isWAN(ifname)[source]

Test if an interface is a WAN interface.

isWireless(ifname)[source]

Test if an interface is a wireless device.

listSystemDevices()[source]

Detect devices on the system.

The result is a single list of dictionaries, each containing information about a network device.

listWiFiDevices()[source]
readHostconfigVlan(vlanInterfaces, builder)[source]
readHostconfigWifi(wifi, networkDevices, builder)[source]
readHostconfigWifiInterfaces(wifiInterfaces, networkDevices, builder)[source]
readSysFile(path)[source]
resetWirelessDevice(phy, primary_interface)[source]

Reset a wireless device’s interfaces to clean state.

This will rename, delete, or add an interface as necessary to make sure only the primary interface exists, e.g. “wlan0” for a wireless device, e.g. phy0.

resolveWirelessDevRef(name, networkDevices)[source]

Resolve a WiFi device reference (wlan0, phy0, 00:11:22:33:44:55, etc.) to the name of the device section as used by pdconf (wifiXXXXXXXXXXXX).

Unambiguous naming is preferred going forward (either wifiXX or the MAC address), but to maintain backward compatibility, we attempt to resolve either wlanX or phyX to the MAC address of the device that currently uses that name.

select_brlan_address(hostConfig)[source]

Select IP address and netmask to use for LAN bridge.

Behavior depends on the proto field, which can either be ‘auto’ or ‘static’. When proto is set to ‘auto’, we check the WAN interface address and choose either 10.0.0.0 or 192.168.0.1 to avoid conflict. Otherwise, when proto is set to ‘static’, we use the specified address.

setConfig(chuteName, sections, filepath)[source]
setSystemDevices(update)[source]

Initialize system configuration files.

This section should only be run for host configuration updates.

Creates basic sections that all chutes require such as the “wan” interface.

paradrop.core.config.dhcp module

getVirtDHCPSettings(update)[source]

Looks at the runtime rules the developer defined to see if they want a dhcp server. If so it generates the data and stores it into the chute cache key:virtDHCPSettings.

revert_dhcp_settings(update)[source]
setVirtDHCPSettings(update)[source]

Takes a list of tuples (config, opts) and saves it to the dhcp config file.

paradrop.core.config.dockerconfig module

dockerconfig module:
This module contains all of the knowledge of how to take internal pdfcd representation of configurations of chutes and translate them into specifically what docker needs to function properly, whether that be in the form of dockerfiles or the HostConfig JSON object known at init time of the chute.
abortCreateVolumeDirs(update)[source]
createVolumeDirs(update)[source]

Create directories required by the chute.

generateToken(bits=128)[source]
getVirtPreamble(update)[source]

Prepare various settings for Docker containers.

paradrop.core.config.firewall module

findMatchingInterface(iface_name, interfaces)[source]

Search an interface list for one matching a given name.

iface_name can contain shell-style wildcards (* and ?).

getDeveloperFirewallRules(update)[source]

Generate other firewall rules requested by the developer such as redirects. The object returned is a list of tuples (config, options).

getOSFirewallRules(update)[source]

There is a set of default things that must exist just for the chute to function at all, generate those here.

Stored in key: osFirewallRules

revert_os_firewall_rules(update)[source]
setOSFirewallRules(update)[source]

Takes a list of tuples (config, opts) and saves it to the firewall config file.

paradrop.core.config.haproxy module

This module is responsible for configuration haproxy.

generateConfigSections()[source]
reconfigureProxy(update)[source]

Reconfigure haproxy with forwarding and redirect rules.

writeConfigFile(output)[source]

paradrop.core.config.hostconfig module

The host configuration controls system settings of the host OS.

This module operates as follows:

1. The first time, we try to detect all devices and auto-generate a reasonable configuration, which we store to a persistent file.

2. (TODO) We present the configuration to the owner sometime around provisioning or first chute creation and allow him to change settings.

3. (TODO) We have some kind of update operation that can manipulate settings.

generateHostConfig(devices)[source]

Scan for devices on the machine and generate a working configuration.

getHostConfig(update)[source]

Load host configuration.

Read device information from networkDevices. Store host configuration in hostConfig.

load(path=None)[source]

Load host configuration.

Tries to load host configuration from persistent file. If that does not work, it will try to automatically generate a working configuration.

Returns a host config object on success or None on failure.

prepareHostConfig(devices=None, hostConfigPath=None, write=True)[source]

Load an existing host configuration or generate one.

Tries to load host configuration from persistent file. If that does not work, it will try to automatically generate a working configuration.

write: if True and host config was automatically generated, then write the new host config to a file.

revertHostConfig(update)[source]

Restore host configuration from before update.

Uses oldHostConfig cache entry.

save(config, path=None)[source]

Save host configuration.

May raise exception if unable to write the configuration file.

setHostConfig(update)[source]

Write host configuration to persistent storage.

Read host configuration from hostConfig.

paradrop.core.config.network module

abortNetworkConfig(update)[source]

Release resources claimed by chute network configuration.

chooseExternalIntf(update, iface)[source]
chooseSubnet(update, cfg, iface)[source]
fulfillDeviceRequest(update, cfg, devices)[source]

Find a physical device that matches the requested device type.

Raises an exception if one cannot be found.

getExtraOptions(cfg)[source]

Get dictionary of extra wifi-iface options that we are not interpreting but just passing on to pdconf.

getInterfaceAddress(update, name, cfg, iface)[source]

Dynamically select IP address for the chute interface.

This function will use a subnet from the chute subnet pool and assign IP addresses to the external (in host) and internal (in chute) interfaces.

The addresses are stored in the iface object.

getL3BridgeConfig(update)[source]

Creates configuration sections for layer 3 bridging.

getNetworkConfig(update)[source]

For the Chute provided, return the dict object of a 100% filled out configuration set of network configuration. This would include determining what the IP addresses, interfaces names, etc…

Store configuration in networkInterfaces cache entry.

getNetworkConfigLan(update, name, cfg, iface)[source]
getNetworkConfigVlan(update, name, cfg, iface)[source]
getNetworkConfigWifi(update, name, cfg, iface)[source]
getOSNetworkConfig(update)[source]

Takes the network interface obj created by NetworkManager.getNetworkConfiguration and returns a properly formatted object to be passed to the UCIConfig class. The object returned is a list of tuples (config, options).

getWifiKeySettings(cfg, iface)[source]

Read encryption settings from cfg and transfer them to iface.

get_current_phy_conf(update, device_id)[source]

Lookup current configuration for a network device.

This includes information such as the Wi-Fi channel.

Returns a dictionary, which may be empty if no configuration was found.

reclaimNetworkResources(chute)[source]

Reclaim network resources for a previously running chute.

This function only applies to the special case in which pd starts up and loads a list of chutes that were running. This function marks their IP addresses and interface names as taken so that new chutes will not use the same values.

revert_l3_bridge_config(update)[source]
revert_os_network_config(update)[source]
satisfies_requirements(obj, requirements)[source]

Checks that an object satifies given requirements.

Every key-value pair in the requirements object must be present in the target object for it to be considered satisfied.

Returns True/False.

select_chute_subnet_pool(host_config)[source]

Select IP subnet to use as pool for chutes.

Behavior depends on whether a static subnet is configured or auto configuration is requested. If the chuteSubnetPool option is set to ‘auto’, then we check the WAN interface address and choose either 10.128.0.0/9 or 192.168.128.0/17 to avoid conflict. Otherwise, we used the specified subnet.

setL3BridgeConfig(update)[source]

Apply configuration for layer 3 bridging.

setOSNetworkConfig(update)[source]

Takes a list of tuples (config, opts) and saves it to the network config file.

split_interface_type(itype)[source]

paradrop.core.config.osconfig module

osconfig module:
This module is in charge of changing configuration files for pdfcd on the host OS. This relates to things like network, dhcp, wifi, firewall changes. Pdfcd should be able to make simple abstracted calls into this module so that if we need to change what type of OS config we need to support only this module would change.
revertConfig(update, theType)[source]

Tell the UCI module to revert changes to the old state of the chute.

paradrop.core.config.power module

reboot(update)[source]

Reboot the node.

shutdown(update)[source]

Power down the node.

paradrop.core.config.reservations module

Module for checking resource reservations by chutes.

One idea motivating this design is to reduce the amount of state in memory for resource reservations. We have the chute list, which contains information about what devices the chute is using. If we also maintain a separate list of devices used by chutes, we need to keep them synchronized. This becomes messy when a chute fails to install or uninstall correctly. The getDeviceReservations function iterates over the chute list and returns an up-to-date view of device usage. This can be called as needed.

class DeviceReservations[source]

Bases: object

add(chute, dtype, mode=None)[source]
count(dtype=None, mode=None)[source]

Return the number of reservations matching the given criteria.

None is used as a wildcard, so if no arguments are passed, the count returned is the total number of reservations.

class InterfaceReservationSet[source]

Bases: object

add(interface)[source]
class SubnetReservationSet[source]

Bases: object

add(subnet)[source]
getDeviceReservations(exclude=None)[source]

Produce a dictionary mapping device names to DeviceReservations objects that describe the current usage of the device.

The returned type is a defaultdict, so there is no need to check if a key exists before accessing it.

exclude: name of chute whose device reservations should be excluded

getInterfaceReservations(exclude=None)[source]

Get current set of interface reservations.

Returns an instance of InterfaceReservationSet.

exclude: name of chute whose interfaces should be excluded

getReservations(update)[source]

Get device and resource reservations claimed by other users.

getSubnetReservations(exclude=None)[source]

Get current set of subnet reservations.

Returns an instance of SubnetReservationSet.

exclude: name of chute whose reservations should be excluded

paradrop.core.config.resource module

computeResourceAllocation(chutes)[source]
getResourceAllocation(update)[source]

Allocate compute resources for chutes.

Sets cache variables “newResourceAllocation” and “oldResourceAllocation”.

paradrop.core.config.services module

Configure optional additional services such as telemetry.

configure_telemetry(update)[source]

paradrop.core.config.snap module

updateSnap(update)[source]

paradrop.core.config.state module

removeAllChutes(update)[source]
revertChute(update)[source]
saveChute(update)[source]

Save information about the chute to the filesystem.

paradrop.core.config.uciutils module

restoreConfigFile(chute, configname)[source]

Restore a system config file from backup.

This can only be used during a chute update operation to revert changes that were made during that update operation.

configname: name of configuration file (“network”, “wireless”, etc.)

setConfig(update, cacheKeys, filepath)[source]

Helper function used to modify config file of each various setting in /etc/config/ Returns:

True: if it modified a file False: if it did NOT cause any modifications

Raises exception if an error occurs.

paradrop.core.config.wifi module

getOSWirelessConfig(update)[source]

Read settings from networkInterfaces for wireless interfaces. Store wireless configuration settings in osWirelessConfig.

revert_os_wireless_config(update)[source]
setOSWirelessConfig(update)[source]

Write settings from osWirelessConfig out to UCI files.

paradrop.core.config.zerotier module

configure(update)[source]
getAddress()[source]

Return the zerotier address for this device or None if unavailable.

get_auth_token()[source]

Return the zerotier auth token for accessing its API or None if unavailable.

get_networks(ignore_error=False)[source]

Get list of active ZeroTier networks.

manage_network(nwid, action='join')[source]

Join or leave a ZeroTier network.

nwid: ZeroTier network ID, e.g. “e5cd7a9e1c8a5e83” action: either “join” or “leave”

wait_for_zerotier(max_delay=120)[source]

Wait for ZeroTier to start up and create the authtoken file.

Module contents