Commit Graph

36 Commits

Author SHA1 Message Date
Thomas Lamprecht
28c5d5e681 Network: add helpers to resolve hostnames to IPs
Add addr_to_ip and get_ip_from_hostname helpers to PVE::Network

The first helper, addr_to_ip, is based on Wolfgangs version of this
[0]
I just moved it from PVE::Tools to PVE::Network, as it seems a more
fitting place.
It uses getnameinfo to extract information from the paddr parameter,
which is sockaddr struct
It gets used in the second helper and in a bug fix series from
Wolfgang [1]

The second helper, get_ip_from_hostname, resolves an hostname to an
IP and checks if it isn't one from the for loopback reserved 127/8
subnet. It will be used in get_remote_nodeip from PVE::CLuster and
for a bugfix in pvecm.

[0]: http://pve.proxmox.com/pipermail/pve-devel/2017-April/026099.html
[1]: http://pve.proxmox.com/pipermail/pve-devel/2017-April/026098.html

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
(cherry picked from commit 87aa00de73)
2017-05-04 10:03:27 +02:00
Wolfgang Bumiller
86330049be Network: stop using ifconfig
We shouldn't mix different tool sets on the one hand, and on
the other hand net-tools is an optional package in stretch
and there's no real need for us to depend on it.
2017-02-07 14:54:31 +01:00
Wolfgang Bumiller
e0a862e2c0 fix #1232: cleanup bridges on veth_delete
When a container stops or hotplug changes are applied we
do a veth_delete() which does not cleanup the firewall
bridges or OVS ports. This is problematic at the next
startup. When creating a network device we usually want to
copy the MTU of the bridge we intend to put it on, however,
with OVS still having the old port lying around the
recreated device gets associated with the bridge before we
read its MTU, potentially reducing it to that of the newly
created device.

This cleanup also gets rid of stale fwbr/fwln devices from
stopped containers.
2017-01-20 10:05:10 +01:00
Thomas Lamprecht
beb9820ffb add get_local_ip_from_cidr
The get_local_ip_from_cidr method can be used to determine addresses
configured on interfaces from the callers node which are located
in the subnet. The subnet can be passed in CIDR notation.

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2016-10-28 12:01:38 +02:00
Wolfgang Bumiller
f3ccd9b4b9 Network: add disable_ipv6 and use it
Many interfaces used to get an ipv6 link-local address which
was usually unusable and therefore pointless.

In order to ensure consistency this is called in various
places:
* $bridge_add_interface() and $ovs_bridge_add_port() because
  it's generally a good choice for bridge ports.
* tap_create() and veth_create() because the activate the
  interfaces and we want to avoid the link local address to
  exist temporarily between bringing the interface up and
  adding it to a bridge.
* create_firewall_bridge_*() because firewall bridges aren't
  meant to have addresses either.
* activate_bridge_vlan() - if vlan_filtering is disabled we
  create vlan-bridges and neither them nor their physical
  ports should have link local addresses.
2016-09-29 12:45:23 +02:00
Wolfgang Bumiller
a712bf6e37 Fix #132: hold a lock while setting up vlan bridges
It's possible for two simultaneous VM starts to try to
create vlan bridges on non-vlan-aware bridges
simultaneously, which causes one of them to fail with the
error "can't add bridge ...".
2016-06-21 15:01:30 +02:00
Wolfgang Bumiller
78e912a3b7 vlan fixups: remove existing vlan ids
bridge_add_interface should remove the existing vids from
the interface (which is usually 1, which was previously left
on the interface)
2016-06-21 06:53:35 +02:00
Wolfgang Bumiller
f0d1b04fda move Network::get_active_interfaces to ProcFSTools
This avoids a circular dependency between PVE::INotify and
PVE::Network.

Also renamed to get_active_network_interfaces since the
package name now doesn't hint at this anymore.
2016-06-03 11:22:40 +02:00
Wolfgang Bumiller
19e609fd33 add netmasks starting from /8 to local netmask list 2016-06-03 11:21:57 +02:00
Wolfgang Bumiller
e43faad9ff Consider /31 and /32 valid subnet masks.
Since we already allow this for container IP addresses it is
reasonable to assume the host might be using such a setup as
well. (You can use an additional route to reach the gateway
and then simply have no "LAN".) Some people seem to want
this...
2016-06-03 11:21:42 +02:00
Dominik Csapak
5d662b31b7 show warning when using VLAN 1 on a VLAN aware bridge
Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
2016-05-18 11:23:03 +02:00
Wolfgang Bumiller
899f8c4aa5 support for predictable network interface device names
Based on patch from: Igor Vlasenko <viy@altlinux.org>
2016-05-17 16:14:15 +02:00
Fabian Grünbichler
2d6b3a90db Use run_command instead of system
and explicitly note that those calls are allowed to fail and
are wrapped in eval {} on purpose.
2016-05-03 07:03:10 +02:00
Wolfgang Bumiller
dd44486ecb Fix #908: cleanup OVS ports in tap_unplug
tap_unplug() is only called in hotplugging functions which
perform a tap_plug() afterwards, and and in qemu-server's
bridge-down script.
The OVS port cleanup for non-firewall ports was done only in
tap_plug(), which means that in the case when qemu exits and
the tap device disappears, the OVS port for it stays.

With this patch the cleanup happens in both tap_unplug() and
tap_plug() to avoid problems with upgrades on systems
where there have already been ports leaked.
2016-04-13 06:36:50 +02:00
Wolfgang Bumiller
ab08ec798d net: don't die in get_active_interfaces() and try both address families 2016-03-15 06:45:29 +01:00
Wolfgang Bumiller
c4534006af cleanup: regex match group reference
Don't refer to the regex match group via $1 after running
other code.
2016-03-09 17:58:08 +01:00
Wolfgang Bumiller
1b915170db net: improve ingress tc filter
Instead of doing a dummy "0 == 0" comparison with the u32
filter just use the 'basic' filter.
2016-03-08 15:58:57 +01:00
Wolfgang Bumiller
bce2a5b34c net: tap_plug() needs to apply rate limiting
Any action we take in tap_plug() when using OVS will undo
our rate limiting, which means any hotplug change must
restore the previous rate setting.
Since this means tap_plug() would always be followed by a
tap_rate_limit() call anyway we just include the rate
parameter here and let the caller decide whether the full
tap_plug() is required or the simple tap_rate_limit()
suffices.
2016-03-08 15:50:17 +01:00
Wolfgang Bumiller
ad066ae2de network: tap_rate_limit: fix uninitialized value 2016-03-08 15:50:03 +01:00
Wolfgang Bumiller
f029c1d092 network: get rid of ioctl.ph 2016-02-12 11:17:20 +01:00
Wolfgang Bumiller
12a235d624 Fix #882: active state of interfaces depends on ipv6
read_etc_network_interfaces used the content of
/proc/net/if_inet6 to decide whether an interface's state is
"active", which means an interface is only active when it
has an ipv6 address, thus using net.ipv6.conf.*.disable_ipv6
on an interface will cause it to show as inactive in the web
interface.

We now filter the interfaces found in /proc/dev/net by their
IFF_UP flag read via an SIOCGIFFLAGS ioctl().
2016-02-10 12:20:21 +01:00
Wolfgang Bumiller
846337ad41 network: fix uninitialized value error 2016-01-18 11:01:35 +01:00
Alexandre Derumier
b0b34ffd4e network : add trunks support
Signed-off-by: Alexandre Derumier <aderumier@odiso.com>
2016-01-15 17:25:42 +01:00
Dietmar Maurer
34eb365639 avoid access to undefinded var $tag 2015-11-19 06:23:12 +01:00
Wolfgang Bumiller
bf52d27bb3 network: IP_from_cidr and is_ip_in_cidr helpers 2015-10-16 16:51:01 +02:00
Stefan Priebe
ce1c3cc44a support QinQ / vlan stacking
Signed-off-by: Stefan Priebe <s.priebe@profihost.ag>
2015-09-21 09:30:15 +02:00
Wolfgang Bumiller
b6bff92ee5 Added PVE::Network::tcp_ping to replace Net::Ping
We use Net::Ping twice in pve-storage (once for ISCSIPlugin
and once in GlusterfsPlugin, both with the 'tcp' variant.),
but Net::Ping doesn't support IPv6.
2015-08-28 10:55:17 +02:00
Wolfgang
5d35df41fc fix bug #860: fix the upload from a VM when it is restricted. 2015-08-17 08:32:51 +02:00
Alen Grizonic
32cb7d272f tap device name parse fix
Signed-off-by: Alen Grizonic <a.grizonic@proxmox.com>
2015-08-10 09:05:37 +02:00
Alexandre Derumier
ff0420567b fix tap_plug with vlan for non aware vlan bridges
Signed-off-by: Alexandre Derumier <aderumier@odiso.com>
2015-08-03 16:13:04 +02:00
Wolfgang Bumiller
6fc54cb240 replace /sbin/vconfig with /sbin/ip call 2015-07-29 11:29:47 +02:00
Alexandre Derumier
4d25f4aafe tap_plug : add support for vlan aware linux bridge
Signed-off-by: Alexandre Derumier <aderumier@odiso.com>
2015-07-29 10:48:06 +02:00
Wolfgang Bumiller
61aa94e472 PVE::Network: add some common constants
added ipv4_reverse_mask and ipv4_mask_hash_localnet as they
are used in several places.
2015-07-23 06:27:47 +02:00
Alexandre Derumier
f3f0bc3afd add veth_delete
Signed-off-by: Alexandre Derumier <aderumier@odiso.com>
2015-06-26 11:49:39 +02:00
Alexandre Derumier
35efc4ebcc add veth_create
Signed-off-by: Alexandre Derumier <aderumier@odiso.com>
2015-06-26 11:49:16 +02:00
Dietmar Maurer
b51b16e6f5 rename data to src 2015-02-27 16:57:20 +01:00