ethtool -T显示ptp过滤器信息源码分析

ptp过滤器

新设备使用ethtool -T显示ptp过滤器信息:

linux_cx7110:~# ethtool -T eth0
Time stamping parameters for eth0:
Capabilities:hardware-transmit     (SOF_TIMESTAMPING_TX_HARDWARE)software-transmit     (SOF_TIMESTAMPING_TX_SOFTWARE)hardware-receive      (SOF_TIMESTAMPING_RX_HARDWARE)software-receive      (SOF_TIMESTAMPING_RX_SOFTWARE)software-system-clock (SOF_TIMESTAMPING_SOFTWARE)hardware-raw-clock    (SOF_TIMESTAMPING_RAW_HARDWARE)
PTP Hardware Clock: 0
Hardware Transmit Timestamp Modes:off                   (HWTSTAMP_TX_OFF)on                    (HWTSTAMP_TX_ON)
Hardware Receive Filter Modes:none                  (HWTSTAMP_FILTER_NONE)all                   (HWTSTAMP_FILTER_ALL)ptpv1-l4-event        (HWTSTAMP_FILTER_PTP_V1_L4_EVENT)ptpv1-l4-sync         (HWTSTAMP_FILTER_PTP_V1_L4_SYNC)ptpv1-l4-delay-req    (HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ)ptpv2-l4-event        (HWTSTAMP_FILTER_PTP_V2_L4_EVENT)ptpv2-l4-sync         (HWTSTAMP_FILTER_PTP_V2_L4_SYNC)ptpv2-l4-delay-req    (HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ)ptpv2-event           (HWTSTAMP_FILTER_PTP_V2_EVENT)ptpv2-sync            (HWTSTAMP_FILTER_PTP_V2_SYNC)ptpv2-delay-req       (HWTSTAMP_FILTER_PTP_V2_DELAY_REQ)

原来设备没有ptp过滤器信息: 

root@imx6qsabresd_genvict:~# ethtool -T eth0
Time stamping parameters for eth0:
Capabilities:hardware-transmit     (SOF_TIMESTAMPING_TX_HARDWARE)software-transmit     (SOF_TIMESTAMPING_TX_SOFTWARE)hardware-receive      (SOF_TIMESTAMPING_RX_HARDWARE)software-receive      (SOF_TIMESTAMPING_RX_SOFTWARE)software-system-clock (SOF_TIMESTAMPING_SOFTWARE)hardware-raw-clock    (SOF_TIMESTAMPING_RAW_HARDWARE)
PTP Hardware Clock: 0
Hardware Transmit Timestamp Modes:off                   (HWTSTAMP_TX_OFF)on                    (HWTSTAMP_TX_ON)
Hardware Receive Filter Modes:none                  (HWTSTAMP_FILTER_NONE)all                   (HWTSTAMP_FILTER_ALL)
linux_cx7101:~# ethtool -T eth0
Time stamping parameters for eth0:
Capabilities:software-receive      (SOF_TIMESTAMPING_RX_SOFTWARE)software-system-clock (SOF_TIMESTAMPING_SOFTWARE)
PTP Hardware Clock: none
Hardware Transmit Timestamp Modes: none
Hardware Receive Filter Modes: none

代码流程

ethtool-4.15,最后系统调用:ioctl(ctx->fd, SIOCETHTOOL, &ctx->ifr);

{ "-T|--show-time-stamping", 1, do_tsinfo,
do_tsinfo#define ETHTOOL_GET_TS_INFO	0x00000041 /* Get time stamping and PHC info */fprintf(stdout, "Time stamping parameters for %s:\n", ctx->devname);info.cmd = ETHTOOL_GET_TS_INFO;if (send_ioctl(ctx, &info)) {perror("Cannot get device time stamping settings");return -1;}dump_tsinfo(&info);#define SIOCETHTOOL     0x8946
int send_ioctl(struct cmd_context *ctx, void *cmd)
{ctx->ifr.ifr_data = cmd;return ioctl(ctx->fd, SIOCETHTOOL, &ctx->ifr);
}static char *rx_filter_labels[N_RX_FILTERS] = {"none                  (HWTSTAMP_FILTER_NONE)","all                   (HWTSTAMP_FILTER_ALL)","some                  (HWTSTAMP_FILTER_SOME)","ptpv1-l4-event        (HWTSTAMP_FILTER_PTP_V1_L4_EVENT)","ptpv1-l4-sync         (HWTSTAMP_FILTER_PTP_V1_L4_SYNC)","ptpv1-l4-delay-req    (HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ)","ptpv2-l4-event        (HWTSTAMP_FILTER_PTP_V2_L4_EVENT)","ptpv2-l4-sync         (HWTSTAMP_FILTER_PTP_V2_L4_SYNC)","ptpv2-l4-delay-req    (HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ)","ptpv2-l2-event        (HWTSTAMP_FILTER_PTP_V2_L2_EVENT)","ptpv2-l2-sync         (HWTSTAMP_FILTER_PTP_V2_L2_SYNC)","ptpv2-l2-delay-req    (HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ)","ptpv2-event           (HWTSTAMP_FILTER_PTP_V2_EVENT)","ptpv2-sync            (HWTSTAMP_FILTER_PTP_V2_SYNC)","ptpv2-delay-req       (HWTSTAMP_FILTER_PTP_V2_DELAY_REQ)","ntp-all               (HWTSTAMP_FILTER_NTP_ALL)",
};dump_tsinfofprintf(stdout, "Hardware Receive Filter Modes:");if (!info->rx_filters)fprintf(stdout, " none\n");elsefprintf(stdout, "\n");for (i = 0; i < N_RX_FILTERS; i++) {if (info->rx_filters & (1 << i))fprintf(stdout, "\t%s\n", rx_filter_labels[i]);}

网络驱动,调用网络通用层代码框架,最后调用设备驱动:get_ts_info

net/core/dev_ioctl.c +420
dev_ioctl(struct net *net, unsigned int cmd, struct ifreq *ifr, bool *need_copyout)case SIOCETHTOOL:dev_load(net, ifr->ifr_name);rtnl_lock();ret = dev_ethtool(net, ifr);rtnl_unlock();if (colon)*colon = ':';return ret;dev_ethtool(struct net *net, struct ifreq *ifr)struct net_device *dev = __dev_get_by_name(net, ifr->ifr_name);void __user *useraddr = ifr->ifr_data;【ETHTOOL_GET_TS_INFO】case ETHTOOL_GET_TS_INFO:rc = ethtool_get_ts_info(dev, useraddr);break;static int ethtool_get_ts_info(struct net_device *dev, void __user *useraddr)
{int err = 0;struct ethtool_ts_info info;const struct ethtool_ops *ops = dev->ethtool_ops;struct phy_device *phydev = dev->phydev;memset(&info, 0, sizeof(info));info.cmd = ETHTOOL_GET_TS_INFO;if (phydev && phydev->drv && phydev->drv->ts_info) {err = phydev->drv->ts_info(phydev, &info);} else if (ops->get_ts_info) {err = ops->get_ts_info(dev, &info);} else {info.so_timestamping =SOF_TIMESTAMPING_RX_SOFTWARE |SOF_TIMESTAMPING_SOFTWARE;info.phc_index = -1;}if (err)return err;if (copy_to_user(useraddr, &info, sizeof(info)))err = -EFAULT;return err;
}

设备驱动,设备驱动如果支持time_stamp,就直接返回全部ptp过滤器信息,没有读取寄存器信息。

drivers/net/ethernet/stmicro/stmmac/stmmac_ethtool.c
static const struct ethtool_ops stmmac_ethtool_ops = {.get_ts_info = stmmac_get_ts_info,static int stmmac_get_ts_info(struct net_device *dev,struct ethtool_ts_info *info)
{   struct stmmac_priv *priv = netdev_priv(dev);if ((priv->dma_cap.time_stamp || priv->dma_cap.atime_stamp)) {info->so_timestamping = SOF_TIMESTAMPING_TX_SOFTWARE |SOF_TIMESTAMPING_TX_HARDWARE |SOF_TIMESTAMPING_RX_SOFTWARE |SOF_TIMESTAMPING_RX_HARDWARE |SOF_TIMESTAMPING_SOFTWARE |SOF_TIMESTAMPING_RAW_HARDWARE;if (priv->ptp_clock)info->phc_index = ptp_clock_index(priv->ptp_clock);info->tx_types = (1 << HWTSTAMP_TX_OFF) | (1 << HWTSTAMP_TX_ON);info->rx_filters = ((1 << HWTSTAMP_FILTER_NONE) |(1 << HWTSTAMP_FILTER_PTP_V1_L4_EVENT) |【ethtool -T eth0执行这里获取信息】(1 << HWTSTAMP_FILTER_PTP_V1_L4_SYNC) |(1 << HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ) |(1 << HWTSTAMP_FILTER_PTP_V2_L4_EVENT) |(1 << HWTSTAMP_FILTER_PTP_V2_L4_SYNC) |(1 << HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ) |(1 << HWTSTAMP_FILTER_PTP_V2_EVENT) |(1 << HWTSTAMP_FILTER_PTP_V2_SYNC) |(1 << HWTSTAMP_FILTER_PTP_V2_DELAY_REQ) |(1 << HWTSTAMP_FILTER_ALL));return 0;} elsereturn ethtool_op_get_ts_info(dev, info);
}

设备驱动支持设置ptp过滤器,但ethtool工具暂不支持:

static int stmmac_hwtstamp_ioctl(struct net_device *dev, struct ifreq *ifr)if (priv->adv_ts) {switch (config.rx_filter) {case HWTSTAMP_FILTER_NONE:/* time stamp no incoming packet at all */config.rx_filter = HWTSTAMP_FILTER_NONE;break;case HWTSTAMP_FILTER_PTP_V1_L4_EVENT:【没有代码设置属性】/* PTP v1, UDP, any kind of event packet */config.rx_filter = HWTSTAMP_FILTER_PTP_V1_L4_EVENT;/* take time stamp for all event messages */if (xmac)snap_type_sel = PTP_GMAC4_TCR_SNAPTYPSEL_1;elsesnap_type_sel = PTP_TCR_SNAPTYPSEL_1;ptp_over_ipv4_udp = PTP_TCR_TSIPV4ENA;ptp_over_ipv6_udp = PTP_TCR_TSIPV6ENA;break;static int stmmac_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)case SIOCSHWTSTAMP:ret = stmmac_hwtstamp_ioctl(dev, rq);static const struct net_device_ops stmmac_netdev_ops = {.ndo_do_ioctl = stmmac_ioctl,net/core/dev_ioctl.c
int dev_ioctl(struct net *net, unsigned int cmd, struct ifreq *ifr, bool *need_copyout)case SIOCSIFNAME:dev_load(net, ifr->ifr_name);if (!ns_capable(net->user_ns, CAP_NET_ADMIN))return -EPERM;rtnl_lock();ret = dev_ifsioc(net, ifr, cmd);dev_ifsioccmd == SIOCSHWTSTAMP ||cmd == SIOCGHWTSTAMP ||cmd == SIOCWANDEV) {err = -EOPNOTSUPP;if (ops->ndo_do_ioctl) {if (netif_device_present(dev))err = ops->ndo_do_ioctl(dev, ifr, cmd);

总结

目前看ptp过滤器没有实际用到(暂不知如何使用),ptpd2工具发送的udp组播包也是能全部收到的。设备收到192.168.8.202主模式发送的udp包:

linux_genvict:~# tcpdump -i eth0
[10124.286185]  {3}[20512:tcpdump]stmmac_get_ts_info,811,
[10124.288759]  {3}[20512:tcpdump]stmmac_get_ts_info,826,
[10124.295198]  {3}[20512:tcpdump]device eth0 entered promiscuous mode
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on eth0, link-type EN10MB (Ethernet), capture size 262144 bytes
14:21:02.767206 IP 192.168.8.202.319 > 224.0.1.129.319: UDP, length 44
14:21:02.767279 IP 192.168.8.202.320 > 224.0.1.129.320: UDP, length 44
14:21:03.767224 IP 192.168.8.202.320 > 224.0.1.129.320: UDP, length 64
14:21:03.767297 IP 192.168.8.202.319 > 224.0.1.129.319: UDP, length 44
14:21:03.767323 IP 192.168.8.202.320 > 224.0.1.129.320: UDP, length 44
14:21:04.767240 IP 192.168.8.202.319 > 224.0.1.129.319: UDP, length 44
14:21:04.767313 IP 192.168.8.202.320 > 224.0.1.129.320: UDP, length 44
14:21:05.767137 IP 192.168.8.202.320 > 224.0.1.129.320: UDP, length 64
14:21:05.767221 IP 192.168.8.202.319 > 224.0.1.129.319: UDP, length 44
14:21:05.767251 IP 192.168.8.202.320 > 224.0.1.129.320: UDP, length 44
14:21:06.767151 IP 192.168.8.202.319 > 224.0.1.129.319: UDP, length 44
14:21:06.767239 IP 192.168.8.202.320 > 224.0.1.129.320: UDP, length 44
14:21:07.767173 IP 192.168.8.202.320 > 224.0.1.129.320: UDP, length 64
14:21:07.767265 IP 192.168.8.202.319 > 224.0.1.129.319: UDP, length 44
14:21:07.767290 IP 192.168.8.202.320 > 224.0.1.129.320: UDP, length 44

设备收到192.168.8.202从模式发送igmp包,

linux_genvict:~# tcpdump -i eth0
[10209.040651]  {2}[22941:tcpdump]stmmac_get_ts_info,811,
[10209.043257]  {2}[22941:tcpdump]stmmac_get_ts_info,826,
[10209.050286]  {2}[22941:tcpdump]device eth0 entered promiscuous mode
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on eth0, link-type EN10MB (Ethernet), capture size 262144 bytes
14:22:27.397521 IP 192.168.8.202 > 224.0.0.22: igmp v3 report, 2 group record(s)
14:22:36.297523 IP 192.168.8.202 > 224.0.0.22: igmp v3 report, 2 group record(s)
14:22:36.397373 IP 192.168.8.202 > 224.0.0.22: igmp v3 report, 2 group record(s)
14:22:44.767547 IP 192.168.8.202 > 224.0.0.22: igmp v3 report, 2 group record(s)

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/178414.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

中小型公司如何搭建运维平台,rancher、kubersphere、rainbond

很多开发人员应该是了解过运维发布相关的平台或实际操作过应用发布&#xff0c;但又通常不是十分熟悉。在一个初创公司&#xff0c;或者没有成熟的运维发布平台的公司&#xff0c;如果让你来搭建一套发布平台&#xff0c;你应该如何去抉择呢&#xff1f; 这里我简单介绍几种。…

本地开启https,配置nodeJs服务

服务端和客户端各有一对公钥和私钥&#xff0c;使用公钥加密的数据只能用私钥解密&#xff0c;建立https传输之前&#xff0c;客户端和服务端互换公钥。客户端发送数据前使用服务端公钥加密&#xff0c;服务端接收到数据后使用私钥解密&#xff0c;反之亦如此。 1. 公钥私钥的…

【Linux】:信号在内核里的处理

信号的发送和保存 一.内核中的信号处理二.信号集操作函数1.一些信号函数2.sigprocmask3.sigpending4.写代码 三.信号在什么时候处理的四.再谈地址空间 一.内核中的信号处理 1.实际执行信号的处理动作称为信号递达(Delivery )2.信号从产生到递达之间的状态,称为信号未决(Pending…

『 Linux 』僵尸进程与孤儿进程

文章目录 &#x1f680;僵尸进程 - Z(zomble)&#x1f6f0;️ 僵尸状态与死亡状态的区别 &#x1f6f0;️&#x1f6f0;️ 僵尸状态的危害 &#x1f6f0;️ &#x1f680;孤儿进程&#x1f6f0;️ 为什么托孤 &#x1f6f0;️ &#x1f680;僵尸进程 - Z(zomble) 一个进程的创…

米贸搜| Youtube运营:免费涨粉的16个技巧

1、要求观众订阅你的频道 要求用户订阅你的频道无非是再简单不过的方法了&#xff0c;有时你需要做的只是一个及时的提醒而已。红色的订阅按钮通常很难被忽略&#xff0c;但是你可能还需要提醒用户点击订阅按钮旁边的“铃铛”图标&#xff0c;以打开消息提醒&#xff0c;以便在…

vue找依赖包的网址

https://www.npmjs.com/ 浅收藏一下

心大数据结构题型

选择题 2021 数据处理的单位&#xff1a;数据元素 矩阵压缩存储 2022 ①单链表头插法选择 ②矩阵压缩存储&#xff0c;行优先 ③删除链表节点的时间复杂度 ④稀疏矩阵存储 ⑤平衡二叉树时间复杂度 ⑥栈和队列的出队&#xff0c;问栈的大小至少多少 ⑦拓扑排序 ⑧参考书 360…

30.0/集合/ArrayList/LinkedList

目录 30.1什么是集合? 30.1.2为什么使用集合 30.1.3自己创建一个集合类 30.1.3 集合框架有哪些? 30.1.2使用ArrayList集合 30.2增加元素 30.3查询的方法 30.4删除 30.5 修改 30.6泛型 30.1什么是集合? 我们之前讲过数组&#xff0c;数组中它也可以存放多个元素。集合…

关于torch.backends.cudnn.benchmark = True

cuDNN 是英伟达专门为深度神经网络所开发出来的 GPU 加速库&#xff0c;针对卷积、池化等等常见操作做了非常多的底层优化&#xff0c;比一般的 GPU 程序要快很多。大多数主流深度学习框架都支持 cuDNN&#xff0c;PyTorch 自然也不例外。在使用 GPU 的时候&#xff0c;PyTorch…

Cenos7系统通过链接一键安装LAMP项目环境(linux,apache,mysql,php)

前言&#xff1a;嫌装环境麻烦&#xff0c;以下介绍自动安装环境的方法 一.环境配置 根据自己需要选择 操作系统&#xff1a;CenOS 7.x以上Web服务器&#xff1a;Apache 2.4数据库&#xff1a;MySQL 5.7开发框架&#xff1a;ThinkPHP 5.0&#xff08;PHP5.0以上&#xff09;…

CountDownLatch和CyclicBarrier源码详解

其他系列文章导航 Java基础合集 设计模式合集 多线程合集 分布式合集 ES合集 文章目录 其他系列文章导航 文章目录 前言 一、CountDownLatch和CyclicBarrier 二、CountDownLatch源码分析 三、CyclicBarrier源码分析 四、总结 前言 我现在有个场景:现在我有50个任务&…

【Web】NewStarCtf Week2 个人复现

目录 ①游戏高手 ②include 0。0 ③ez_sql ④Unserialize&#xff1f; ⑤Upload again! ⑥ R!!C!!E!! ①游戏高手 经典前端js小游戏 检索与分数相关的变量 控制台直接修改分数拿到flag ②include 0。0 禁了base64和rot13 尝试过包含/var/log/apache/access.log,ph…

Git 入门指南

什么是 Git&#xff1f; Git 的目前最流行的分布式版本控制软件&#xff0c;可以帮助我们高效敏捷的处理任何项目。 版本管理 要理解 Git 我们首先要理解版本管理。 版本管理就是开发过程中用于管理对文件、目录或者工程等内容的修改历史&#xff0c;可以让我们方便的查看历史…

java学习part20内部类

116-面向对象(高级)-类的成员之五&#xff1a;内部类_哔哩哔哩_bilibili 1.内部类

在Anaconda中用命令行安装环境以及安装包

一、下载Anaconda 下载地址 二、创建环境 1. 打开Anaconda命令行 2.创建环境 conda create -n 环境名称 python3.10(需要的python版本号) 3.激活环境 activate 环境名4.下载安装包 pip install 模块名 -i https://pypi.tuna.tsinghua.edu.cn/simple5.下载torch 官网&…

Python语言学习笔记之三(字符编码)

本课程对于有其它语言基础的开发人员可以参考和学习&#xff0c;同时也是记录下来&#xff0c;为个人学习使用&#xff0c;文档中有此不当之处&#xff0c;请谅解。 什么是字符编码 计算机从本质上来说只认识二进制中的0和1&#xff0c;字符编码(Character Encoding) 是一种将…

大数据-之LibrA数据库系统告警处理(ALM-37006 Coordinator进程异常)

告警解释 当出现如下情况时&#xff0c;产生该告警&#xff1a; CN所在机器发生硬件故障&#xff08;断电、硬盘损坏等&#xff09;。CN实例数据目录中的postgresql.conf配置文件不存在或者其中某个配置参数不正确。CN实例线程无法监听IP&#xff0c;或者无法绑定监听端口。C…

【Makefile】和【CMake】的区别

Makefile 和 CMake 的区别 Makefile 和 CMake 都是用于构建项目的工具&#xff0c;但它们有一些区别。 Makefile: 语法&#xff1a; Makefile 使用自己的语法规则&#xff0c;包括规则、目标、依赖等。这是一种特定于 make 工具的语法。 平台依赖&#xff1a; Makefile 是平…

【JavaScript框架】Vue与React中的组件框架概念

组件框架是用于构建应用程序的工具&#xff0c;以便将UI和逻辑划分为单独的可重用组件。目前的组件框架包括React、Vue、Angular、Ember、Svelte等。 Vue和React使用了常见的框架概念&#xff0c;如处理状态、道具、引用、生命周期挂钩、事件等。这两个框架在当今的web开发中被…

案例:某电子产品电商平台借助监控易保障网络正常运行

一、背景介绍 某电子产品电商平台是一家专注于电子产品销售的电商平台&#xff0c;拥有庞大的用户群体和丰富的产品线。随着业务规模的不断扩大&#xff0c;网络设备的数量和复杂性也不断增加&#xff0c;网络故障和性能问题时有发生&#xff0c;给平台的稳定运行带来了很大的挑…