Chinaunix
标题:
请教ip_local_reserved_ports
[打印本页]
作者:
4059056
时间:
2014-05-16 21:22
标题:
请教ip_local_reserved_ports
/proc/sys/net/ipv4/ip_local_reserved_ports文件的作用我就无多说了,我想请教一下,哪些内核进程对此文件进行解析,及相应的内核函数?
作者:
Tinnal
时间:
2014-05-19 22:42
麻烦你移步到内核代码,search!
作者:
4059056
时间:
2014-05-22 08:59
找了很久没找到,能不能给点提示?
回复
2#
Tinnal
作者:
Tinnal
时间:
2014-05-22 19:10
http://lxr.free-electrons.com/so ... pv4.c?v=2.6.36#L303
作者:
Tinnal
时间:
2014-05-22 20:02
回复
3#
4059056
真正控制的变量在这:
http://lxr.free-electrons.com/so ... pv4.c?v=2.6.36#L750
748 for (i = ipv4_table; i->procname; i++) {
749 if (strcmp(i->procname, "ip_local_reserved_ports") == 0) {
750 i->data = sysctl_local_reserved_ports;
751 break;
752 }
753 }
复制代码
使用这个变量的地方:
http://lxr.free-electrons.com/so ... /ip.h?v=2.6.36#L199
199 static inline int inet_is_reserved_local_port(int port)
200 {
201 return test_bit(port, sysctl_local_reserved_ports);
202 }
复制代码
正真生效的地方:
http://lxr.free-electrons.com/so ... ock.c?v=2.6.36#L113
92 int inet_csk_get_port(struct sock *sk, unsigned short snum)
93 {
……
103 if (!snum) {
104 int remaining, rover, low, high;
105
106 again:
107 inet_get_local_port_range(&low, &high);
108 remaining = (high - low) + 1;
109 smallest_rover = rover = net_random() % remaining + low;
110
111 smallest_size = -1;
112 do {
113 if (inet_is_reserved_local_port(rover))
114 goto next_nolock;
……
137 next_nolock:
138 if (++rover > high)
139 rover = low;
140 } while (--remaining > 0);
141
……
213 }
214 EXPORT_SYMBOL_GPL(inet_csk_get_port);
复制代码
这也不难搜索呀。以后自己要多练习。这个实现在内核来于已经很解单了。
作者:
4059056
时间:
2014-05-24 09:28
这些我都看过,看完之后,也没有找到答案,所以我才到CU求助的。还有没有其他的提示?
回复
5#
Tinnal
作者:
Tinnal
时间:
2014-05-24 18:17
回复
6#
4059056
相关的代码在5楼不是给你了吗?你还想知到什么???{:2_166:}
作者:
4059056
时间:
2014-05-25 14:53
这些代码我早就看过,你认为这些代码能解决问题吗?
回复
7#
Tinnal
作者:
4059056
时间:
2014-05-25 15:00
我想知道的不是sysctl_local_reserved_ports的初始化,也不是inet_csk_get_port使用sysctl_local_reserved_ports随机分配端口。而是系统在运行期间实时更新sysctl_local_reserved_ports的过程,
回复
7#
Tinnal
作者:
Tinnal
时间:
2014-05-25 18:51
回复
9#
4059056
那是一个sysctl接口,系统自己不去更新它,他们系统管理员通过sysctl命令去手工设置的更新的。
系统启动时,现有的发行版本也会按sysctl.conf配置文件去配置。
欢迎光临 Chinaunix (http://bbs.chinaunix.net/)
Powered by Discuz! X3.2