how to remember ip/tcp/udp header

IP HEADER

以前找工作时,常被问到IP头都有哪些字段?
现在觉得真的理解了记起来没那么难。

上路时总要记得终点和起点(src/dst ip),
要倒几次车,大体也知道(ttl).

路有大路有小路,有高速路和土路。
大路到小路要分片,小路到大路可能重组。
上高速路需要通行证(qos/tos).

路上有警察,查你是不是非法(csum, header len, ip option),
查你装的什么货(protocol)?

Read More

inetsw table

Data struct.

1
2
3
4
5
123 /* The inetsw table contains everything that inet_create needs to
124 * build a new socket.
125 */
126 static struct list_head inetsw[SOCK_MAX];
127 static DEFINE_SPINLOCK(inetsw_lock);

Read More

how to create a inet socket

Data Structure

1
2
3
4
5
1019 static const struct net_proto_family inet_family_ops = {
1020 .family = PF_INET,
1021 .create = inet_create,
1022 .owner = THIS_MODULE,
1023 };

call trace

1
2
3
4
5
6
> inet_create
> > search the right inetsw array element with type/protocol
> > sock->ops = answer->ops;
> > k = sk_alloc(net, PF_INET, GFP_KERNEL, answer_prot);
> > sock_init_data(sock, sk);
> > init the sk

Read More

system call socket

Summary

System call socket will do two things:

  1. create a struct socket *sock.
    Mainly done by __sock_create, which alloc a struct socket *sock,
    then init it with the creating method of net_families[family].
  2. map the sock to a file descriptor by sock_map_fd.
    TODO…..

call trace:

1
2
3
4
5
6
7
8
9
10
11
12
> socket
> > sock_create
> > > __sock_create
> > > > sock = sock_alloc();
> > > > sock->type = type;
> > > > rcu_read_lock();
> > > > pf = rcu_dereference(net_families[family]);
> > > > try_module_get(pf->owner))
> > > > rcu_read_unlock();
> > > > pf->create(net, sock, protocol, kern);
> > > > module_put(pf->owner)
> > socket_map_fd

Read More

socket net_proto_family

summary

Each family has a corresponding array element of struct net_proto_family,
which will be called in system call socket.

Data Structure

1
2
3
4
5
6
181 struct net_proto_family {
182 int family;
183 int (*create)(struct net *net, struct socket *sock,
184 int protocol, int kern);
185 struct module *owner;
186 };

The create is important, which is first and basic function during
system call socket.

1
2
164 static DEFINE_SPINLOCK(net_family_lock);
165 static const struct net_proto_family __rcu *net_families[NPROTO] __read_mostly;

Read More

how to update github page in multi pos

Requirement

I want to write blog with github page and octopress in the office
and in the home.

Steps

The github page has work well done with pc in the home.
Now setup the environment in office to write github page.
The github page repo:
https://github.com/martinbj2008/martinbj2008.github.io

the octopress is pushed to git repo as branch “source”

How to write blog and sync them to github while avoid conflict with home?

Read More