login
Header Space

 
 

Eus's blog

How to Start Hacking the Linux Kernel

June 20, 2008 - 3:54am
Submitted by Eus on June 20, 2008 - 3:54am.
Linux

Someone posted such a question here.

Personally, I started to hack the Linux kernel when developing a new networking suite called the ATN TP4/CLNP Networking Suite for use with GNU/Linux systems in the aeronautical industry. So, I have some suggestions here.

What does SOCK_ZAPPED mean?

June 13, 2008 - 12:38am
Submitted by Eus on June 13, 2008 - 12:38am.
Linux

SOCK_ZAPPED, which is defined in include/net/sock.h, is a status flag of a socket (struct sock) to indicate that the socket has a name assigned to it already (i.e., the socket is bound with bind()).

Archive: Linux Kernel's Networking Part (Networking Socket)

What Kind of Ethernet MAC Addresses are These?

June 11, 2008 - 2:47pm
Submitted by Eus on June 11, 2008 - 2:47pm.
Linux

It turned out that any wireless Ethernet card's device driver in a non-promiscuous mode does not drop any Ethernet frame with the following destination MAC address:
YY:xx:xx:xx:xx:xx, where YY is an odd number (e.g., 0xE1, 0x11, 0x01, etc.)

Don't Forget "make clean"

June 10, 2008 - 4:02am
Submitted by Eus on June 10, 2008 - 4:02am.

Just yesterday my friend and I were wondering why his Linux kernel module crashed the kernel in QEMU everytime the module was removed with rmmod; it caused the kernel to issue the BUG message on the screen before crashing. The kernel module itself had just been transfered from his host GNU/Linux operating system via scp.

Localhost does not Response to Ping to Multicast Address 224.0.0.1

June 1, 2008 - 11:28am
Submitted by Eus on June 1, 2008 - 11:28am.
Linux

If you are wondering why:

ping 224.0.0.1

does not give you anything back from your localhost or other hosts that are running Linux kernel 2.6, it is because, in Linux kernel 2.6, the capability of ICMP to reply to broadcast/multicast ping message is disabled by default. Whereas, it is enabled by default in Linux kernel 2.4.

The Relation between `skb->len' and `skb->data_len' and What They Represent

June 1, 2008 - 11:16am
Submitted by Eus on June 1, 2008 - 11:16am.
Linux

If skb is linear (i.e., skb->data_len == 0), the length of skb->data is skb->len.

How to Differentiate between EOF and a Character whose ASCII code is 255

June 1, 2008 - 11:05am
Submitted by Eus on June 1, 2008 - 11:05am.

A call to fgetc() or getchar() will return EOF if the end-of-file has been reached.
As far as I know, GNU C Library defines EOF to be (-1).

Those who are unwary will think that those functions return a char.
Now a char has a range from 0x00 to 0xFF because its size is one byte.
However, if EOF is returned as a char, which must take one value from the range, there will be no way to differentiate whether or not the returned char is actually a byte read from the stream or EOF to signal that the end-of-file has been reached already.

insmod: error inserting 'x.ko': -1 Invalid module format

May 22, 2008 - 10:07am
Submitted by Eus on May 22, 2008 - 10:07am.
Linux

That error message is issued because a version mismatch occurs when the Linux kernel module to be inserted into the working kernel was not compiled with the source code that was used to compile the working Linux kernel.

Where `skb->len' is set so that ip_rcv() can directly perform `skb->len < iph->tot_len'?

May 22, 2008 - 9:47am
Submitted by Eus on May 22, 2008 - 9:47am.
Linux

As an example, let's use Realtek 8139 as the NIC.

cp_rx_poll(): desc = &cp->rx_ring[rx_tail];
 |            status = le32_to_cpu(desc->opts1);
 |            len = (status & 0x1fff) - 4;
 |
 V
dev_alloc_skb(): skb->len = 0
 |
 V
skb_put(): skb->len += len

Printing size_t or ssize_t variable

May 18, 2008 - 11:28am
Submitted by Eus on May 18, 2008 - 11:28am.

Looking at the man page of printf (man 3 printf), in the length modifier section, it is written:

z       A following integer conversion corresponds to a size_t or ssize_t argument. (Linux libc5 has Z with this meaning. Don't use it.)

Therefore,

size_t x = sizeof (int);

printf ("%zd\n", x);

Zero-length array to provide an elegant link

May 18, 2008 - 11:22am
Submitted by Eus on May 18, 2008 - 11:22am.

Consider the following struct and program:

#include <stdio.h>
#include <stdlib.h>

struct fix_data
{
	char data [5];
	unsigned char optional_part [0];
} __attribute__ ((packed));

int main (int argc, char **argv, char **envp)
{
	char buffer [10] = "Name\0emaN\0";
	int i = 0;
	struct fix_data *ptr = (struct fix_data *) buffer;

Why do the function prototypes use extern

May 18, 2008 - 11:14am
Submitted by Eus on May 18, 2008 - 11:14am.
Linux

It is a universal truth that with or without the extern keyword a function prototype will just do the same. So, why does almost all function prototypes in Linux kernel source code prefixed with the extern keyword?

Getting the size of a member of a struct or union

May 18, 2008 - 11:07am
Submitted by Eus on May 18, 2008 - 11:07am.

Looking at Getting the offset of a member in a struct, I realized that you can also use the same technique to get the size of a member of a struct or a union without declaring a variable of that struct. Suppose a struct has been defined as follows:

struct person
{
	int id;
	char name [50];
	double salary;
};

Getting the offset of a member in a struct

May 18, 2008 - 11:02am
Submitted by Eus on May 18, 2008 - 11:02am.
Linux
struct aligned_struct
{
	char a [5];
	int b;
};

Another way to use the C ternary operator (? :)

May 12, 2008 - 8:58am
Submitted by Eus on May 12, 2008 - 8:58am.
Linux

I found in Linux kernel 2.6.21.5 in include/net/netinet_hastables.h in function __inet_lookup this interesting expression:

	return sk ? : __inet_lookup_listener(hashinfo, daddr, hnum, dif);
speck-geostationary