int __connman_inet_modify_address(int cmd, int flags,
int index, int family,
const char *address,
+ const char *peer,
unsigned char prefixlen,
const char *broadcast)
{
uint8_t request[NLMSG_ALIGN(sizeof(struct nlmsghdr)) +
NLMSG_ALIGN(sizeof(struct ifaddrmsg)) +
+ RTA_LENGTH(sizeof(struct in6_addr)) +
RTA_LENGTH(sizeof(struct in6_addr))];
struct nlmsghdr *header;
struct sockaddr_nl nl_addr;
struct ifaddrmsg *ifaddrmsg;
struct in6_addr ipv6_addr;
- struct in_addr ipv4_addr, ipv4_bcast;
+ struct in_addr ipv4_addr, ipv4_dest, ipv4_bcast;
int sk, err;
DBG("");
ipv4_bcast.s_addr = ipv4_addr.s_addr |
htonl(0xfffffffflu >> prefixlen);
+ if (peer != NULL) {
+ if (inet_pton(AF_INET, peer, &ipv4_dest) < 1)
+ return -1;
+
+ if ((err = add_rtattr(header, sizeof(request),
+ IFA_ADDRESS,
+ &ipv4_dest, sizeof(ipv4_dest))) < 0)
+ return err;
+ }
+
if ((err = add_rtattr(header, sizeof(request), IFA_LOCAL,
&ipv4_addr, sizeof(ipv4_addr))) < 0)
return err;
if ((__connman_inet_modify_address(RTM_NEWADDR,
NLM_F_REPLACE | NLM_F_ACK, index, AF_INET6,
- address, prefix_len, NULL)) < 0) {
+ address, NULL, prefix_len, NULL)) < 0) {
connman_error("Set IPv6 address error");
return -1;
}
int connman_inet_set_address(int index, struct connman_ipaddress *ipaddress)
{
unsigned char prefix_len;
- const char *address, *broadcast;
+ const char *address, *broadcast, *peer;
if (ipaddress->local == NULL)
return -1;
prefix_len = ipaddress->prefixlen;
address = ipaddress->local;
broadcast = ipaddress->broadcast;
+ peer = ipaddress->peer;
DBG("index %d address %s prefix_len %d", index, address, prefix_len);
if ((__connman_inet_modify_address(RTM_NEWADDR,
NLM_F_REPLACE | NLM_F_ACK, index, AF_INET,
- address, prefix_len, broadcast)) < 0) {
+ address, peer, prefix_len, broadcast)) < 0) {
DBG("address setting failed");
return -1;
}
DBG("index %d address %s prefix_len %d", index, address, prefix_len);
if ((__connman_inet_modify_address(RTM_DELADDR, 0, index, AF_INET6,
- address, prefix_len, NULL)) < 0) {
+ address, NULL, prefix_len, NULL)) < 0) {
connman_error("Clear IPv6 address error");
return -1;
}
int connman_inet_clear_address(int index, struct connman_ipaddress *ipaddress)
{
unsigned char prefix_len;
- const char *address, *broadcast;
+ const char *address, *broadcast, *peer;
prefix_len = ipaddress->prefixlen;
address = ipaddress->local;
broadcast = ipaddress->broadcast;
+ peer = ipaddress->peer;
DBG("index %d address %s prefix_len %d", index, address, prefix_len);
if ((__connman_inet_modify_address(RTM_DELADDR, 0, index, AF_INET,
- address, prefix_len, broadcast)) < 0) {
+ address, peer, prefix_len, broadcast)) < 0) {
DBG("address removal failed");
return -1;
}
struct connman_ipconfig *ipconfig;
struct connman_element *connection;
const char *address = NULL, *netmask = NULL, *broadcast = NULL;
- const char *nameserver = NULL, *pac = NULL;
+ const char *peer = NULL, *nameserver = NULL, *pac = NULL;
char *timeserver = NULL;
unsigned char prefixlen;
CONNMAN_PROPERTY_ID_IPV4_NETMASK, &netmask);
connman_element_get_value(element,
CONNMAN_PROPERTY_ID_IPV4_BROADCAST, &broadcast);
+ connman_element_get_value(element,
+ CONNMAN_PROPERTY_ID_IPV4_PEER, &peer);
connman_element_get_value(element,
CONNMAN_PROPERTY_ID_IPV4_NAMESERVER, &nameserver);
CONNMAN_PROPERTY_ID_IPV4_PAC, &pac);
DBG("address %s", address);
+ DBG("peer %s", peer);
DBG("netmask %s", netmask);
DBG("broadcast %s", broadcast);
if ((__connman_inet_modify_address(RTM_NEWADDR,
NLM_F_REPLACE | NLM_F_ACK, element->index,
- AF_INET, address, prefixlen, broadcast)) < 0)
+ AF_INET, address, peer, prefixlen, broadcast)) < 0)
DBG("address setting failed");
service = __connman_element_get_service(element);
static void ipv4_remove(struct connman_element *element)
{
const char *address = NULL, *netmask = NULL, *broadcast = NULL;
- const char *nameserver = NULL;
+ const char *peer = NULL, *nameserver = NULL;
char *timeserver = NULL;
unsigned char prefixlen;
CONNMAN_PROPERTY_ID_IPV4_NETMASK, &netmask);
connman_element_get_value(element,
CONNMAN_PROPERTY_ID_IPV4_BROADCAST, &broadcast);
+ connman_element_get_value(element,
+ CONNMAN_PROPERTY_ID_IPV4_PEER, &peer);
connman_element_get_value(element,
CONNMAN_PROPERTY_ID_IPV4_NAMESERVER, &nameserver);
connman_timeserver_remove(timeserver);
DBG("address %s", address);
+ DBG("peer %s", peer);
DBG("netmask %s", netmask);
DBG("broadcast %s", broadcast);
prefixlen = __connman_ipconfig_netmask_prefix_len(netmask);
if ((__connman_inet_modify_address(RTM_DELADDR, 0, element->index,
- AF_INET, address, prefixlen, broadcast) < 0))
+ AF_INET, address, peer, prefixlen, broadcast) < 0))
DBG("address removal failed");
}