在思科的开源软件VPP(Vector Packet Processing)系统中,Mactime插件的主要功能是监视并记录网络接口上的MAC地址活动。这一特性支持基于MAC地址的过滤功能,常用于网络管理,以控制哪些设备可以访问网络资源。以下是该功能的一些常见应用场景及其具体应用方式:
下面以时间控制中允许时间段通过来介绍mactime相关的配置。运行vpp进程,我们创建一个tap接口用来内核和vpp之间的通信,并分别配置ip地址。
root@learning-vpp:~/workspace/vpp# ifconfig tap0
tap0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.1.2 netmask 255.255.255.0 broadcast 192.168.1.255
inet6 fe80::fe:9dff:fe6b:d47f prefixlen 64 scopeid 0x20<link>
ether 02:fe:9d:6b:d4:7f txqueuelen 1000 (Ethernet)
RX packets 150 bytes 14400 (14.4 KB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 1835 bytes 86134 (86.1 KB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
内核接口tap0地址是02:fe:9d:6b:d4:7f,接下来我们配置mactime,我们设置10:10-10:12之间允许mac地址通过的。在内核上长ping vpp中接口ip。
binary-api mactime_add_del_range name pc1 mac 02:fe:9d:6b:d4:7f allow-range Sat - Sat 10:10-10:12
配置完毕之后观察如下:在10:10-10:12之间时,可以ping通192.168.1.1的,当时间10:12:01秒再次查询统计时,已经无法ping通了。
当执行下面命令
binary-api mactime_add_del_range name pc1 mac 02:fe:9d:6b:d4:7f del
删除对mac地址限制之后,有可以ping通了。
下面我们通过设置trace抓取转发流程如下:
01:46:06:935832: virtio-input
virtio: hw_if_index 1 next-index 11 vring 0 len 98
hdr: flags 0x00 gso_type 0x00 hdr_len 0 gso_size 0 csum_start 0 csum_offset 0 num_buffers 1
01:46:06:935842: mactime
MACTIME: src mac 02:fe:9d:6b:d4:7f device mac-02:fe:9d:6b:d4:7f result pass
01:46:06:935850: ethernet-input
IP4: 02:fe:9d:6b:d4:7f -> 02:fe:b5:0f:ac:51
01:46:06:935857: ip4-input
ICMP: 192.168.1.2 -> 192.168.1.1
tos 0x00, ttl 64, length 84, checksum 0x5e50 dscp CS0 ecn NON_ECN
fragment id 0x5905, flags DONT_FRAGMENT
ICMP echo_request checksum 0x789b id 9
01:46:06:935864: ip4-lookup
fib 0 dpo-idx 7 flow hash: 0x00000000
ICMP: 192.168.1.2 -> 192.168.1.1
tos 0x00, ttl 64, length 84, checksum 0x5e50 dscp CS0 ecn NON_ECN
fragment id 0x5905, flags DONT_FRAGMENT
ICMP echo_request checksum 0x789b id 9
01:46:06:935870: ip4-receive
fib:0 adj:7 flow:0x00000000
ICMP: 192.168.1.2 -> 192.168.1.1
tos 0x00, ttl 64, length 84, checksum 0x5e50 dscp CS0 ecn NON_ECN
fragment id 0x5905, flags DONT_FRAGMENT
ICMP echo_request checksum 0x789b id 9
01:46:06:935875: ip4-icmp-input
ICMP: 192.168.1.2 -> 192.168.1.1
tos 0x00, ttl 64, length 84, checksum 0x5e50 dscp CS0 ecn NON_ECN
fragment id 0x5905, flags DONT_FRAGMENT
ICMP echo_request checksum 0x789b id 9
01:46:06:935877: ip4-icmp-echo-request
ICMP: 192.168.1.2 -> 192.168.1.1
tos 0x00, ttl 64, length 84, checksum 0x5e50 dscp CS0 ecn NON_ECN
fragment id 0x5905, flags DONT_FRAGMENT
ICMP echo_request checksum 0x789b id 9
01:46:06:935881: ip4-load-balance
fib 0 dpo-idx 2 flow hash: 0x00000000
ICMP: 192.168.1.1 -> 192.168.1.2
tos 0x00, ttl 64, length 84, checksum 0x1f06 dscp CS0 ecn NON_ECN
fragment id 0x984f, flags DONT_FRAGMENT
ICMP echo_reply checksum 0x809b id 9
01:46:06:935886: ip4-rewrite
tx_sw_if_index 1 dpo-idx 2 : ipv4 via 192.168.1.2 tap0: mtu:9000 next:3 flags:[] 02fe9d6bd47f02feb50fac5
10800 flow hash: 0x00000000
00000000: 02fe9d6bd47f02feb50fac51080045000054984f400040011f06c0a80101c0a8
00000020: 01020000809b000909c02dd6ee66000000008d8b0d00000000001011
01:46:06:935888: tap0-output
tap0 flags 0x02180005
IP4: 02:fe:b5:0f:ac:51 -> 02:fe:9d:6b:d4:7f
ICMP: 192.168.1.1 -> 192.168.1.2
tos 0x00, ttl 64, length 84, checksum 0x1f06 dscp CS0 ecn NON_ECN
fragment id 0x984f, flags DONT_FRAGMENT
ICMP echo_reply checksum 0x809b id 9
01:46:06:935893: mactime-tx
MACTIME: src mac 02:fe:b5:0f:ac:51 device mac-02:fe:9d:6b:d4:7f result pass
01:46:06:935898: tap0-tx
buffer 0xa7af4: current data 0, length 98, buffer-pool 0, ref-count 1, trace handle 0x0
local l2-hdr-offset 0 l3-hdr-offset 14
hdr-sz 0 l2-hdr-offset 0 l3-hdr-offset 14 l4-hdr-offset 0 l4-hdr-sz 0
IP4: 02:fe:b5:0f:ac:51 -> 02:fe:9d:6b:d4:7f
ICMP: 192.168.1.1 -> 192.168.1.2
tos 0x00, ttl 64, length 84, checksum 0x1f06 dscp CS0 ecn NON_ECN
fragment id 0x984f, flags DONT_FRAGMENT
ICMP echo_reply checksum 0x809b id 9
通过上面的转发流程和下面的代码中可以了解到mactime节点挂载点存在2个,rx对应mactime节点是在device-input arc feature上,tx对应mactime-tx是在interface-output节点上。
VNET_FEATURE_INIT (mactime, static) =
{
.arc_name = "device-input",
.node_name = "mactime",
.runs_before = VNET_FEATURES ("ethernet-input"),
};
VNET_FEATURE_INIT (mactime_tx, static) = {
.arc_name = "interface-output",
.node_name = "mactime-tx",
.runs_before = VNET_FEATURES ("interface-output-arc-end"),
};
请注意,虽然MAC地址过滤提供了一定程度的安全性,但它并不是绝对安全的方法,因为MAC地址可以被伪造。因此,最好将MAC地址过滤与其他安全措施(如强密码保护、最新的加密标准等)结合起来使用。
本文分享自 DPDK VPP源码分析 微信公众号,前往查看
如有侵权,请联系 cloudcommunity@tencent.com 删除。
本文参与 腾讯云自媒体同步曝光计划 ,欢迎热爱写作的你一起参与!