@@ -10,6 +10,7 @@ LOG_MODULE_REGISTER(net_if, CONFIG_NET_IF_LOG_LEVEL);
1010#include <init.h>
1111#include <kernel.h>
1212#include <linker/sections.h>
13+ #include <syscall_handler.h>
1314#include <stdlib.h>
1415#include <string.h>
1516#include <net/net_core.h>
@@ -751,6 +752,30 @@ struct net_if_addr *net_if_ipv6_addr_lookup_by_iface(struct net_if *iface,
751752 return NULL ;
752753}
753754
755+ int z_impl_net_if_ipv6_addr_lookup_by_index (const struct in6_addr * addr )
756+ {
757+ struct net_if * iface = NULL ;
758+ struct net_if_addr * if_addr ;
759+
760+ if_addr = net_if_ipv6_addr_lookup (addr , & iface );
761+ if (!if_addr ) {
762+ return 0 ;
763+ }
764+
765+ return net_if_get_by_iface (iface );
766+ }
767+
768+ #ifdef CONFIG_USERSPACE
769+ Z_SYSCALL_HANDLER (net_if_ipv6_addr_lookup_by_index , addr )
770+ {
771+ struct in6_addr addr_v6 ;
772+
773+ Z_OOPS (z_user_from_copy (& addr_v6 , (void * )addr , sizeof (addr_v6 )));
774+
775+ return z_impl_net_if_ipv6_addr_lookup_by_index (& addr_v6 );
776+ }
777+ #endif
778+
754779#if defined(CONFIG_NET_IPV6 )
755780static bool check_timeout (u32_t start , s32_t timeout , u32_t counter ,
756781 u32_t current_time )
@@ -1087,6 +1112,69 @@ bool net_if_ipv6_addr_rm(struct net_if *iface, const struct in6_addr *addr)
10871112 return false;
10881113}
10891114
1115+ bool z_impl_net_if_ipv6_addr_add_by_index (int index ,
1116+ struct in6_addr * addr ,
1117+ enum net_addr_type addr_type ,
1118+ u32_t vlifetime )
1119+ {
1120+ struct net_if * iface ;
1121+
1122+ iface = net_if_get_by_index (index );
1123+ if (!iface ) {
1124+ return false;
1125+ }
1126+
1127+ return net_if_ipv6_addr_add (iface , addr , addr_type , vlifetime ) ?
1128+ true : false;
1129+ }
1130+
1131+ #ifdef CONFIG_USERSPACE
1132+ Z_SYSCALL_HANDLER (net_if_ipv6_addr_add_by_index , index , addr , addr_type ,
1133+ vlifetime )
1134+ {
1135+ #if defined(CONFIG_NET_IF_USERSPACE_ACCESS )
1136+ struct in6_addr addr_v6 ;
1137+
1138+ Z_OOPS (z_user_from_copy (& addr_v6 , (void * )addr , sizeof (addr_v6 )));
1139+
1140+ return z_impl_net_if_ipv6_addr_add_by_index (index ,
1141+ & addr_v6 ,
1142+ addr_type ,
1143+ vlifetime );
1144+ #else
1145+ return false;
1146+ #endif /* CONFIG_NET_IF_USERSPACE_ACCESS */
1147+ }
1148+ #endif /* CONFIG_USERSPACE */
1149+
1150+ bool z_impl_net_if_ipv6_addr_rm_by_index (int index ,
1151+ const struct in6_addr * addr )
1152+ {
1153+ struct net_if * iface ;
1154+
1155+ iface = net_if_get_by_index (index );
1156+ if (!iface ) {
1157+ return false;
1158+ }
1159+
1160+ return net_if_ipv6_addr_rm (iface , addr );
1161+ }
1162+
1163+ #ifdef CONFIG_USERSPACE
1164+ Z_SYSCALL_HANDLER (net_if_ipv6_addr_rm_by_index , index , addr )
1165+ {
1166+ #if defined(CONFIG_NET_IF_USERSPACE_ACCESS )
1167+ struct in6_addr addr_v6 ;
1168+
1169+ Z_OOPS (z_user_from_copy (& addr_v6 , (void * )addr , sizeof (addr_v6 )));
1170+
1171+ return z_impl_net_if_ipv6_addr_rm_by_index (index , & addr_v6 );
1172+ #else
1173+ return false;
1174+ #endif /* CONFIG_NET_IF_USERSPACE_ACCESS */
1175+ }
1176+ #endif /* CONFIG_USERSPACE */
1177+
10901178struct net_if_mcast_addr * net_if_ipv6_maddr_add (struct net_if * iface ,
10911179 const struct in6_addr * addr )
10921180{
@@ -2485,6 +2573,30 @@ struct net_if_addr *net_if_ipv4_addr_lookup(const struct in_addr *addr,
24852573 return NULL ;
24862574}
24872575
2576+ int z_impl_net_if_ipv4_addr_lookup_by_index (const struct in_addr * addr )
2577+ {
2578+ struct net_if_addr * if_addr ;
2579+ struct net_if * iface = NULL ;
2580+
2581+ if_addr = net_if_ipv4_addr_lookup (addr , & iface );
2582+ if (!if_addr ) {
2583+ return 0 ;
2584+ }
2585+
2586+ return net_if_get_by_iface (iface );
2587+ }
2588+
2589+ #ifdef CONFIG_USERSPACE
2590+ Z_SYSCALL_HANDLER (net_if_ipv4_addr_lookup_by_index , addr )
2591+ {
2592+ struct in_addr addr_v4 ;
2593+
2594+ Z_OOPS (z_user_from_copy (& addr_v4 , (void * )addr , sizeof (addr_v4 )));
2595+
2596+ return z_impl_net_if_ipv4_addr_lookup_by_index (& addr_v4 );
2597+ }
2598+ #endif
2599+
24882600#if defined(CONFIG_NET_IPV4 )
24892601static struct net_if_addr * ipv4_addr_find (struct net_if * iface ,
24902602 struct in_addr * addr )
@@ -2609,6 +2721,70 @@ bool net_if_ipv4_addr_rm(struct net_if *iface, struct in_addr *addr)
26092721 return false;
26102722}
26112723
2724+ bool z_impl_net_if_ipv4_addr_add_by_index (int index ,
2725+ struct in_addr * addr ,
2726+ enum net_addr_type addr_type ,
2727+ u32_t vlifetime )
2728+ {
2729+ struct net_if * iface ;
2730+ struct net_if_addr * if_addr ;
2731+
2732+ iface = net_if_get_by_index (index );
2733+ if (!iface ) {
2734+ return false;
2735+ }
2736+
2737+ if_addr = net_if_ipv4_addr_add (iface , addr , addr_type , vlifetime );
2738+ return if_addr ? true : false;
2739+ }
2740+
2741+ #ifdef CONFIG_USERSPACE
2742+ Z_SYSCALL_HANDLER (net_if_ipv4_addr_add_by_index , index , addr , addr_type ,
2743+ vlifetime )
2744+ {
2745+ #if defined(CONFIG_NET_IF_USERSPACE_ACCESS )
2746+ struct in_addr addr_v4 ;
2747+
2748+ Z_OOPS (z_user_from_copy (& addr_v4 , (void * )addr , sizeof (addr_v4 )));
2749+
2750+ return z_impl_net_if_ipv4_addr_add_by_index (index ,
2751+ & addr_v4 ,
2752+ addr_type ,
2753+ vlifetime );
2754+ #else
2755+ return false;
2756+ #endif /* CONFIG_NET_IF_USERSPACE_ACCESS */
2757+ }
2758+ #endif /* CONFIG_USERSPACE */
2759+
2760+ bool z_impl_net_if_ipv4_addr_rm_by_index (int index ,
2761+ const struct in_addr * addr )
2762+ {
2763+ struct net_if * iface ;
2764+
2765+ iface = net_if_get_by_index (index );
2766+ if (!iface ) {
2767+ return false;
2768+ }
2769+
2770+ return net_if_ipv4_addr_rm (iface , addr );
2771+ }
2772+
2773+ #ifdef CONFIG_USERSPACE
2774+ Z_SYSCALL_HANDLER (net_if_ipv4_addr_rm_by_index , index , addr )
2775+ {
2776+ #if defined(CONFIG_NET_IF_USERSPACE_ACCESS )
2777+ struct in_addr addr_v4 ;
2778+
2779+ Z_OOPS (z_user_from_copy (& addr_v4 , (void * )addr , sizeof (addr_v4 )));
2780+
2781+ return (uint32_t )z_impl_net_if_ipv4_addr_rm_by_index (index , & addr_v4 );
2782+ #else
2783+ return false;
2784+ #endif /* CONFIG_NET_IF_USERSPACE_ACCESS */
2785+ }
2786+ #endif /* CONFIG_USERSPACE */
2787+
26122788#if defined(CONFIG_NET_IPV4 )
26132789static struct net_if_mcast_addr * ipv4_maddr_find (struct net_if * iface ,
26142790 bool is_used ,
0 commit comments