Specifying new option for hop by hop extension header IPv6? - c

I have been trying to get an answer for this for sometime now but not been able to find it.
Is there a way that I can specify a new option value for the hop by hop extension header in IPv6, so that I can parse the value in the user space rather than the kernel parsing it?
The kernel when tries to parse the value, sends me an ICMP reply stating parameter not recognized for that value in the header.
I'm wondering if there should be a way to deploy and test new options in IPv6 extension header without writing handlers for them as LKM.
There isn't a lot available on the web for IPv6, so any help from IPv6 experts would be great!
RFC 2460 mentions this. I assume you can create a new option type for testing any new applications:
Mindful of the need for compatibility with existing IPv6 deployments,
new IPv6 extension headers MUST NOT be created or specified, unless
no existing IPv6 Extension Header can be used by specifying a new
option for that existing IPv6 Extension Header. Any proposal to
create or specify a new IPv6 Extension Header MUST include a detailed
technical explanation of why no existing IPv6 Extension Header can be
used in the Internet-Draft proposing the new IPv6 Extension Header.

As for "The kernel when tries to parse the value, sends me an ICMP reply ..." you mentioned, by "kernel" I assume you means a remote ipv6 node ( either router or destination host ). Then you might set the "Option Type" wrong way in your egress packet sending by raw-socket.
As RFC 2460 says:
The Option Type identifiers are internally encoded such that their highest-order two bits specify the action that must be taken if the processing IPv6 node does not recognize the Option Type:
00, 01, 10, 11 ....
--- I guess you fill in "10" or "11", you could fill in "00"

Related

Whats the meaning from the IP Headers in C iph_tos?

Of course, some information are going to be send to the target machine. Something like the IP version and the length... But what does "tos" mean?
­­­­­­­­­­­­­­­­­­­­
From [man]: IP(7):
IP_TOS (since Linux 1.0)
Set or receive the Type-Of-Service (TOS) field that is sent...

How to set total length of TCP option in Linux kernel?

I'm trying to add a new TCP option inside Linux kernel. However, I find that my new option cannot coexist with other options because there are no enough spaces in the option field for it. I get the warning from wireshark as "option goes past end of options".
So I'm wondering how I can extend the length of the whole TCP option field?
In tcp_parse_options() of tcp_input.c, I find such statement:
int length = (th->doff * 4) - sizeof(struct tcphdr);
And the while loop to parse options starts with while (length > 0). However, no matter how I increase the value of th->doff in tcp_make_synack() of tcp_output.c, the problem remains. I also suspect this is because I add the option in SYN pakcet while this function is for SYN-ACK. But I cannot find similar functions such as tcp_make_synack()....
Does anyone have any insights of this problem?
Thanks!

FreeBSD: Understanding /var/db/dhclient.leases.<interface_name> dhcp lease files

FreeBSD: network interface address: dhcp or static
Followup question now:
I've decided to go with looking at leases files: /var/db/dhclient.leases.. What does it tell me exactly? Existence of /var/db/dhclient.leases.em0 signifies em0 has address by DHCP? This file does not seem to go away with reboot.
You should read the manual page for dhclient. This will answer most of your questions. And if that fails, you can browse the source in /usr/src/sbin/dhclient.
Another possibility might be to to use devd(8). This is a daemon that can execulte a script or program if a certain event occurs. It can e.g. note when a network interface goes "up" or "down". From the default /etc/devd.conf (see also devd.conf(5)):
# Try to start dhclient on Ethernet-like interfaces when the link comes
# up. Only devices that are configured to support DHCP will actually
# run it. No link down rule exists because dhclient automatically exits
# when the link goes down.
#
notify 0 {
match "system" "IFNET";
match "type" "LINK_UP";
media-type "ethernet";
action "/etc/rc.d/dhclient quietstart $subsystem";
};
A client is supposed to remember a DHCP lease across reboots and is supposed to remember past leases on a particular network when requesting an address. Therefore, the file should not go away across boots.

Finding interface name for destination address using routing table

i'm trying to find a linux C function which should obtain interface name(or id) of ipv6 destination address using routing informating.
I want use this interface name to send my raw packet through pcap_inject()
Does something like this exist? or i have to popen ip -6 route and parse information from this output?
what you are looking for is ICMPv6 protocol, messages are NeighborAdvertisment and NeighborSolicitation

getting the domain name by code in Linux

I am using getdomainname() and gethostbyname() to try to get the domain of the computer so I can show the correct information on my program. However sometimes these functions don't return the correct information.
Is there any other way (in plain C) to get the domain name in Linux?
Edit: just to make it a bit more clear: I want to check if the computer is part of a domain. If it is, get the domain name.
Currently I am using the functions mentioned above. Are there any others?
#unwind: please DO NOT edit this question for "brevity" if I would like to say thanks I'll say thanks.
Thanks!
If you want to get the (Internet) domain name there are certain issues you need to think about.
A computer can have multiple network interfaces, in fact it almost certainly has at least two including the loopback interface. Each interface has an IP address (possibly more than one) and each IP address can be mapped to from any number of DNS names and entries in the hosts file.
So which, if any of the many possible domain names that getdomainname() returns depends on a whole raft of configuration issues. e.g. which IP address is configured to be the primary address, whether the hosts file is used in preference to DNS, whether the hosts file is correctly configured, whether the IP address has a reverse lookup set and lots of other issues.
For instance, it is fairly common to misconfigure the hosts file. If you see an entry in it like:
192.168.1.1 foohost foohost.example.com
that is wrong. The first host name on a line is the canonical name (for the interface) and subsequent entries are merely aliases. If you want the domain to come out as example.com rather than nothing, it needs to look like this:
192.168.1.1 foohost.example.com foohost
Also, every IP address on the Internet should ideally have a reverse lookup record in DNS which maps the IP address to a hostname and domain. However, there is no rule to say it has to exist or to say that it has to be the domain by which you SSH'd in or pointed your web browser at.
On any given computer, there are many reasons why the domain name is not what you expect.
Unfortunately this information is not always set correctly. First of all, complain to your system administrator.
If all that fails, with something like the following you may get a field res->ai_canonname with a canonical hostname and then also iterate over all IP addresses:
struct addrinfo *res = NULL;
struct addrinfo hints = {
.ai_family = AF_UNSPEC,
.ai_flags = AI_V4MAPPED | AI_ADDRCONFIG | AI_CANONNAME | (name ? 0 : AI_PASSIVE),
.ai_socktype = SOCK_STREAM,
};
getaddrinfo(name, NULL, &hints, &res);
for (struct addrinfo *p = res; p; p = p->ai_next) {
...
}
You'd then somehow have to select which ones are interesting for you (avoid loopback etc) and try to find a hostname corresponding to one of these IP addresses. But as IP addresses do not necessarily correspond to a valid hostname, this might fail also.
To get the hostname of the computer you are running the program on:
uname
/etc/hostname

Resources