- 浏览: 1468207 次
- 性别:
- 来自: 郑州
文章分类
最新评论
-
getelephantbyid:
make 无法通过.....
php-5.3,php-5.4的thttpd2.25b补丁,及编译方法 -
getelephantbyid:
patch -p1 ../php-5.4.7_thttpd-2 ...
php-5.3,php-5.4的thttpd2.25b补丁,及编译方法 -
zander:
zander 写道c 语言是静态类型语言还是动态类型语言阅读理 ...
什么是动态语言和静态语言? -
zander:
c 语言是静态类型语言还是动态类型语言
什么是动态语言和静态语言? -
lunajiayou:
很有道理,赞一个
跟着苍蝇会找到厕所,跟着蜜蜂会找到花朵
转至:http://blogold.chinaunix.net/u/15993/showart_90109.html
rtnetlink就是一组操作rtnetlink消息的宏。
在netlink中,初始化一个netlink_route套接字时,最后一个字段使用NETLINK_ROUTE时就是rtnetlink_socket。
#include <asm/types.h>
#include <linux/netlink.h>
#include <linux/rtnetlink.h>
#include <sys/socket.h>
rtnetlink_socket = socket(PF_NETLINK, int socket_type, NETLINK_ROUTE);
这组宏包括:
int RTA_OK(struct rtattr *rta, int rtabuflen);
void *RTA_DATA(struct rtattr *rta);
unsigned int RTA_PAYLOAD(struct rtattr *rta);
struct rtattr *RTA_NEXT(struct rtattr *rta, unsigned int rtabuflen);
unsigned int RTA_LENGTH(unsigned int length);
unsigned int RTA_SPACE(unsigned int length);
使用这一组宏可以对路由表进行读写和修改。不仅对路由表,还有很多网络参数都可以通过rtnetlink来修改。
路由属性:
一些rtnetlink消息在初始化头后面有附加的属性:
struct rtattr
{
unsigned short rta_len; /* Length of option */
unsigned short rta_type; /* Type of option */
/* Data follows */
};
一些rtnetlink消息在初始化头后面有附加的属性:
struct rtattr
{
unsigned short rta_len; /* Length of option */
unsigned short rta_type; /* Type of option */
/* Data follows */
};
除了标准的netlink消息之外,rtnetlink由这些消息类型组成。
RTM_NEWLINK, RTM_DELLINK, RTM_GETLINK
创建或者删除一个特定的网络接口,或者从一个特定的网络接口上获得信息。这些消息含有一个ifinfomsg类型的结构,紧跟在后面的是一系列的rtattr结构。
struct ifinfomsg
{
unsigned char ifi_family; /* AF_UNSPEC */
unsigned char __ifi_pad; /* unused */
unsigned short ifi_type; /* Device type */
int ifi_index; /* Interface index */
unsigned int ifi_flags; /* Device flags */
unsigned int ifi_change; /* change mask */
}
其中ifi_change是为将来预留的,总是被设为0xFFFFFFFF
rta_type value type description
--------------------------------------------------------------
IFLA_UNSPEC - unspecified.
IFLA_ADDRESS hardware address interface L2 address
IFLA_BROADCAST hardware address L2 broadcast address.
IFLA_IFNAME asciiz string Device name.
IFLA_MTU unsigned int MTU of the device.
IFLA_LINK int Link type.
IFLA_QDISC asciiz string Queueing discipline.
IFLA_STATS struct Interface Statistics.
net_device_stats
RTM_NEWADDR, RTM_DELADDR, RTM_GETADDR
添加,删除或者接收一个和接口相关的IP地址的信息。在linux2.2中,一个网口是可以有多个IP地址信息的。这些消息含有一个ifaddrmsg类型的结构,紧跟在后面的是一系列的rtattr结构。
struct ifaddrmsg
{
unsigned char ifa_family; /* Address type */
unsigned char ifa_prefixlen;/* Prefixlength of the address */
unsigned char ifa_flags; /* Address flags */
unsigned char ifa_scope; /* Address scope */
int ifa_index; /* Interface index */
};
rta_type value type description
-------------------------------------------------------------
IFA_UNSPEC - unspecified.
IFA_ADDRESS raw protocol address interface address
IFA_LOCAL raw protocol address local address
IFA_LABEL asciiz string name of the interface
IFA_BROADCAST raw protocol address broadcast address.
IFA_ANYCAST raw protocol address anycast address
IFA_CACHEINFO struct ifa_cacheinfo Address information.
RTM_NEWLINK, RTM_DELLINK, RTM_GETLINK
创建或者删除一个特定的网络接口,或者从一个特定的网络接口上获得信息。这些消息含有一个ifinfomsg类型的结构,紧跟在后面的是一系列的rtattr结构。
struct ifinfomsg
{
unsigned char ifi_family; /* AF_UNSPEC */
unsigned char __ifi_pad; /* unused */
unsigned short ifi_type; /* Device type */
int ifi_index; /* Interface index */
unsigned int ifi_flags; /* Device flags */
unsigned int ifi_change; /* change mask */
}
其中ifi_change是为将来预留的,总是被设为0xFFFFFFFF
rta_type value type description
--------------------------------------------------------------
IFLA_UNSPEC - unspecified.
IFLA_ADDRESS hardware address interface L2 address
IFLA_BROADCAST hardware address L2 broadcast address.
IFLA_IFNAME asciiz string Device name.
IFLA_MTU unsigned int MTU of the device.
IFLA_LINK int Link type.
IFLA_QDISC asciiz string Queueing discipline.
IFLA_STATS struct Interface Statistics.
net_device_stats
RTM_NEWADDR, RTM_DELADDR, RTM_GETADDR
添加,删除或者接收一个和接口相关的IP地址的信息。在linux2.2中,一个网口是可以有多个IP地址信息的。这些消息含有一个ifaddrmsg类型的结构,紧跟在后面的是一系列的rtattr结构。
struct ifaddrmsg
{
unsigned char ifa_family; /* Address type */
unsigned char ifa_prefixlen;/* Prefixlength of the address */
unsigned char ifa_flags; /* Address flags */
unsigned char ifa_scope; /* Address scope */
int ifa_index; /* Interface index */
};
rta_type value type description
-------------------------------------------------------------
IFA_UNSPEC - unspecified.
IFA_ADDRESS raw protocol address interface address
IFA_LOCAL raw protocol address local address
IFA_LABEL asciiz string name of the interface
IFA_BROADCAST raw protocol address broadcast address.
IFA_ANYCAST raw protocol address anycast address
IFA_CACHEINFO struct ifa_cacheinfo Address information.
RTM_NEWROUTE, RTM_DELROUTE, RTM_GETROUTE
创建,删除一个网络路由或者从一个网络路由上获得信息。这些消息包含了一个rtmsg结构,紧跟着的是一系列的rtattr结构,这是可选的。
struct rtmsg
{
unsigned char rtm_family; /* Address family of route */
unsigned char rtm_dst_len; /* Length of source */
unsigned char rtm_src_len; /* Length of destination */
unsigned char rtm_tos; /* TOS filter */
创建,删除一个网络路由或者从一个网络路由上获得信息。这些消息包含了一个rtmsg结构,紧跟着的是一系列的rtattr结构,这是可选的。
struct rtmsg
{
unsigned char rtm_family; /* Address family of route */
unsigned char rtm_dst_len; /* Length of source */
unsigned char rtm_src_len; /* Length of destination */
unsigned char rtm_tos; /* TOS filter */
unsigned char rtm_table; /* Routing table id */
unsigned char rtm_protocol;/* Routing protocol; see below */
unsigned char rtm_scope; /* See below */
unsigned char rtm_type; /* See below */
unsigned char rtm_protocol;/* Routing protocol; see below */
unsigned char rtm_scope; /* See below */
unsigned char rtm_type; /* See below */
unsigned int rtm_flags;
};
};
rtm_type Route type
-----------------------------------------------------------
RTN_UNSPEC unknown route
RTN_UNICAST a gateway or direct route
RTN_LOCAL a local interface route
RTN_BROADCAST a local broadcast route (sent as a
broadcast)
RTN_ANYCAST a local broadcast route (sent as a uni-
cast)
RTN_MULTICAST a multicast route
RTN_BLACKHOLE a packet dropping route
RTN_UNREACHABLE an unreachable destination
RTN_PROHIBIT a packet rejection route
RTN_THROW continue routing lookup in another table
RTN_NAT a network address translation rule
RTN_XRESOLVE refer to an external resolver (not
implemented)
-----------------------------------------------------------
RTN_UNSPEC unknown route
RTN_UNICAST a gateway or direct route
RTN_LOCAL a local interface route
RTN_BROADCAST a local broadcast route (sent as a
broadcast)
RTN_ANYCAST a local broadcast route (sent as a uni-
cast)
RTN_MULTICAST a multicast route
RTN_BLACKHOLE a packet dropping route
RTN_UNREACHABLE an unreachable destination
RTN_PROHIBIT a packet rejection route
RTN_THROW continue routing lookup in another table
RTN_NAT a network address translation rule
RTN_XRESOLVE refer to an external resolver (not
implemented)
rtm_protocol Route origin.
-----------------------------------------
RTPROT_UNSPEC unknown
RTPROT_REDIRECT by an ICMP redirect
(currently unused)
RTPROT_KERNEL by the kernel
RTPROT_BOOT during boot
RTPROT_STATIC by the administrator
比RTPROT_STATIC大的值就不会再被kernel解释了,他们就只是用于用户信息了。
-----------------------------------------
RTPROT_UNSPEC unknown
RTPROT_REDIRECT by an ICMP redirect
(currently unused)
RTPROT_KERNEL by the kernel
RTPROT_BOOT during boot
RTPROT_STATIC by the administrator
比RTPROT_STATIC大的值就不会再被kernel解释了,他们就只是用于用户信息了。
rtm_scope为到目标的距离
RT_SCOPE_UNIVERSE global route
RT_SCOPE_SITE interior route in the
local autonomous system
RT_SCOPE_LINK route on this link
RT_SCOPE_HOST route on the local host
RT_SCOPE_NOWHERE destination doesn't exist
RT_SCOPE_UNIVERSE global route
RT_SCOPE_SITE interior route in the
local autonomous system
RT_SCOPE_LINK route on this link
RT_SCOPE_HOST route on the local host
RT_SCOPE_NOWHERE destination doesn't exist
RT_SCOPE_UNIVERSE到RT_SCOPE_SITE之间的值是对用户可得的。
The rtm_flags有以下一些含义:
RTM_F_NOTIFY if the route changes, notify the user via
rtnetlink
RTM_F_CLONED route is cloned from another route
RTM_F_EQUALIZE a multicast equalizer (not yet implemented)
RTM_F_NOTIFY if the route changes, notify the user via
rtnetlink
RTM_F_CLONED route is cloned from another route
RTM_F_EQUALIZE a multicast equalizer (not yet implemented)
rtm_table表明了路由表
RT_TABLE_UNSPEC an unspecified routing table
RT_TABLE_DEFAULT the default table
RT_TABLE_MAIN the main table
RT_TABLE_LOCAL the local table
RT_TABLE_UNSPEC an unspecified routing table
RT_TABLE_DEFAULT the default table
RT_TABLE_MAIN the main table
RT_TABLE_LOCAL the local table
用户可以分配RT_TABLE_UNSPEC和RT_TABLE_DEFAULT之间任意的值。
属性
rta_type value type description
--------------------------------------------------------------
RTA_UNSPEC - ignored.
RTA_DST protocol address Route destination address.
RTA_SRC protocol address Route source address.
RTA_IIF int Input interface index.
RTA_OIF int Output interface index.
RTA_GATEWAY protocol address The gateway of the route
RTA_PRIORITY int Priority of route.
RTA_PREFSRC
RTA_METRICS int Route metric
RTA_MULTIPATH
RTA_PROTOINFO
RTA_FLOW
RTA_CACHEINFO
rta_type value type description
--------------------------------------------------------------
RTA_UNSPEC - ignored.
RTA_DST protocol address Route destination address.
RTA_SRC protocol address Route source address.
RTA_IIF int Input interface index.
RTA_OIF int Output interface index.
RTA_GATEWAY protocol address The gateway of the route
RTA_PRIORITY int Priority of route.
RTA_PREFSRC
RTA_METRICS int Route metric
RTA_MULTIPATH
RTA_PROTOINFO
RTA_FLOW
RTA_CACHEINFO
RTM_NEWNEIGH, RTM_DELNEIGH, RTM_GETNEIGH
RTM_NEWQDISC, RTM_DELQDISC, RTM_GETQDISC
RTM_NEWTCLASS, RTM_DELTCLASS, RTM_GETTCLASS
RTM_NEWTFILTER, RTM_DELTFILTER, RTM_GETTFILTER
RTM_NEWQDISC, RTM_DELQDISC, RTM_GETQDISC
RTM_NEWTCLASS, RTM_DELTCLASS, RTM_GETTCLASS
RTM_NEWTFILTER, RTM_DELTFILTER, RTM_GETTFILTER
这四组宏我就不一一介绍了,大家可以man一下。
发表评论
-
使用strongswan建立基于ikev2 eap-mschapv2的ipsec服务器
2017-04-17 23:14 3208sudo apt-get install strongsw ... -
使用strongswan/xl2tpd建立ipsec/l2tp服务器
2017-04-17 22:32 6163sudo apt-get install strongsw ... -
SecureFX中文件名乱码的解决
2014-08-28 03:23 3354原始贴子:https://forums.vandyke.c ... -
为Linux编译atheros ar1111(设备ID:168c:0037,AW-NB100H – AR5B225 Atheros half size)网卡驱动
2012-07-15 22:57 4597买了个zotac h61itx-a-e wifi主板,从zot ... -
PHY管理接口(MDIO)
2012-01-17 17:01 4216对吉比特以太网而言,串行通信总线称为管理数据输入输出 (MDI ... -
理解ipsec身份标识和认证选项
2012-01-11 15:42 6870This article is part of the Ide ... -
netfiletr和iptables的状态和连接跟踪机制
2012-01-11 15:38 3343Como se lleva a cabo el rastreo ... -
编译安装iw
2011-11-09 13:31 2376ubuntu安装build-essentials libnl- ... -
从ip addr add和ifconfig的区别看linux网卡ip地址的结构
2011-09-24 13:06 1670转至:http://blog.csdn.net/dog25 ... -
DLNA中的UPnP技术浅析
2011-09-22 18:39 5073说到DLNA,UPn ... -
Linux 用户态与内核态的交互——netlink 篇
2011-09-19 01:39 3523转至:http://bbs.chinaunix.net/thr ... -
netlink和rtnetlink(一)
2011-09-19 01:35 5228转到:http://blogold.chinaunix.net ... -
Linux——Netlink
2011-09-19 01:24 9656转载:http://blog.csdn.net/firo_ba ... -
linux notification chains
2011-08-13 00:26 1053linux内核由各个不同的子系统构成,比如网络子系统、存储 ... -
内核中的notification chain浅析
2011-08-13 00:25 1375内核中的很多子系统都是联系很紧密的,因此有可能某个子系统的某些 ... -
Linux Notification chains
2011-08-13 00:24 2845Notifier是Linux 中提供一种在内核子系统 中共 ... -
printk 使用方法
2011-08-12 22:28 9884内核通过 printk() 输出的信息具有日志级别,日志级 ... -
WEXT/mac80211/nl80211/cfg80211
2011-07-29 02:32 11255Wireless-Extensions--旧的无 ... -
fedora上wpa_supplicant上网配置
2011-07-29 01:28 35351,vi /etc/sysconfig/wpa_supplic ... -
vi替换命令用法详解
2011-07-19 01:06 2196vi替换命令用法详解 : ranges /pat1/ ...
相关推荐
`rtnetlink.c`是实现rtnetlink功能的主要源代码文件,其中包含了处理netlink消息的函数、事件处理逻辑以及与网络接口和路由相关的操作。开发者可以通过调用这些函数来执行任务,如创建、修改或删除网络接口,或者...
这个库提供了如下模块:Netlink协议实现(RTNetlink, TaskStats等)rtnl, 网络设置 --- 地址(addresses), 路由(routes), 传输控制(traffic controls)nl80211 --- 无线功能相关的API(开发中)nfnetlink --- netfilter ...
rtnetlink 软件包rtnetlink允许读取和更改内核的路由表。 网络路由,IP地址,... nlmod是一个特殊的内核模块,它允许您捕获内核内部的所有netlink(而不仅仅是rtnetlink)流量。 请注意,这可能在具有大量netlink流
Netlink 是Linux内核与用户空间之间的一种通信机制,它允许用户空间程序查询和更新内核数据结构,例如网络配置信息。在这个特定的场景中,我们关注的是如何使用Netlink查询IP路由信息以及可能遇到的问题。 在...
`<linux/rtnetlink.h>`头文件包含了处理路由和Netlink相关数据结构的定义。 ```c struct rtmsg { __u8 rtm_family; // 地址族,通常为AF_INET或AF_INET6 __u8 rtm_dst_len; // 目标地址长度 __u8 rtm_src_len; /...
与和集成是可选的。 每个netlink协议都有一个netlink-packet-板条箱,用于提供该协议的数据包: 提供有关消息提供有关协议的消息提供有关协议的消息是所有其他netlink-packet-*包装箱的胶水。 它提供了...
`rtnetlink`是一种基于`netlink`机制的协议,`netlink`是Linux内核提供的一种用于进程间通信(IPC)的机制,特别适用于用户空间程序和内核模块之间的通信。`rtnetlink`主要负责处理网络相关的控制消息,如创建、删除...
#include <linux/rtnetlink.h> #include #include #include // 省略Netlink相关的处理代码 int main() { // 创建Netlink套接字,订阅事件等 // 接收并处理来自内核的消息,解析IPv6地址 } ``` ...
- RTNetlink是Netlink的一个子集,专门用于处理路由相关的信息。 - **2.2.5.1 内核创建Netlink套接字 (Function netlink_kernel_create())** - **2.2.5.2 注册网络设备通知器 (Function register_netdevice_...
- 内核初始化rtnetlink模块,创建NETLINK_ROUTE协议簇的netlink套接字。 - 用户空间同样创建NETLINK_ROUTE协议簇的netlink套接字,并绑定到RTMGRP_IPV4_IFADDR组播组,以便接收IP地址变更的消息。 - 当IP地址变化...
Netlink是一种路由器管理协议,它为内核与用户空间应用程序之间提供了通信机制,主要用于网络设备管理和配置。具体来说,初始化Netlink套接字的代码位于`linux-2.4.22\net\core\Rtnetlink.c`文件中,这部分代码实现...
#include <linux/rtnetlink.h> #include int main() { int sock = socket(PF_ROUTE, SOCK_RAW, 0); if (sock ) { perror("Failed to create socket"); return 1; } struct sockaddr_nl sa; memset(&sa, 0,...
2.2.5 Function rtnetlink init() . . . . . . . . . . . . . . . . . 12 2.2.5.1 Function netlink kernel create() . . . . . . . . 13 2.2.5.2 Function register netdevice notifier() . . . . . 13 2.2.6 ...
介绍 Xenium LLMNR响应程序(xllmnrd)是一个IPv6网络服务守护程序,它响应来自同一网络链接... 但是它的存在并不意味着与LSB规范的任何一致性。 执照 本程序是根据或任何更高版本的条款和条件提供的。 也可以看看 。