1 Star 0 Fork 50

庞庆/systemd_1

forked from src-anolis-os/systemd 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
0493-socket-util-add-generic-socket_pass_pktinfo-helper.patch 1.68 KB
一键复制 编辑 原始数据 按行查看 历史
geliwei 提交于 2021-06-16 16:46 . update to systemd-239-45.el8.src.rpm
From 96681723232e9eb0182279086fef291283004806 Mon Sep 17 00:00:00 2001
From: Lennart Poettering <lennart@poettering.net>
Date: Wed, 27 May 2020 19:27:51 +0200
Subject: [PATCH] socket-util: add generic socket_pass_pktinfo() helper
The helper turns on the protocol specific "packet info" structure cmsg
for three relevant protocols we know.
(cherry picked from commit 35a3eb9bdc95d1e6ba25bc65c78959ea104e45a1)
Related: #1887181
---
src/basic/socket-util.c | 23 +++++++++++++++++++++++
src/basic/socket-util.h | 2 ++
2 files changed, 25 insertions(+)
diff --git a/src/basic/socket-util.c b/src/basic/socket-util.c
index 986bc6e67f..053bcba670 100644
--- a/src/basic/socket-util.c
+++ b/src/basic/socket-util.c
@@ -1246,3 +1246,26 @@ int socket_ioctl_fd(void) {
return fd;
}
+
+int socket_pass_pktinfo(int fd, bool b) {
+ int af;
+ socklen_t sl = sizeof(af);
+
+ if (getsockopt(fd, SOL_SOCKET, SO_DOMAIN, &af, &sl) < 0)
+ return -errno;
+
+ switch (af) {
+
+ case AF_INET:
+ return setsockopt_int(fd, IPPROTO_IP, IP_PKTINFO, b);
+
+ case AF_INET6:
+ return setsockopt_int(fd, IPPROTO_IPV6, IPV6_RECVPKTINFO, b);
+
+ case AF_NETLINK:
+ return setsockopt_int(fd, SOL_NETLINK, NETLINK_PKTINFO, b);
+
+ default:
+ return -EAFNOSUPPORT;
+ }
+}
diff --git a/src/basic/socket-util.h b/src/basic/socket-util.h
index 616f2e0d05..c7c9ad34d6 100644
--- a/src/basic/socket-util.h
+++ b/src/basic/socket-util.h
@@ -190,3 +190,5 @@ static inline int setsockopt_int(int fd, int level, int optname, int value) {
return 0;
}
+
+int socket_pass_pktinfo(int fd, bool b);
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/pang-qing/systemd_1.git
git@gitee.com:pang-qing/systemd_1.git
pang-qing
systemd_1
systemd_1
a8

搜索帮助