Linux Source code location of interface configuration(eth) - linux-kernel

My requirement is to implement(insert ) an ip address validation step in kernel.. Once any of the interface is up and got ip, then my validation should happen..
So as the first step , in source code (linux 2.6 source code I downloaded ) , in which file I need to trace

The kernel is the wrong place for this unless you're doing something embedded with a teeny tiny footprint. What you really want is ifplugd.
However, if you absolutely insist on having it be in the kernel - take a look at the kernel bits that get enabled when CONFIG_IP_PNP=y

Related

How does Linux kernel parse vga= parameter?

I want to boot my Linux 3.18.48 compiled from source, with resolution 640x480. So I'm passing it a parameter vga=0x312. For some reason, it doesn't work.
To understand what's happening, I grep'ed the kernel source for "vga=", expecting some macro __setup("vga=", function_ptr), similar to other kernel cmdline parameters (video=, root=, etc).
However, there's no such occurrence.
So how does the Linux kernel parse vga= parameter?
According to the docs:
vga= [BOOT,X86-32] Select a particular video mode
...
This is actually a boot loader parameter; the value is
passed to the kernel using a special protocol.
So the kernel does not parse this parameter at all. In my case it's GRUB 2.02 parsing this parameter and passing to the kernel through variable gfxpayload, as listed in GRUB's linux command.
Now I can continue investigating why vga= parameter is being ignored, looking at GRUB's source :-)
EDIT
vga= is parsed by GRUB only on legacy BIOS systems.
That's why vga= is being ignored on my machine. Since I'm using a UEFI system, I need to set the gfxpayload variable directly:
set gfxpayload=640x480
Now it sets the resolution correctly.

Using maketorrent in libtorrent examples

So I am trying to build an application that uses libtorrent. However, before I start I would like to make sure that I have compiled the lib correctly and that I have a functioning environment for testing.
I am currently running a VM with opentracker and I try to connect using the example client in libtorrent.
First I start by creating a .torrent file using libtorrent (I am currently not sitting in front of a computer with libtorrent available so I might be remembering the exact commands a bit wrong):
maketorrent.exe dummy.txt -t "http://10.XXX.XXX.XXX/announce"
This gives me a .torrent file called a.torrent. Opening the file everything looks ok, the bencoding is correct and the announce address is there.
Next I try to add it to the example client hoping it starts to seed:
client_test.exe a.torrent
Everything starts up OK, but no tracker is found. Then if I press t to show tracker information I see an error (maybe not the exact phrasing):
Alert: {null} unsupported URL protocol
OK, so maybe something is wrong with how I built libtorrent. So I get the Halite client instead since that is also supposed to be build upon libtorret. But there I have the same problem.
So I have a look at the code and found where this error message is generated. The code is checking if I am supplying an address using the HTTP or HTTPS protocol, which I am. So could it be that I am not able to use a bare IP-address or am I doing something wrong?
I found the problem. It was not a problem with the IP address or the torrent itself. Instead it was a problem with caching.
The first time I added the torrent I used http:\XXX.XXX.XXX.XXX instead of http://XXX.XXX.XXX.XXX which didn't work. However whatever change i did to the torrent file after that did not stick. It was always falling back to that original file until I removed the .resume folder.

Debugging Linux Kernel Module

I have built a linux kernel module which helps in migrating TCP socket from one server to another. The module is working perfectly except when the importing server tries to close the migrating socket, the whole server hangs and freezes.
I am not able to find out the root of the problem, I believe it is something beyond my kernel module code. Something I am missing when I am recreating the socket in the importing machine, and initializes its states. It seems that the system is entering an endless loop. But when I close the socket from client side, this problem does not appear at all.
So my question, what is the appropriate way to debug the kernel module and figure out what is going on, why is it freezing? How to dump error messages especially in my case I am not able to see anything, once I close the file descriptor related to the migrated socket in the server side, the machines freezes.
Note: I used printk to print all the values, and I am not able to find something wrong in the code.
Considering your system is freezing, have you checked if your system is under heavy load while migrating the socket, have you looked into any sar reports to confirm this, see if you can take a vmcore (after configuring kdump) and use crash-tool to narrow down the problem. First, install and configure kdump, then you may need add the following lines to /etc/sysctl.conf and running sysctl -p
kernel.hung_task_panic=1
kernel.hung_task_timeout_secs=300
Next get a vmcore/dump of memory:
echo 'c' > /proc/sysrq-trigger # ===> 1
If you still have access to the terminal, use the sysrq-trigger to dump all the stack traces of kernel thread in the syslog:
echo 't' > /proc/sysrq-trigger
If you system is hung try using the keyboard hot keys
Alt+PrintScreen+'c' ====> same as 1
Other things you may want to try out, assuming you would have already tried some of the below:
1. dump_stack() in your code
2. printk(KERN_ALERT "Hello msg %ld", err); add these lines in the code.
3. dmesg -c; dmesg

How to configure spi in the driver file insted of giving configuration in the application

I want to write a test driver for mcspi and want to give all configuration in my driver file (instead of using user space application I want to use driver as a test driver and want to create .ko) and want to pass all configuration to the mcspi controller.
The configurations like chip_select, mode, speed, bits etc., Basically all these configurations I want to use for my test driver to check functionality of FIFO mode in the mcspi. I have already enabled FIFO in the mcspi but I want to check its functionality.
Can anyone please give me some suggestions?
I don't really know why cant you do something you want. I think you can pass the configuration by set up parameters using module_param
Adding on what #sunnyleevip suggested: another "standard" way to configure your driver would be to expose the params of interest via the /proc or the /sys filesystems.
You can find all the details in Linux Device Driver
Expanding on #sergico and #sunnyleevip, you could also use device tree to pass configuration data to the driver. The SPI bus master driver (since the 2.6.30s and all of the 3.x kernels) already are pretty devicetree supportive, so there might not be much more to do to get it to work.

Uboot Option to print boot time prefixes

Is there any uboot config option to print boot sequence with time prefixes similar to kernel option CONFIG_PRINTK?
I am expecting output like below,
[ 0.000000] U-Boot 1.1.4-gedeced79 (Feb 6 2012 - 09:27:11)
[ 0.011300] Starting kernel ...
[ 0.015686] Uncompressing Linux... done, booting the kernel
define DEBUG config option is best for your purpose, it is picked up by all u-boot code after you put it in your include/configs/myboard.h. (each config option is '#define', but that is doing strange things in my page preview)
Also
define CONFIG_BOOTSTAGE.
You can look at README for this, code is in common/bootstage.c, its functions do some of what you want. You may have to add a function show_boot_progress() in your BSP, for these functions to be used. With those in place, I believe there are already hooks in infrastructure code for them to get called, but I haven't used this option.
I am not aware of U-Boot config option that does such thing, but there are some other techniques which enables you to do it. I.e. config option inside the Linux kernel.
Take a look at: Measuring Boot-up time

Resources