Linux Kernel 网络实现
星空探索
linux
展开
-
linux 网络协议
/* * The protocol list. Each protocol is registered in here. */static DEFINE_SPINLOCK(net_family_lock);static const struct net_proto_family __rcu *net_families[NPROTO];static const str原创 2016-10-09 21:43:53 · 713 阅读 · 0 评论 -
网络层数据接收
static int __netif_receive_skb(struct sk_buff *skb){int ret;if (sk_memalloc_socks() && skb_pfmemalloc(skb)) {unsigned long pflags = current->flags;/** PFMEMALLOC skbs are special,原创 2016-10-06 18:41:55 · 687 阅读 · 0 评论 -
探测封包类型
/** * eth_type_trans - determine the packet's protocol ID. * @skb: received socket data * @dev: receiving network device * * The rule here is that we * assume 802.3 if the type field is sh原创 2016-10-06 19:03:21 · 632 阅读 · 0 评论 -
以太网帧结构
struct ethhdr {unsigned char h_dest[ETH_ALEN]; /* destination eth addr*/unsigned char h_source[ETH_ALEN]; /* source ether addr*/__be16 h_proto; /* packet type ID field*/} __attribu原创 2016-10-06 23:32:35 · 2642 阅读 · 0 评论 -
napi介绍
/* * Structure for NAPI scheduling similar to tasklet but with weighting */struct napi_struct {/* The poll_list must only be managed by the entity which* changes the state of the NAPI_STATE_转载 2016-10-07 00:15:11 · 928 阅读 · 0 评论 -
网络设备NAPI能力
void netif_napi_add(struct net_device *dev, struct napi_struct *napi, int (*poll)(struct napi_struct *, int), int weight){INIT_LIST_HEAD(&napi->poll_list);hrtimer_init(&napi->timer, CLOCK_MO原创 2016-10-07 00:32:21 · 629 阅读 · 0 评论 -
packet_type
struct packet_type { __be16 type; /* This is really htons(ether_type). */ struct net_device *dev; /* NULL is wildcarded here */ int (*func) (struct sk_buff *, struct net_device *原创 2017-03-13 08:10:36 · 424 阅读 · 0 评论 -
napi_gro_cb
struct napi_gro_cb { /* Virtual address of skb_shinfo(skb)->frags[0].page + offset. */ void *frag0; /* Length of frag0. */ unsigned int frag0_len; /* This indicates where we are proc原创 2017-03-13 08:11:38 · 464 阅读 · 0 评论 -
socket文件
static const struct file_operations socket_file_ops = { .owner = THIS_MODULE, .llseek = no_llseek, .read_iter = sock_read_iter, .write_iter = sock_write_iter, .poll = sock_poll, .unlocked原创 2017-03-13 08:14:23 · 538 阅读 · 0 评论 -
general BSD socket
/** * struct socket - general BSD socket * @state: socket state (%SS_CONNECTED, etc) * @type: socket type (%SOCK_STREAM, etc) * @flags: socket flags (%SOCK_NOSPACE, etc) * @ops: protoco原创 2017-03-13 08:14:34 · 133 阅读 · 0 评论 -
sock结构
/** * struct sock - network layer representation of sockets * @__sk_common: shared layout with inet_timewait_sock * @sk_shutdown: mask of %SEND_SHUTDOWN and/or %RCV_SHUTDOWN * @sk_userlock原创 2017-03-13 08:14:50 · 844 阅读 · 0 评论 -
sock_common
/** * struct sock_common - minimal network layer representation of sockets * @skc_daddr: Foreign IPv4 addr * @skc_rcv_saddr: Bound local IPv4 addr * @skc_hash: hash value used with various pro原创 2017-03-13 08:15:03 · 702 阅读 · 0 评论 -
sk_buff_head
struct sk_buff_head { /* These two members must be first. */ struct sk_buff *next; struct sk_buff *prev; __u32 qlen; spinlock_t lock;};/** * struct sk_buff - socket buffer原创 2017-03-13 08:15:18 · 1805 阅读 · 2 评论 -
net_device
/** * struct net_device - The DEVICE structure. * Actually, this whole structure is a big mistake. It mixes I/O * data with strictly "high-level" data, and it has to know about * almost ev原创 2017-03-13 08:15:33 · 450 阅读 · 0 评论 -
net_device_ops
/* * This structure defines the management hooks for network devices. * The following hooks can be defined; unless noted otherwise, they are * optional and can be filled with a null pointer. *原创 2017-03-13 08:15:48 · 2069 阅读 · 0 评论 -
网络层协议注册
static DEFINE_SPINLOCK(ptype_lock);struct list_head ptype_base[PTYPE_HASH_SIZE] ;struct list_head ptype_all ; /* Taps */struct packet_type {__be16 type; /* This is really htons(ether_typ原创 2016-10-06 18:33:14 · 240 阅读 · 0 评论 -
发送IP封包到高层协议
int ip_local_deliver(struct sk_buff *skb){/** Reassemble IP fragments.*/struct net *net = dev_net(skb->dev);if (ip_is_fragment(ip_hdr(skb))) {if (ip_defrag(net, skb, IP_DEFRAG_LOCAL_原创 2016-10-06 18:09:38 · 564 阅读 · 0 评论 -
IP上层协议注册
/* This is one larger than the largest protocol value that can be * found in an ipv4 or ipv6 header. Since in both cases the protocol * value is presented in a __u8, this is defined to be 256.原创 2016-10-06 17:53:21 · 332 阅读 · 0 评论 -
socket创建过程
SYSCALL_DEFINE3(socket, int, family, int, type, int, protocol){int retval;struct socket *sock;int flags;/* Check the SOCK_* constants for consistency. */BUILD_BUG_ON(SOCK_CLOEXEC != O原创 2016-10-09 22:45:04 · 622 阅读 · 0 评论 -
lINUX iCmp协议
ICMP是(Internet Control Message Protocol)Internet控制报文协议。它是TCP/IP协议族的一个子协议,用于在IP主机、路由器之间传递控制消息。控制消息是指网络通不通、主机是否可达、路由是否可用等网络本身的消息。这些控制消息虽然并不传输用户数据,但是对于用户数据的传递起着重要的作用。在Linux kernel中密切相关的函数是下面几个:void i原创 2016-10-13 19:16:56 · 1033 阅读 · 0 评论 -
IGMP
IGMP(Internet Group Manage Protocol):Internet组管理协议,提供internet网际多点传送的功能,即将一个ip包拷贝给多个host。 IGMP的工作过程如下:一. 当主机加入一个新的工作组时,它发送一个igmp host membership report的报文给全部主机组,宣布此成员关系.本地多点广播路由器接受到这个报文后,向Inter原创 2016-10-13 19:25:56 · 720 阅读 · 0 评论 -
RAW实现
struct proto raw_prot = { .name = "RAW", .owner = THIS_MODULE, .close = raw_close, .destroy = raw_destroy, .connect = ip4_datagram_connect, .disconnect = udp_disconnec原创 2016-10-13 19:39:16 · 619 阅读 · 0 评论 -
Linux IP 处理
增加IP头到一个skb,之后发送这个skb到下层处理。int ip_build_and_send_pkt(struct sk_buff *skb, const struct sock *sk, __be32 saddr, __be32 daddr, struct ip_options_rcu *opt){struct inet_sock *inet = inet_sk(sk);原创 2016-10-01 22:28:09 · 315 阅读 · 0 评论 -
Linux IP处理之ip_queue_xmit
ip_queue_xmit()完成面向连接套接字的包输出,当套接字处于连接状态时,所有从套接字发出的包都具有确定的路由, 无需为每一个输出包查询它的目的入口,可将套接字直接绑定到路由入口上, 这由套接字的目的缓冲指针(dst_cache)来完成.ip_queue_xmit()首先为输入包建立IP包头, 经过本地包过滤器后,再将IP包分片输出(ip_fragment)。/原创 2016-10-01 22:33:23 · 3358 阅读 · 0 评论 -
Linux TCP/IP socket 实现
简要记录函数调用流程SYSCALL_DEFINE3(socket, int, family, int, type, int, protocol){int retval;struct socket *sock;int flags;/* Check the SOCK_* constants for consistency. */BUILD_BUG_ON(S原创 2016-10-01 22:48:54 · 470 阅读 · 0 评论 -
Linux 内核 net_proto_family
static const struct net_proto_family inet_family_ops = {.family = PF_INET,.create = inet_create,.owner = THIS_MODULE,};(void)sock_register(&inet_family_ops);/** * sock_register -原创 2016-10-01 22:58:10 · 1232 阅读 · 0 评论 -
Linux创建socket
static const struct net_proto_family inet_family_ops = {.family = PF_INET,.create = inet_create,.owner = THIS_MODULE,};/* * Create an inet socket. */static int inet_create(原创 2016-10-01 23:01:05 · 547 阅读 · 0 评论 -
inetsw table
/* The inetsw table contains everything that inet_create needs to * build a new socket. */static struct list_head inetsw[SOCK_MAX];static DEFINE_SPINLOCK(inetsw_lock);for (q = inetsw_arr原创 2016-10-01 23:08:20 · 356 阅读 · 0 评论 -
传输层实现
struct inet_protosw {struct list_head list; /* These two fields form the lookup key. */unsigned shorttype; /* This is the 2nd argument to socket(2). */unsigned shortprotocol;原创 2016-10-01 23:12:01 · 495 阅读 · 0 评论 -
tcp_prot
{.type = SOCK_STREAM,.protocol = IPPROTO_TCP,.prot = &tcp_prot,.ops = &inet_stream_ops,.flags = INET_PROTOSW_PERMANENT | INET_PROTOSW_ICSK,},struct pr原创 2016-10-01 23:13:35 · 590 阅读 · 0 评论 -
udp_prot
{.type = SOCK_DGRAM,.protocol = IPPROTO_UDP,.prot = &udp_prot,.ops = &inet_dgram_ops,.flags = INET_PROTOSW_PERMANENT, },struct proto udp_prot = {原创 2016-10-01 23:15:09 · 483 阅读 · 0 评论 -
ping_prot
{.type = SOCK_DGRAM,.protocol = IPPROTO_ICMP,.prot = &ping_prot,.ops = &inet_dgram_ops,.flags = INET_PROTOSW_REUSE, },struct proto ping_prot = {.nam原创 2016-10-01 23:16:36 · 719 阅读 · 0 评论 -
raw_prot
{ .type = SOCK_RAW, .protocol = IPPROTO_IP,/* wild card */ .prot = &raw_prot, .ops = &inet_sockraw_ops, .flags = INET_PROTOSW_REUSE,原创 2016-10-01 23:18:14 · 297 阅读 · 0 评论 -
Socket types
/** * enum sock_type - Socket types * @SOCK_STREAM: stream (connection) socket * @SOCK_DGRAM: datagram (conn.less) socket * @SOCK_RAW: raw socket * @SOCK_RDM: reliably-delivered message *原创 2016-10-06 17:37:36 · 424 阅读 · 0 评论 -
Linux内核网络ip_mkroute_input
为输入的IP包生成一个路由项: ip_mkroute_inputstatic int ip_mkroute_input(struct sk_buff *skb, struct fib_result *res, const struct flowi4 *fl4, struct in_device *in_dev, __be3原创 2017-03-23 08:23:31 · 1521 阅读 · 0 评论