summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSamuel Ortiz <sameo@linux.intel.com>2010-11-03 10:29:05 +0100
committerSamuel Ortiz <sameo@linux.intel.com>2010-11-03 10:29:05 +0100
commit28872fdedc8d65efb270bcca8a04739836b1c56d (patch)
treee4844329f6b4adc720c89c96ae7c7123ca8344ae
parent100025e2a97191de322dbfd95d73849a4ee2aaa1 (diff)
downloadconnman-28872fdedc8d65efb270bcca8a04739836b1c56d.tar.gz
connman-28872fdedc8d65efb270bcca8a04739836b1c56d.tar.bz2
connman-28872fdedc8d65efb270bcca8a04739836b1c56d.zip
inet: Add peer argument to address modification routine
Some point to point interfaces need to specify their peer address.
-rw-r--r--src/connman.h1
-rw-r--r--src/inet.c28
-rw-r--r--src/ipv4.c14
3 files changed, 32 insertions, 11 deletions
diff --git a/src/connman.h b/src/connman.h
index e4bfe516..b487b4d8 100644
--- a/src/connman.h
+++ b/src/connman.h
@@ -107,6 +107,7 @@ void __connman_task_cleanup(void);
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);
diff --git a/src/inet.c b/src/inet.c
index 15c0138c..9f183ea1 100644
--- a/src/inet.c
+++ b/src/inet.c
@@ -66,18 +66,20 @@ static int add_rtattr(struct nlmsghdr *n, size_t max_length, int type,
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("");
@@ -113,6 +115,16 @@ int __connman_inet_modify_address(int cmd, int flags,
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;
@@ -542,7 +554,7 @@ int connman_inet_set_ipv6_address(int index,
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;
}
@@ -553,7 +565,7 @@ int connman_inet_set_ipv6_address(int index,
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;
@@ -561,12 +573,13 @@ int connman_inet_set_address(int index, struct connman_ipaddress *ipaddress)
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;
}
@@ -580,7 +593,7 @@ int connman_inet_clear_ipv6_address(int index, const char *address,
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;
}
@@ -591,16 +604,17 @@ int connman_inet_clear_ipv6_address(int index, const char *address,
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;
}
diff --git a/src/ipv4.c b/src/ipv4.c
index c73f6518..416dab26 100644
--- a/src/ipv4.c
+++ b/src/ipv4.c
@@ -67,7 +67,7 @@ static int ipv4_probe(struct connman_element *element)
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;
@@ -78,6 +78,8 @@ static int ipv4_probe(struct connman_element *element)
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);
@@ -87,6 +89,7 @@ static int ipv4_probe(struct connman_element *element)
CONNMAN_PROPERTY_ID_IPV4_PAC, &pac);
DBG("address %s", address);
+ DBG("peer %s", peer);
DBG("netmask %s", netmask);
DBG("broadcast %s", broadcast);
@@ -97,7 +100,7 @@ static int ipv4_probe(struct connman_element *element)
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);
@@ -130,7 +133,7 @@ static int ipv4_probe(struct connman_element *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;
@@ -142,6 +145,8 @@ static void ipv4_remove(struct connman_element *element)
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);
@@ -151,6 +156,7 @@ static void ipv4_remove(struct connman_element *element)
connman_timeserver_remove(timeserver);
DBG("address %s", address);
+ DBG("peer %s", peer);
DBG("netmask %s", netmask);
DBG("broadcast %s", broadcast);
@@ -164,7 +170,7 @@ static void ipv4_remove(struct connman_element *element)
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");
}