// Allocate an empty address object to be filled out with the attributes // of the new address. struct rtnl_addr *addr = rtnl_addr_alloc(); // Fill out the mandatory attributes of the new address. Setting the // local address will automatically set the address family and the // prefix length to the correct values. rtnl_addr_set_ifindex(addr, ifindex); rtnl_addr_set_local(addr, local_addr); // The label of the address can be specified, currently only supported // by IPv4 and DECnet. rtnl_addr_set_label(addr, "mylabel"); // The peer address can be specified if necessary, in either case a peer // address will be sent to the kernel in order to fullfil the interface // requirements. If none is set, it will equal the local address. // Note: Real peer addresses are only supported by IPv4 for now. rtnl_addr_set_peer(addr, peer_addr); // In case you want to have the address have a scope other than global // it may be overwritten using rtnl_addr_set_scope(). The scope currently // cannot be set for IPv6 addresses. rtnl_addr_set_scope(addr, rtnl_str2scope("site")); // Broadcast and anycast address may be specified using the relevant // functions, the address family will be verified if one of the other // addresses has been set already. Currently only works for IPv4. rtnl_addr_set_broadcast(addr, broadcast_addr); rtnl_addr_set_anycast(addr, anycast_addr); // Build the netlink message and send it to the kernel, the operation will // block until the operation has been completed. Alternatively the required // netlink message can be built using rtnl_addr_build_add_request() to be // sent out using nl_send_auto_complete(). rtnl_addr_add(handle, addr, 0); // Free the memory rtnl_addr_put(addr);
// Allocate an empty address object to be filled out with the attributes // matching the address to be deleted. Alternatively a fully equipped // address object out of a cache can be used instead. struct rtnl_addr *addr = rtnl_addr_alloc(); // The only mandatory parameter besides the address family is the interface // index the address is on, i.e. leaving out all other parameters will // result in all addresses of the specified address family interface tuple // to be deleted. rtnl_addr_set_ifindex(addr, ifindex); // Specyfing the address family manually is only required if neither the // local nor peer address have been specified. rtnl_addr_set_family(addr, AF_INET); // Specyfing the local address is optional but the best choice to delete // specific addresses. rtnl_addr_set_local(addr, local_addr); // The label of the address can be specified, currently only supported // by IPv4 and DECnet. rtnl_addr_set_label(addr, "mylabel"); // The peer address can be specified if necessary, in either case a peer // address will be sent to the kernel in order to fullfil the interface // requirements. If none is set, it will equal the local address. // Note: Real peer addresses are only supported by IPv4 for now. rtnl_addr_set_peer(addr, peer_addr); // Build the netlink message and send it to the kernel, the operation will // block until the operation has been completed. Alternatively the required // netlink message can be built using rtnl_addr_build_delete_request() // to be sent out using nl_send_auto_complete(). rtnl_addr_delete(handle, addr, 0); // Free the memory rtnl_addr_put(addr);
Address Flags Translations | |
| char * | rtnl_addr_flags2str (int flags, char *buf, size_t size) |
| Convert address flags to character string. | |
| int | rtnl_addr_str2flags (const char *name) |
| Convert character string to address flags. | |
Address Object Creation/Deletion | |
| rtnl_addr * | rtnl_addr_alloc (void) |
| Allocate and initialize a new address object. | |
| void | rtnl_addr_put (struct rtnl_addr *addr) |
| Give back a reference on a address object. | |
| void | rtnl_addr_free (struct rtnl_addr *addr) |
| Free an address object. | |
Address Cache Management | |
| nl_cache * | rtnl_addr_alloc_cache (struct nl_handle *handle) |
| Allocate address cache and fill in all configured addresses. | |
Address Addition | |
| nl_msg * | rtnl_addr_build_add_request (struct rtnl_addr *addr, int flags) |
| Build netlink request message to request addition of new address. | |
| int | rtnl_addr_add (struct nl_handle *handle, struct rtnl_addr *addr, int flags) |
| Request addition of new address. | |
Address Deletion | |
| nl_msg * | rtnl_addr_build_delete_request (struct rtnl_addr *addr, int flags) |
| Build a netlink request message to request deletion of an address. | |
| int | rtnl_addr_delete (struct nl_handle *handle, struct rtnl_addr *addr, int flags) |
| Request deletion of an address. | |
Attribute Access | |
| void | rtnl_addr_set_label (struct rtnl_addr *addr, const char *label) |
| Set label of address object. | |
| char * | rtnl_addr_get_label (struct rtnl_addr *addr) |
| Get label of address object. | |
| void | rtnl_addr_set_ifindex (struct rtnl_addr *addr, int ifindex) |
| Set interface index of address object. | |
| int | rtnl_addr_get_ifindex (struct rtnl_addr *addr) |
| Get interface index of address object. | |
| void | rtnl_addr_set_family (struct rtnl_addr *addr, int family) |
| Set address family of address object. | |
| int | rtnl_addr_get_family (struct rtnl_addr *addr) |
| Get address family of address object. | |
| void | rtnl_addr_set_prefixlen (struct rtnl_addr *addr, int prefix) |
| Set prefix length of address object. | |
| int | rtnl_addr_get_prefixlen (struct rtnl_addr *addr) |
| Get prefix length of address object. | |
| void | rtnl_addr_set_scope (struct rtnl_addr *addr, int scope) |
| Set scope of address object. | |
| int | rtnl_addr_get_scope (struct rtnl_addr *addr) |
| Get scope of address object. | |
| void | rtnl_addr_set_flags (struct rtnl_addr *addr, unsigned int flags) |
| Set flags of address object. | |
| void | rtnl_addr_unset_flags (struct rtnl_addr *addr, unsigned int flags) |
| Unset flags of address object. | |
| unsigned int | rtnl_addr_get_flags (struct rtnl_addr *addr) |
| Get flags of address object. | |
| int | rtnl_addr_set_local (struct rtnl_addr *addr, struct nl_addr *local) |
| Set local address of address object. | |
| nl_addr * | rtnl_addr_get_local (struct rtnl_addr *addr) |
| Get local address of address object. | |
| int | rtnl_addr_set_peer (struct rtnl_addr *addr, struct nl_addr *peer) |
| Set peer address of address object. | |
| nl_addr * | rtnl_addr_get_peer (struct rtnl_addr *addr) |
| Get peer address of address object. | |
| int | rtnl_addr_set_broadcast (struct rtnl_addr *addr, struct nl_addr *bcast) |
| Set broadcast address of address object. | |
| nl_addr * | rtnl_addr_get_broadcast (struct rtnl_addr *addr) |
| Get broadcast address of address object. | |
| int | rtnl_addr_set_anycast (struct rtnl_addr *addr, struct nl_addr *anycast) |
| Set anycast address of address object. | |
| nl_addr * | rtnl_addr_get_anycast (struct rtnl_addr *addr) |
| Get anycast address of address object. | |
| int | rtnl_addr_set_multicast (struct rtnl_addr *addr, struct nl_addr *multicast) |
| Set multicast address of address object. | |
| nl_addr * | rtnl_addr_get_multicast (struct rtnl_addr *addr) |
| Get multicast address of address object. | |
| struct rtnl_addr* rtnl_addr_alloc | ( | void | ) |
Allocate and initialize a new address object.
Definition at line 571 of file addr.c.
References nl_object_alloc_from_ops().
| void rtnl_addr_put | ( | struct rtnl_addr * | addr | ) |
Give back a reference on a address object.
| addr | Address object to be given back. |
Definition at line 583 of file addr.c.
References nl_object_put().
| void rtnl_addr_free | ( | struct rtnl_addr * | addr | ) |
Free an address object.
| addr | Address object to be freed. |
Definition at line 595 of file addr.c.
References nl_object_free().
| struct nl_cache* rtnl_addr_alloc_cache | ( | struct nl_handle * | handle | ) |
Allocate address cache and fill in all configured addresses.
| handle | Netlink handle. |
Definition at line 617 of file addr.c.
References nl_cache_alloc_from_ops(), nl_cache_free(), and nl_cache_update().
| struct nl_msg* rtnl_addr_build_add_request | ( | struct rtnl_addr * | addr, | |
| int | flags | |||
| ) |
Build netlink request message to request addition of new address.
| addr | Address object representing the new address. | |
| flags | Additional netlink message flags. |
Minimal required attributes:
The scope will default to universe except for loopback addresses in which case a host scope is used if not specified otherwise.
Definition at line 712 of file addr.c.
References NLM_F_CREATE.
Referenced by rtnl_addr_add().
| int rtnl_addr_add | ( | struct nl_handle * | handle, | |
| struct rtnl_addr * | addr, | |||
| int | flags | |||
| ) |
Request addition of new address.
| handle | Netlink handle. | |
| addr | Address object representing the new address. | |
| flags | Additional netlink message flags. |
Definition at line 740 of file addr.c.
References nl_send_auto_complete(), nl_wait_for_ack(), nlmsg_free(), and rtnl_addr_build_add_request().
| struct nl_msg* rtnl_addr_build_delete_request | ( | struct rtnl_addr * | addr, | |
| int | flags | |||
| ) |
Build a netlink request message to request deletion of an address.
| addr | Address object to be deleteted. | |
| flags | Additional netlink message flags. |
Minimal required attributes:
Optional attributes:
Definition at line 786 of file addr.c.
Referenced by rtnl_addr_delete().
| int rtnl_addr_delete | ( | struct nl_handle * | handle, | |
| struct rtnl_addr * | addr, | |||
| int | flags | |||
| ) |
Request deletion of an address.
| handle | Netlink handle. | |
| addr | Address object to be deleted. | |
| flags | Additional netlink message flags. |
Definition at line 813 of file addr.c.
References nl_send_auto_complete(), nl_wait_for_ack(), nlmsg_free(), and rtnl_addr_build_delete_request().
| void rtnl_addr_set_label | ( | struct rtnl_addr * | addr, | |
| const char * | label | |||
| ) |
| char* rtnl_addr_get_label | ( | struct rtnl_addr * | addr | ) |
| void rtnl_addr_set_ifindex | ( | struct rtnl_addr * | addr, | |
| int | ifindex | |||
| ) |
| int rtnl_addr_get_ifindex | ( | struct rtnl_addr * | addr | ) |
Get interface index of address object.
| addr | Address object. |
Definition at line 880 of file addr.c.
References RTNL_LINK_NOT_FOUND.
| void rtnl_addr_set_family | ( | struct rtnl_addr * | addr, | |
| int | family | |||
| ) |
Set address family of address object.
| addr | Address object to be modified. | |
| family | New address family |
| int rtnl_addr_get_family | ( | struct rtnl_addr * | addr | ) |
| void rtnl_addr_set_prefixlen | ( | struct rtnl_addr * | addr, | |
| int | prefix | |||
| ) |
| int rtnl_addr_get_prefixlen | ( | struct rtnl_addr * | addr | ) |
| void rtnl_addr_set_scope | ( | struct rtnl_addr * | addr, | |
| int | scope | |||
| ) |
| int rtnl_addr_get_scope | ( | struct rtnl_addr * | addr | ) |
| void rtnl_addr_set_flags | ( | struct rtnl_addr * | addr, | |
| unsigned int | flags | |||
| ) |
| void rtnl_addr_unset_flags | ( | struct rtnl_addr * | addr, | |
| unsigned int | flags | |||
| ) |
| unsigned int rtnl_addr_get_flags | ( | struct rtnl_addr * | addr | ) |
| int rtnl_addr_set_local | ( | struct rtnl_addr * | addr, | |
| struct nl_addr * | local | |||
| ) |
Set local address of address object.
| addr | Address object to be modified. | |
| local | New local address. |
Definition at line 1035 of file addr.c.
References nl_addr_get_prefixlen().
| struct nl_addr* rtnl_addr_get_local | ( | struct rtnl_addr * | addr | ) |
| int rtnl_addr_set_peer | ( | struct rtnl_addr * | addr, | |
| struct nl_addr * | peer | |||
| ) |
Set peer address of address object.
| addr | Address object to be modified. | |
| peer | New peer address. |
Definition at line 1078 of file addr.c.
References nl_addr_get_prefixlen().
| struct nl_addr* rtnl_addr_get_peer | ( | struct rtnl_addr * | addr | ) |
| int rtnl_addr_set_broadcast | ( | struct rtnl_addr * | addr, | |
| struct nl_addr * | bcast | |||
| ) |
Set broadcast address of address object.
| addr | Address object to be modified. | |
| bcast | New broadcast address. |
| struct nl_addr* rtnl_addr_get_broadcast | ( | struct rtnl_addr * | addr | ) |
| int rtnl_addr_set_anycast | ( | struct rtnl_addr * | addr, | |
| struct nl_addr * | anycast | |||
| ) |
Set anycast address of address object.
| addr | Address object to be modified. | |
| anycast | New anycast address. |
| struct nl_addr* rtnl_addr_get_anycast | ( | struct rtnl_addr * | addr | ) |
| int rtnl_addr_set_multicast | ( | struct rtnl_addr * | addr, | |
| struct nl_addr * | multicast | |||
| ) |
Set multicast address of address object.
| addr | Address object to be modified. | |
| multicast | New multicast address. |
| struct nl_addr* rtnl_addr_get_multicast | ( | struct rtnl_addr * | addr | ) |
| char* rtnl_addr_flags2str | ( | int | flags, | |
| char * | buf, | |||
| size_t | size | |||
| ) |
Convert address flags to character string.
| flags | Address flags. | |
| buf | Destination buffer. | |
| size | Size of destination buffer. |
| int rtnl_addr_str2flags | ( | const char * | name | ) |
Convert character string to address flags.
| name | Name of address flags. |
1.5.1