深入理解Linux网络技术内幕——用户空间与内核空间交互
概述:
procfs 与 sysctl
procfs
static const struct file_operations arp_seq_fops = { .owner = THIS_MODULE, .open = arp_seq_open, .read = seq_read, .llseek = seq_lseek, .release = seq_release_net, };
static int __net_init arp_net_init(struct net *net) { if (!proc_create("arp", S_IRUGO, net->proc_net, &arp_seq_fops)) return -ENOMEM; return 0; }
static inline struct proc_dir_entry *proc_create(const char *name, umode_t mode, struct proc_dir_entry *parent, const struct file_operations *proc_fops) { return proc_create_data(name, mode, parent, proc_fops, NULL); }
static int arp_seq_open(struct inode *inode, struct file *file) { return seq_open_net(inode, file, &arp_seq_ops, sizeof(struct neigh_seq_state)); }
static const struct seq_operations arp_seq_ops = { .start = arp_seq_start, .next = neigh_seq_next, .stop = neigh_seq_stop, .show = arp_seq_show, };
sysctl:/proc/sys目录
struct ctl_table { const char *procname; /* Text ID for /proc/sys, or zero */ void *data; int maxlen; umode_t mode; struct ctl_table *child; /* Deprecated */ proc_handler *proc_handler; /* Callback for text formatting */ struct ctl_table_poll *poll; void *extra1; void *extra2; };
sysfs
ioctl
struct ifreq data; fd = socket(PF_INET, SOCK_DGRAM, 0); < ... initialize "data" ...> err = ioctl(fd, SIOCSIFMTU, &data);
Netlink
int socket(int domain, int type, int protocol)
#define NETLINK_ROUTE 0 /* Routing/device hook */ #define NETLINK_UNUSED 1 /* Unused number */ #define NETLINK_USERSOCK 2 /* Reserved for user mode socket protocols */ #define NETLINK_FIREWALL 3 /* Unused number, formerly ip_queue */ .....
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。