RTM_CHGADDRATTR try 2

2018-07-12 Thread Florian Obser
When I sent this around in april it still needed the kernel lock which
made it fuggly... Now the netlock is enough.

Introduce RTM_CHGADDRATTR to inform userland on the route socket when
an attribute of an address is changed.
For now it's used when IPv6 duplicate address detection finishes.

With this slaacd(8) can find out if a configured address is not
duplicated without the need to poll.

OK?

diff --git sbin/route/route.c sbin/route/route.c
index a0ac03c646a..5dff7eec3aa 100644
--- sbin/route/route.c
+++ sbin/route/route.c
@@ -1226,7 +1226,8 @@ char *msgtypes[] = {
"RTM_DESYNC: route socket overflow",
"RTM_INVALIDATE: invalidate cache of L2 route",
"RTM_BFD: bidirectional forwarding detection",
-   "RTM_PROPOSAL: config proposal"
+   "RTM_PROPOSAL: config proposal",
+   "RTM_CHGADDRATTR: address attributes being changed"
 };
 
 char metricnames[] =
@@ -1297,6 +1298,7 @@ print_rtmsg(struct rt_msghdr *rtm, int msglen)
break;
    case RTM_NEWADDR:
case RTM_DELADDR:
+   case RTM_CHGADDRATTR:
ifam = (struct ifa_msghdr *)rtm;
printf(", metric %d, flags:", ifam->ifam_metric);
bprintf(stdout, ifam->ifam_flags, routeflags);
diff --git sys/net/route.h sys/net/route.h
index 43386fa41a6..b6fc1f3aee9 100644
--- sys/net/route.h
+++ sys/net/route.h
@@ -240,6 +240,7 @@ struct rt_msghdr {
 #define RTM_INVALIDATE 0x11/* Invalidate cache of L2 route */
 #define RTM_BFD0x12/* bidirectional forwarding detection */
 #define RTM_PROPOSAL   0x13/* proposal for netconfigd */
+#define RTM_CHGADDRATTR0x14/* address attribute change */
 
 #define RTV_MTU0x1 /* init or lock _mtu */
 #define RTV_HOPCOUNT   0x2 /* init or lock _hopcount */
diff --git sys/netinet6/nd6_nbr.c sys/netinet6/nd6_nbr.c
index d63279a0b8b..2ef3f116e2e 100644
--- sys/netinet6/nd6_nbr.c
+++ sys/netinet6/nd6_nbr.c
@@ -1100,6 +1100,9 @@ nd6_dad_start(struct ifaddr *ifa)
KASSERT(ia6->ia6_flags & IN6_IFF_TENTATIVE);
if ((ia6->ia6_flags & IN6_IFF_ANYCAST) || (!ip6_dad_count)) {
    ia6->ia6_flags &= ~IN6_IFF_TENTATIVE;
+
+   rtm_addr(RTM_CHGADDRATTR, ifa);
+
return;
}
 
@@ -1248,6 +1251,8 @@ nd6_dad_timer(void *xifa)
 */
    ia6->ia6_flags &= ~IN6_IFF_TENTATIVE;
 
+   rtm_addr(RTM_CHGADDRATTR, ifa);
+
nd6log((LOG_DEBUG,
"%s: DAD complete for %s - no duplicates found\n",
ifa->ifa_ifp->if_xname,
@@ -1291,6 +1296,9 @@ nd6_dad_duplicated(struct dadq *dp)
ia6->ia_ifp->if_xname);
 
TAILQ_REMOVE(, dp, dad_list);
+
+   rtm_addr(RTM_CHGADDRATTR, dp->dad_ifa);
+
ifafree(dp->dad_ifa);
free(dp, M_IP6NDP, sizeof(*dp));
ip6_dad_pending--;


-- 
I'm not entirely sure you are real.



Re: RTM_CHGADDRATTR

2018-04-25 Thread Peter Hessler
On 2018 Apr 18 (Wed) at 19:49:41 +0200 (+0200), Florian Obser wrote:
:On Wed, Apr 18, 2018 at 05:05:59PM +0200, Florian Obser wrote:
:> This is to inform userland (i.e. slaacd(8)) when duplicate address
:> detection finishes.
:> 
:> Not a big fan of the lock/unlock dance but I guess it can't be helped
:> for now.
:> 
:> Comments, OKs?
:
:Theo points out that I suck at naming things. I guess we already knew
:that.
:
:How about RTM_CHGADDRATTR, we are changing the attribute of an
:address. Also fixes a tab vs. space in previous.
:

this looks fine, OK


:diff --git net/route.h net/route.h
:index 3c89348cb43..5fa12578e45 100644
:--- net/route.h
:+++ net/route.h
:@@ -241,6 +241,7 @@ struct rt_msghdr {
: #define RTM_INVALIDATE0x11/* Invalidate cache of L2 route */
: #define RTM_BFD   0x12/* bidirectional forwarding detection */
: #define RTM_PROPOSAL  0x13/* proposal for netconfigd */
:+#define RTM_CHGADDRATTR   0x14/* address attribute change */
: 
: #define RTV_MTU   0x1 /* init or lock _mtu */
: #define RTV_HOPCOUNT  0x2 /* init or lock _hopcount */
:diff --git netinet6/nd6_nbr.c netinet6/nd6_nbr.c
:index cb5c04c24ed..ef1644aa6f6 100644
:--- netinet6/nd6_nbr.c
:+++ netinet6/nd6_nbr.c
:@@ -1102,6 +1102,11 @@ nd6_dad_start(struct ifaddr *ifa)
:   KASSERT(ia6->ia6_flags & IN6_IFF_TENTATIVE);
:   if ((ia6->ia6_flags & IN6_IFF_ANYCAST) || (!ip6_dad_count)) {
:   ia6->ia6_flags &= ~IN6_IFF_TENTATIVE;
:+
:+  KERNEL_LOCK();
:+  rtm_addr(RTM_CHGADDRATTR, ifa);
:+  KERNEL_UNLOCK();
:+
:   return;
:   }
: 
:@@ -1250,6 +1255,10 @@ nd6_dad_timer(void *xifa)
:*/
:   ia6->ia6_flags &= ~IN6_IFF_TENTATIVE;
: 
:+  KERNEL_LOCK();
:+  rtm_addr(RTM_CHGADDRATTR, ifa);
:+  KERNEL_UNLOCK();
:+
:   nd6log((LOG_DEBUG,
:   "%s: DAD complete for %s - no duplicates found\n",
:   ifa->ifa_ifp->if_xname,
:@@ -1293,6 +1302,11 @@ nd6_dad_duplicated(struct dadq *dp)
:   ia6->ia_ifp->if_xname);
: 
:   TAILQ_REMOVE(, dp, dad_list);
:+
:+  KERNEL_LOCK();
:+  rtm_addr(RTM_CHGADDRATTR, dp->dad_ifa);
:+  KERNEL_UNLOCK();
:+
:   ifafree(dp->dad_ifa);
:   free(dp, M_IP6NDP, sizeof(*dp));
:   ip6_dad_pending--;
:
:
:
:-- 
:I'm not entirely sure you are real.
:

-- 
Worst Vegetable of the Year:
The brussels sprout.  This is also the worst vegetable of next
year.
-- Steve Rubenstein



Re: RTM_CHGADDRATTR

2018-04-25 Thread Florian Obser
anyone? should slaacd just poll?

On Wed, Apr 18, 2018 at 07:49:41PM +0200, Florian Obser wrote:
> On Wed, Apr 18, 2018 at 05:05:59PM +0200, Florian Obser wrote:
> > This is to inform userland (i.e. slaacd(8)) when duplicate address
> > detection finishes.
> > 
> > Not a big fan of the lock/unlock dance but I guess it can't be helped
> > for now.
> > 
> > Comments, OKs?
> 
> Theo points out that I suck at naming things. I guess we already knew
> that.
> 
> How about RTM_CHGADDRATTR, we are changing the attribute of an
> address. Also fixes a tab vs. space in previous.
> 
> diff --git net/route.h net/route.h
> index 3c89348cb43..5fa12578e45 100644
> --- net/route.h
> +++ net/route.h
> @@ -241,6 +241,7 @@ struct rt_msghdr {
>  #define RTM_INVALIDATE   0x11/* Invalidate cache of L2 route */
>  #define RTM_BFD  0x12/* bidirectional forwarding detection */
>  #define RTM_PROPOSAL 0x13/* proposal for netconfigd */
> +#define RTM_CHGADDRATTR  0x14/* address attribute change */
>  
>  #define RTV_MTU  0x1 /* init or lock _mtu */
>  #define RTV_HOPCOUNT 0x2 /* init or lock _hopcount */
> diff --git netinet6/nd6_nbr.c netinet6/nd6_nbr.c
> index cb5c04c24ed..ef1644aa6f6 100644
> --- netinet6/nd6_nbr.c
> +++ netinet6/nd6_nbr.c
> @@ -1102,6 +1102,11 @@ nd6_dad_start(struct ifaddr *ifa)
>   KASSERT(ia6->ia6_flags & IN6_IFF_TENTATIVE);
>   if ((ia6->ia6_flags & IN6_IFF_ANYCAST) || (!ip6_dad_count)) {
>   ia6->ia6_flags &= ~IN6_IFF_TENTATIVE;
> +
> + KERNEL_LOCK();
> + rtm_addr(RTM_CHGADDRATTR, ifa);
> + KERNEL_UNLOCK();
> +
>   return;
>   }
>  
> @@ -1250,6 +1255,10 @@ nd6_dad_timer(void *xifa)
>    */
>   ia6->ia6_flags &= ~IN6_IFF_TENTATIVE;
>  
> + KERNEL_LOCK();
> + rtm_addr(RTM_CHGADDRATTR, ifa);
> + KERNEL_UNLOCK();
> +
>   nd6log((LOG_DEBUG,
>   "%s: DAD complete for %s - no duplicates found\n",
>   ifa->ifa_ifp->if_xname,
> @@ -1293,6 +1302,11 @@ nd6_dad_duplicated(struct dadq *dp)
>   ia6->ia_ifp->if_xname);
>  
>   TAILQ_REMOVE(, dp, dad_list);
> +
> + KERNEL_LOCK();
> + rtm_addr(RTM_CHGADDRATTR, dp->dad_ifa);
> + KERNEL_UNLOCK();
> +
>   ifafree(dp->dad_ifa);
>   free(dp, M_IP6NDP, sizeof(*dp));
>   ip6_dad_pending--;
> 
> 
> 
> -- 
> I'm not entirely sure you are real.
> 

-- 
I'm not entirely sure you are real.



RTM_CHGADDRATTR: route(8)

2018-04-18 Thread Florian Obser
diff --git route.c route.c
index 9c85f70de78..a9ee414c562 100644
--- route.c
+++ route.c
@@ -1257,7 +1257,8 @@ char *msgtypes[] = {
"RTM_DESYNC: route socket overflow",
"RTM_INVALIDATE: invalidate cache of L2 route",
"RTM_BFD: bidirectional forwarding detection",
-   "RTM_PROPOSAL: config proposal"
+   "RTM_PROPOSAL: config proposal",
+   "RTM_CHGADDRATTR: address attributes being changed"
 };
 
 char metricnames[] =
@@ -1328,6 +1329,7 @@ print_rtmsg(struct rt_msghdr *rtm, int msglen)
break;
    case RTM_NEWADDR:
case RTM_DELADDR:
+   case RTM_CHGADDRATTR:
ifam = (struct ifa_msghdr *)rtm;
printf(", metric %d, flags:", ifam->ifam_metric);
bprintf(stdout, ifam->ifam_flags, routeflags);

-- 
I'm not entirely sure you are real.



RTM_CHGADDRATTR

2018-04-18 Thread Florian Obser
On Wed, Apr 18, 2018 at 05:05:59PM +0200, Florian Obser wrote:
> This is to inform userland (i.e. slaacd(8)) when duplicate address
> detection finishes.
> 
> Not a big fan of the lock/unlock dance but I guess it can't be helped
> for now.
> 
> Comments, OKs?

Theo points out that I suck at naming things. I guess we already knew
that.

How about RTM_CHGADDRATTR, we are changing the attribute of an
address. Also fixes a tab vs. space in previous.

diff --git net/route.h net/route.h
index 3c89348cb43..5fa12578e45 100644
--- net/route.h
+++ net/route.h
@@ -241,6 +241,7 @@ struct rt_msghdr {
 #define RTM_INVALIDATE 0x11/* Invalidate cache of L2 route */
 #define RTM_BFD0x12/* bidirectional forwarding detection */
 #define RTM_PROPOSAL   0x13/* proposal for netconfigd */
+#define RTM_CHGADDRATTR0x14/* address attribute change */
 
 #define RTV_MTU0x1 /* init or lock _mtu */
 #define RTV_HOPCOUNT   0x2 /* init or lock _hopcount */
diff --git netinet6/nd6_nbr.c netinet6/nd6_nbr.c
index cb5c04c24ed..ef1644aa6f6 100644
--- netinet6/nd6_nbr.c
+++ netinet6/nd6_nbr.c
@@ -1102,6 +1102,11 @@ nd6_dad_start(struct ifaddr *ifa)
KASSERT(ia6->ia6_flags & IN6_IFF_TENTATIVE);
if ((ia6->ia6_flags & IN6_IFF_ANYCAST) || (!ip6_dad_count)) {
ia6->ia6_flags &= ~IN6_IFF_TENTATIVE;
+
+   KERNEL_LOCK();
+   rtm_addr(RTM_CHGADDRATTR, ifa);
+   KERNEL_UNLOCK();
+
return;
}
 
@@ -1250,6 +1255,10 @@ nd6_dad_timer(void *xifa)
 */
ia6->ia6_flags &= ~IN6_IFF_TENTATIVE;
 
+   KERNEL_LOCK();
+   rtm_addr(RTM_CHGADDRATTR, ifa);
+   KERNEL_UNLOCK();
+
nd6log((LOG_DEBUG,
"%s: DAD complete for %s - no duplicates found\n",
ifa->ifa_ifp->if_xname,
@@ -1293,6 +1302,11 @@ nd6_dad_duplicated(struct dadq *dp)
ia6->ia_ifp->if_xname);
 
TAILQ_REMOVE(, dp, dad_list);
+
+   KERNEL_LOCK();
+   rtm_addr(RTM_CHGADDRATTR, dp->dad_ifa);
+   KERNEL_UNLOCK();
+
ifafree(dp->dad_ifa);
free(dp, M_IP6NDP, sizeof(*dp));
ip6_dad_pending--;



-- 
I'm not entirely sure you are real.