├── 51-ec2-hvm-devices.rules ├── 52-ec2-vcpu.rules ├── 53-ec2-network-interfaces.rules ├── 75-persistent-net-generator.rules ├── README.md ├── acpiphp.modules ├── ec2-ifup@.service ├── ec2-metadata ├── ec2-utils.spec ├── ec2dhcp.sh ├── ec2ifdown ├── ec2ifscan ├── ec2ifscan.8 ├── ec2ifup ├── ec2ifup.8 ├── ec2net-functions ├── ec2net.hotplug ├── ec2udev ├── elastic-network-interfaces.conf ├── elastic-network-interfaces.service ├── ixgbevf.conf └── sources /51-ec2-hvm-devices.rules: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2006-2012 Amazon.com, Inc. or its affiliates. 2 | # All Rights Reserved. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"). 5 | # You may not use this file except in compliance with the License. 6 | # A copy of the License is located at 7 | # 8 | # http://aws.amazon.com/apache2.0/ 9 | # 10 | # or in the "license" file accompanying this file. This file is 11 | # distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS 12 | # OF ANY KIND, either express or implied. See the License for the 13 | # specific language governing permissions and limitations under the 14 | # License. 15 | 16 | KERNEL=="xvd*", PROGRAM="/sbin/ec2udev %k", SYMLINK+="%c" 17 | -------------------------------------------------------------------------------- /52-ec2-vcpu.rules: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2012 Amazon.com, Inc. or its affiliates. 2 | # All Rights Reserved. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"). 5 | # You may not use this file except in compliance with the License. 6 | # A copy of the License is located at 7 | # 8 | # http://aws.amazon.com/apache2.0/ 9 | # 10 | # or in the "license" file accompanying this file. This file is 11 | # distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS 12 | # OF ANY KIND, either express or implied. See the License for the 13 | # specific language governing permissions and limitations under the 14 | # License. 15 | 16 | SUBSYSTEM=="cpu",ACTION=="add",RUN+="/bin/sh -c '[ ! -e /sys$devpath/online ] || echo 1 > /sys$devpath/online'" 17 | -------------------------------------------------------------------------------- /53-ec2-network-interfaces.rules: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2012 Amazon.com, Inc. or its affiliates. 2 | # All Rights Reserved. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"). 5 | # You may not use this file except in compliance with the License. 6 | # A copy of the License is located at 7 | # 8 | # http://aws.amazon.com/apache2.0/ 9 | # 10 | # or in the "license" file accompanying this file. This file is 11 | # distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS 12 | # OF ANY KIND, either express or implied. See the License for the 13 | # specific language governing permissions and limitations under the 14 | # License. 15 | 16 | ACTION=="add", SUBSYSTEM=="net", KERNEL=="eth*", IMPORT{program}="/bin/sleep 1" 17 | 18 | # ec2net.hotplug writes interface config for new interfaces, and adds or 19 | # removes source routes. It exits if network.service has not yet come up. 20 | SUBSYSTEM=="net", RUN+="/etc/sysconfig/network-scripts/ec2net.hotplug" 21 | 22 | # During bootup with an unconfigured ENI, the udev add event is fired more than 23 | # once (the usual boot event, and another created later by ec2ifscan, which is 24 | # run by elastic-network-interfaces.service). The following rule has to use 25 | # 'systemctl start' rather than ENV{SYSTEMD_WANTS} because systemd doesn't 26 | # keep trying to start the service in the WANTS case. 27 | ACTION=="add", SUBSYSTEM=="net", KERNEL=="eth*", \ 28 | RUN+="/usr/bin/systemctl start ec2-ifup@$env{INTERFACE}" 29 | 30 | # A remove event may be for an interface which was started by network.service 31 | # (if config existed at boot) or by ec2-ifup@.service. In the latter case, 32 | # systemd should kill dhclient when the device disappears. Still have to run 33 | # ifdown to kill dhclient in the former case. 34 | ACTION=="remove", SUBSYSTEM=="net", KERNEL=="eth*", \ 35 | RUN+="/sbin/ifdown $env{INTERFACE}" 36 | -------------------------------------------------------------------------------- /75-persistent-net-generator.rules: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2012 Amazon.com, Inc. or its affiliates. 2 | # All Rights Reserved. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"). 5 | # You may not use this file except in compliance with the License. 6 | # A copy of the License is located at 7 | # 8 | # http://aws.amazon.com/apache2.0/ 9 | # 10 | # or in the "license" file accompanying this file. This file is 11 | # distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS 12 | # OF ANY KIND, either express or implied. See the License for the 13 | # specific language governing permissions and limitations under the 14 | # License. 15 | 16 | # these rules generate rules for persistent network device naming 17 | SUBSYSTEM!="net", GOTO="persistent_net_generator_end" 18 | KERNEL!="eth*", GOTO="persistent_net_generator_end" 19 | ACTION!="add", GOTO="persistent_net_generator_end" 20 | NAME=="?*", GOTO="persistent_net_generator_end" 21 | 22 | # do not create rule for eth0 23 | ENV{INTERFACE}=="eth0", GOTO="persistent_net_generator_end" 24 | 25 | # read MAC address 26 | ENV{MATCHADDR}="$attr{address}" 27 | 28 | # do not use empty address 29 | ENV{MATCHADDR}=="00:00:00:00:00:00", GOTO="persistent_net_generator_end" 30 | 31 | # discard any interface name not generated by our rules 32 | ENV{INTERFACE_NAME}=="?*", ENV{INTERFACE_NAME}="" 33 | 34 | # default comment 35 | ENV{COMMENT}="elastic network interface" 36 | 37 | # write rule 38 | IMPORT{program}="write_net_rules" 39 | 40 | # rename interface if needed 41 | ENV{INTERFACE_NEW}=="?*", NAME="$env{INTERFACE_NEW}" 42 | 43 | LABEL="persistent_net_generator_end" 44 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## ec2-net-utils for Fedora/systemd 2 | 3 | This is a fork of Amazon's ec2-utils with modifications to support Elastic Network Interfaces (ENI) under systemd. 4 | 5 | The spec file produces two RPMs: ec2-utils and ec2-net-utils. The ec2-net-utils RPM contains ENI support. It allows you to attach an ENI to a running instance and have it work as you would expect. Hurray! 6 | 7 | The ec2-utils RPM just contains a shell script to lookup instance metadata. 8 | 9 | ## Install 10 | 11 | Builds are available on [Copr](https://copr.fedoraproject.org/coprs/etuttle/ec2-utils/). Drop the .repo in your repos.d, then `yum install ec2-net-utils` 12 | 13 | * Imporant! Don't forget to enable the `elastic-network-interfaces` systemd unit, or ENI's won't work at boot! 14 | 15 | ## OS Support 16 | 17 | * ✓ Fedora 20 18 | * ? Fedora 21 (should work, as it is using network-scripts according to [the cloud kickstart](https://git.fedorahosted.org/cgit/spin-kickstarts.git/tree/fedora-cloud-base.ks?id=7f202a0e531ea178243c563a721c0c248af87219#n51)) 19 | * ? Fedora 19 not tested with recent changes 20 | * ? CentOS7 I don't think there's an official AMI yet 21 | * ✗ RHEL7 - the AMI uses Network Manager 22 | 23 | ## How does it work 24 | 25 | A udev rule runs `ec2net.hotplug` when a device is added or removed, which is a script that writes interface config, including source route setup. It relies on the primary interface having come up so it can query AWS metadata. 26 | 27 | Another udev rule starts the `ec2-ifup@` service when an interface is added, and a third one runs `/sbin/ifdown` on device removal. The original version from AWS relied on net.hotplug to do this, which has been removed from Fedora. 28 | 29 | Finally, `elastic-network-interfaces.service` is run late in the boot process. It calls `ec2ifscan` which fires another udev add event for any interface which is not configured. This handles the case of booting with an ENI that `ec2net.hotplug` hasn't had a chance to configure yet. 30 | 31 | ## Complications 32 | 33 | * udev add events are fired during boot, during 'attach', and a second time during boot for the unconfigured case. Meanwhile, network-scripts expects to manage any interface with a cfg that exists at boot. So the udev events have to be ignored in the appropriate cases. 34 | * Fedora 20 uses a kernel feature (address lifetime) which removes expired addresses, even if dhclient isn't running. So dhclient must be kept running or the address will be dropped. 35 | * Systemd kills any long-running processes that are spawned by scripts that are run by udev. To be kept alive, dhclient must be started by a service started by udev (hence `ec2-ifup@`). 36 | 37 | ## This is a mess! 38 | 39 | Yeah, but it's not easy to untangle it from network-scripts without porting to NetworkManager, and it's not clear if NetworkManager is even the way forward (with systemd-networkd on the horizon). If Amazon Linux ever switches to systemd, they'll probably come up with a cleaner solution. -------------------------------------------------------------------------------- /acpiphp.modules: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | exec /sbin/modprobe acpiphp >/dev/null 2>&1 3 | -------------------------------------------------------------------------------- /ec2-ifup@.service: -------------------------------------------------------------------------------- 1 | [Unit] 2 | Description=Bring up %i if configured by ec2net.hotplug 3 | 4 | # BindsTo marks this service as stopped when the device disappears, and also 5 | # kills children in the control group such as dhclient (though, the ifdown 6 | # run by udev would take care of that as well). 7 | BindsTo=sys-subsystem-net-devices-%i.device 8 | 9 | # Don't run when network.service is still starting, avoids trying to bring up 10 | # interfaces that network.service is already bringing up. 11 | After=network.service 12 | 13 | # Don't run if network.service has already configured the interface. 14 | ConditionPathExists=!/var/run/dhclient-%i.pid 15 | 16 | # Don't run if elastic-network-interfaces hasn't written the config yet. 17 | # There will be another udev add event after it's configured. 18 | ConditionPathExists=/etc/sysconfig/network-scripts/ifcfg-%i 19 | 20 | [Service] 21 | ExecStart=/sbin/ifup %i 22 | RemainAfterExit=true 23 | -------------------------------------------------------------------------------- /ec2-metadata: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Copyright (C) 2006-2012 Amazon.com, Inc. or its affiliates. 4 | # All Rights Reserved. 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"). 7 | # You may not use this file except in compliance with the License. 8 | # A copy of the License is located at 9 | # 10 | # http://aws.amazon.com/apache2.0/ 11 | # 12 | # or in the "license" file accompanying this file. This file is 13 | # distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS 14 | # OF ANY KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations under the 16 | # License. 17 | 18 | function print_help() 19 | { 20 | echo "ec2-metadata v0.1.2 21 | Use to retrieve EC2 instance metadata from within a running EC2 instance. 22 | e.g. to retrieve instance id: ec2-metadata -i 23 | to retrieve ami id: ec2-metadata -a 24 | to get help: ec2-metadata --help 25 | For more information on Amazon EC2 instance meta-data, refer to the documentation at 26 | http://docs.amazonwebservices.com/AWSEC2/2008-05-05/DeveloperGuide/AESDG-chapter-instancedata.html 27 | 28 | Usage: ec2-metadata