From 28872fdedc8d65efb270bcca8a04739836b1c56d Mon Sep 17 00:00:00 2001 From: Samuel Ortiz Date: Wed, 3 Nov 2010 10:29:05 +0100 Subject: [PATCH] inet: Add peer argument to address modification routine Some point to point interfaces need to specify their peer address. --- src/connman.h | 1 + src/inet.c | 28 +++++++++++++++++++++------- src/ipv4.c | 14 ++++++++++---- 3 files changed, 32 insertions(+), 11 deletions(-) diff --git a/src/connman.h b/src/connman.h index e4bfe51..b487b4d 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 15c0138..9f183ea 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 c73f651..416dab2 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"); } -- 2.7.4