cfengine/core — pull request #459 by lpefferkorn (2013-03-23 16:27:48+00:00)
Title: Add GetInterfaceFlags() to get NIC flags

Here is my first try to get interfaces flag in sys.interface_flags[device]

Tried with the following bundle:

body common control {
bundlesequence => { "foo" };
inputs => { "cfengine_stdlib.cf" };
}

bundle agent foo {

vars:
"if" slist => { "@(sys.interfaces)"};

reports:
"interface: $(if) flags: $(sys.interface_flags[$(if)])";
}

Tested on a CentOS 6.4:

# ip link show|grep "^[0-9]"
1: lo: mtu 16436 qdisc noqueue state UNKNOWN
2: eth0: mtu 1500 qdisc pfifo_fast state UP qlen 1000
3: eth1: mtu 1500 qdisc noop state DOWN qlen 1000
4: eth2: mtu 1500 qdisc noop state DOWN qlen 1000
5: eth3: mtu 1500 qdisc noop state DOWN qlen 1000

Adding IPs to get them found by CFEngine:

# ip addr add 10.0.1.1 dev eth1
# ip addr add 10.0.2.1 dev eth2
# ip addr add 10.0.3.1 dev eth3

Changing some flags:

# ip link set eth1 arp off
# ip link set eth2 multicast off
# ip link set eth3 promisc on
# ip link show|grep "^[0-9]"
1: lo: mtu 16436 qdisc noqueue state UNKNOWN
2: eth0: mtu 1500 qdisc pfifo_fast state UP qlen 1000
3: eth1: mtu 1500 qdisc noop state DOWN qlen 1000
4: eth2: mtu 1500 qdisc noop state DOWN qlen 1000
5: eth3: mtu 1500 qdisc noop state DOWN qlen 1000

Running the bundle:

# ./cf-agent/cf-agent -KIf ~/.cfagent/inputs/test.cf
Running full policy integrity checks
R: interface: eth0 flags: up_broadcast_running_multicast
R: interface: eth1 flags: broadcast_noarp_multicast
R: interface: eth2 flags: broadcast
R: interface: eth3 flags: broadcast_promisc_multicast

Feedback is welcome :) (can't test on FreeBSD right now, because of a bug I've just found while testing this feature)