Multipath routing via netlink

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Dear kernelnewbies list,

I already posted this to linux-net last week but didn't get a response,
so I'll try here. Those who get it twice, sorry for bothering.

I'm currently implementing a multipath routing protocol based on an
existing project which is implemented partly in user-space and party as
a kernel module (aodv-uu). Netlink is used to manage routes.

If I understand this right, I have to set the RTA_MULTIPATH attribute
for the RTM_NEWROUTE message. However, no matter what I try, I can't
seem to get the arguments right (I keep getting "Invalid argument"
errors).

Here's the code I'm working with:


/* Function to add, remove and update entries in the kernel routing
 * table */
int nl_kern_route(int action, int flags, int family,
		  int index, struct in_addr *dst, struct in_addr *gw,
		  struct in_addr *nm, int metric)
{
	struct {
		struct nlmsghdr nlh;
		struct rtmsg rtm;
		char attrbuf[1024];
	} req;

	if (!dst || !gw)
		return -1;

	req.nlh.nlmsg_len = NLMSG_LENGTH(sizeof(struct rtmsg));
	req.nlh.nlmsg_type = action;
	req.nlh.nlmsg_flags = NLM_F_REQUEST | flags;
	req.nlh.nlmsg_pid = 0;

	req.rtm.rtm_family = family;

	if (!nm)
		req.rtm.rtm_dst_len = sizeof(struct in_addr) * 8;
	else
		req.rtm.rtm_dst_len = prefix_length(AF_INET, nm);

	req.rtm.rtm_src_len = 0;
	req.rtm.rtm_tos = 0;
	req.rtm.rtm_table = RT_TABLE_MAIN;
	req.rtm.rtm_protocol = 100;
	req.rtm.rtm_scope = RT_SCOPE_LINK;
	req.rtm.rtm_type = RTN_UNICAST;
	req.rtm.rtm_flags = 0;

	addattr(&req.nlh, RTA_DST, dst, sizeof(struct in_addr));

	if (memcmp(dst, gw, sizeof(struct in_addr)) != 0) {
		req.rtm.rtm_scope = RT_SCOPE_UNIVERSE;
		addattr(&req.nlh, RTA_GATEWAY, gw, sizeof(struct in_addr));
	}

	if (index > 0)
		addattr(&req.nlh, RTA_OIF, &index, sizeof(index));

	addattr(&req.nlh, RTA_PRIORITY, &metric, sizeof(metric));

	return nl_send(&rtnl, &req.nlh);
}

with

/* Utility function  comes from iproute2. 
   Authors:	Alexey Kuznetsov, <kuznet@xxxxxxxxxxxxx> */
int addattr(struct nlmsghdr *n, int type, void *data, int alen)
{
	struct rtattr *attr;
	int len = RTA_LENGTH(alen);

	attr = (struct rtattr *) (((char *) n) + NLMSG_ALIGN(n->nlmsg_len));
	attr->rta_type = type;
	attr->rta_len = len;
	memcpy(RTA_DATA(attr), data, alen);
	n->nlmsg_len = NLMSG_ALIGN(n->nlmsg_len) + len;

	return 0;
}

What I tried so far is adding addattr(&rel.nlh, RTA_MULTIPATH, ...)
right below the addattr(&req.nlh, RTA_GATEWAY, ...) line.

Could anyone maybe give me a hint on what I might be doing wrong in
general and/or, more precisely, what arguments I have to pass with
RTA_MULTIPATH?

Also, as I would like to define the multipath arlogithm to be used, I
saw that there is an attribute RTA_MP_ALGO. How do I use that one?

Btw, I'm using kernel 2.6.17.14 as the netlink API changed in 2.6.18 and
I don't feel like rewriting the whole netlink part unless absolutely
neccessary.

Thanks
-- 
Stefan Ott
http://www.desire.ch/

Attachment: signature.asc
Description: Digital signature


[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux