Rename rt_ifa_addloop(9)

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Rename rt_ifa_addloop(9)

Martin Pieuchot-2
When I decided to use in6_ifaddloop() for IPv4 I barely though about
the name of the function.  Recently mikeb@ told me that the name is
confusing, especially because I'm trying to turn the "loopback hack"
into "local routes".

So here's a diff to rename these functions and to make them return
the error code of rtrequest9(9), ignored for the moment.

Ok?

Index: share/man/man9/Makefile
===================================================================
RCS file: /home/ncvs/src/share/man/man9/Makefile,v
retrieving revision 1.222
diff -u -p -r1.222 Makefile
--- share/man/man9/Makefile 4 Nov 2014 23:27:02 -0000 1.222
+++ share/man/man9/Makefile 20 Nov 2014 14:28:48 -0000
@@ -325,8 +325,8 @@ MLINKS+=rssadapt.9 ieee80211_rssadapt_ch
  rssadapt.9 ieee80211_rssadapt_updatestats.9
 MLINKS+=route.9 rt_lookup.9 \
  route.9 rt_setgate.9 route.9 rtredirect.9 route.9 rtdeletemsg.9
-MLINKS+=rt_ifa_add.9 rt_ifa_del.9 rt_ifa_add.9 rt_ifa_addloop.9 \
- rt_ifa_add.9 rt_ifa_delloop.9
+MLINKS+=rt_ifa_add.9 rt_ifa_del.9 rt_ifa_add.9 rt_ifa_addlocal.9 \
+ rt_ifa_add.9 rt_ifa_dellocal.9
 MLINKS+=rt_timer_add.9 rt_timer_queue_create.9 \
  rt_timer_add.9 rt_timer_queue_count.9 \
  rt_timer_add.9 rt_timer_queue_change.9 \
Index: share/man/man9/rt_ifa_add.9
===================================================================
RCS file: /home/ncvs/src/share/man/man9/rt_ifa_add.9,v
retrieving revision 1.3
diff -u -p -r1.3 rt_ifa_add.9
--- share/man/man9/rt_ifa_add.9 15 Oct 2014 11:58:13 -0000 1.3
+++ share/man/man9/rt_ifa_add.9 20 Nov 2014 14:28:48 -0000
@@ -20,8 +20,8 @@
 .Sh NAME
 .Nm rt_ifa_add ,
 .Nm rt_ifa_del ,
-.Nm rt_ifa_addloop ,
-.Nm rt_ifa_delloop
+.Nm rt_ifa_addlocal ,
+.Nm rt_ifa_dellocal
 .Nd add or delete routing entries associated with an address
 .Sh SYNOPSIS
 .In sys/types.h
@@ -32,14 +32,14 @@
 .Fn rt_ifa_add "struct ifaddr *ifa" "int flags" "struct sockaddr *dst"
 .Ft int
 .Fn rt_ifa_del "struct ifaddr *ifa" "int flags" "struct sockaddr *dst"
-.Ft void
-.Fn rt_ifa_addloop "struct ifaddr *ifa"
-.Ft void
-.Fn rt_ifa_delloop "struct ifaddr *ifa"
+.Ft int
+.Fn rt_ifa_addlocal "struct ifaddr *ifa"
+.Ft int
+.Fn rt_ifa_dellocal "struct ifaddr *ifa"
 .Sh DESCRIPTION
 These functions create and delete routing entries required by the network
 stack and managed by the kernel.
-.Bl -tag -width rt_ifa_addloopxx
+.Bl -tag -width rt_ifa_addlocalxx
 .It Fn rt_ifa_add
 Creates and associates a connected routing entry with
 .Fa ifa .
@@ -66,7 +66,7 @@ Connected routing entries have a priorit
 .It Fn rt_ifa_del
 Removes the connected routing entry associated with
 .Fa ifa .
-.It Fn rt_ifa_addloop
+.It Fn rt_ifa_addlocal
 Creates and associates a local routing entry
 with
 .Fa ifa .
@@ -79,21 +79,23 @@ They have the lowest priority available,
 and contain a special flag,
 .Dv RTF_LOCAL ,
 that can be checked to determine if the address is configured on the system.
-.It Fn rt_ifa_delloop
+.It Fn rt_ifa_dellocal
 Removes the local routing entry associated with
 .Fa ifa .
 .El
 .Sh CONTEXT
 .Fn rt_ifa_add ,
 .Fn rt_ifa_del ,
-.Fn rt_ifa_addloop ,
+.Fn rt_ifa_addlocal ,
 and
-.Fn rt_ifa_delloop
+.Fn rt_ifa_dellocal
 can be called during autoconf, from process context, or from interrupt context.
 .Sh RETURN VALUES
-.Fn rt_ifa_add
+.Fn rt_ifa_add ,
+.Fn rt_ifa_del ,
+.Fn rt_ifa_addlocal ,
 and
-.Fn rt_ifa_del
+.Fn rt_ifa_dellocal
 will return
 .Dv 0
 on success and the return value of
Index: sys/net/route.c
===================================================================
RCS file: /home/ncvs/src/sys/net/route.c,v
retrieving revision 1.190
diff -u -p -r1.190 route.c
--- sys/net/route.c 10 Nov 2014 10:38:46 -0000 1.190
+++ sys/net/route.c 20 Nov 2014 14:28:48 -0000
@@ -1182,13 +1182,14 @@ rt_ifa_del(struct ifaddr *ifa, int flags
 }
 
 /*
- * Add ifa's address as a loopback rtentry.
+ * Add ifa's address as a local rtentry.
  */
-void
-rt_ifa_addloop(struct ifaddr *ifa)
+int
+rt_ifa_addlocal(struct ifaddr *ifa)
 {
  struct rtentry *rt;
  u_int flags = RTF_HOST|RTF_LOCAL;
+ int error = 0;
 
  /*
  * If the configured address correspond to the magical "any"
@@ -1199,13 +1200,13 @@ rt_ifa_addloop(struct ifaddr *ifa)
  switch (ifa->ifa_addr->sa_family) {
  case AF_INET:
  if (satosin(ifa->ifa_addr)->sin_addr.s_addr == INADDR_ANY)
- return;
+ return (0);
  break;
 #ifdef INET6
  case AF_INET6:
  if (IN6_ARE_ADDR_EQUAL(&satosin6(ifa->ifa_addr)->sin6_addr,
     &in6addr_any))
- return;
+ return (0);
  break;
 #endif
  default:
@@ -1218,19 +1219,22 @@ rt_ifa_addloop(struct ifaddr *ifa)
  /* If there is no loopback entry, allocate one. */
  rt = rtalloc(ifa->ifa_addr, 0, ifa->ifa_ifp->if_rdomain);
  if (rt == NULL || !ISSET(rt->rt_flags, flags));
- rt_ifa_add(ifa, RTF_UP | flags, ifa->ifa_addr);
+ error = rt_ifa_add(ifa, RTF_UP | flags, ifa->ifa_addr);
  if (rt)
  rtfree(rt);
+
+ return (error);
 }
 
 /*
- * Remove loopback rtentry of ifa's addresss if it exists.
+ * Remove local rtentry of ifa's addresss if it exists.
  */
-void
-rt_ifa_delloop(struct ifaddr *ifa)
+int
+rt_ifa_dellocal(struct ifaddr *ifa)
 {
  struct rtentry *rt;
  u_int flags = RTF_HOST|RTF_LOCAL;
+ int error = 0;
 
  /*
  * We do not add local routes for such address, so do not bother
@@ -1239,13 +1243,13 @@ rt_ifa_delloop(struct ifaddr *ifa)
  switch (ifa->ifa_addr->sa_family) {
  case AF_INET:
  if (satosin(ifa->ifa_addr)->sin_addr.s_addr == INADDR_ANY)
- return;
+ return (0);
  break;
 #ifdef INET6
  case AF_INET6:
  if (IN6_ARE_ADDR_EQUAL(&satosin6(ifa->ifa_addr)->sin6_addr,
     &in6addr_any))
- return;
+ return (0);
  break;
 #endif
  default:
@@ -1265,9 +1269,11 @@ rt_ifa_delloop(struct ifaddr *ifa)
  */
  rt = rtalloc(ifa->ifa_addr, 0, ifa->ifa_ifp->if_rdomain);
  if (rt != NULL && ISSET(rt->rt_flags, flags))
- rt_ifa_del(ifa, flags, ifa->ifa_addr);
+ error = rt_ifa_del(ifa, flags, ifa->ifa_addr);
  if (rt)
  rtfree(rt);
+
+ return (error);
 }
 
 /*
Index: sys/net/route.h
===================================================================
RCS file: /home/ncvs/src/sys/net/route.h,v
retrieving revision 1.100
diff -u -p -r1.100 route.h
--- sys/net/route.h 1 Nov 2014 21:40:38 -0000 1.100
+++ sys/net/route.h 20 Nov 2014 14:28:48 -0000
@@ -382,8 +382,8 @@ void rtfree(struct rtentry *);
 int rt_getifa(struct rt_addrinfo *, u_int);
 int rt_ifa_add(struct ifaddr *, int, struct sockaddr *);
 int rt_ifa_del(struct ifaddr *, int, struct sockaddr *);
-void rt_ifa_addloop(struct ifaddr *);
-void rt_ifa_delloop(struct ifaddr *);
+int rt_ifa_addlocal(struct ifaddr *);
+int rt_ifa_dellocal(struct ifaddr *);
 int rtioctl(u_long, caddr_t, struct proc *);
 void rtredirect(struct sockaddr *, struct sockaddr *,
  struct sockaddr *, int, struct sockaddr *,
Index: sys/netinet/in.c
===================================================================
RCS file: /home/ncvs/src/sys/netinet/in.c,v
retrieving revision 1.109
diff -u -p -r1.109 in.c
--- sys/netinet/in.c 20 Nov 2014 10:06:54 -0000 1.109
+++ sys/netinet/in.c 20 Nov 2014 14:28:48 -0000
@@ -621,7 +621,7 @@ in_ifinit(struct ifnet *ifp, struct in_i
  * position gets updated in case the key changes.
  */
  if (!newaddr) {
- rt_ifa_delloop(&ia->ia_ifa);
+ rt_ifa_dellocal(&ia->ia_ifa);
  ifa_del(ifp, &ia->ia_ifa);
  }
  oldaddr = ia->ia_addr;
@@ -694,7 +694,7 @@ out:
  * carp(4).
  */
  ifa_add(ifp, &ia->ia_ifa);
- rt_ifa_addloop(&ia->ia_ifa);
+ rt_ifa_addlocal(&ia->ia_ifa);
 
  if (error && newaddr)
  in_purgeaddr(&ia->ia_ifa);
@@ -712,7 +712,7 @@ in_purgeaddr(struct ifaddr *ifa)
 
  in_ifscrub(ifp, ia);
 
- rt_ifa_delloop(&ia->ia_ifa);
+ rt_ifa_dellocal(&ia->ia_ifa);
  ifa_del(ifp, &ia->ia_ifa);
 
  TAILQ_REMOVE(&in_ifaddr, ia, ia_list);
Index: sys/netinet6/in6.c
===================================================================
RCS file: /home/ncvs/src/sys/netinet6/in6.c,v
retrieving revision 1.145
diff -u -p -r1.145 in6.c
--- sys/netinet6/in6.c 20 Nov 2014 09:55:57 -0000 1.145
+++ sys/netinet6/in6.c 20 Nov 2014 14:28:48 -0000
@@ -1062,7 +1062,7 @@ in6_purgeaddr(struct ifaddr *ifa)
  }
 
  if (ia6_count == 1)
- rt_ifa_delloop(&(ia6->ia_ifa));
+ rt_ifa_dellocal(&(ia6->ia_ifa));
 
  /*
  * leave from multicast groups we have joined for the interface
@@ -1402,7 +1402,7 @@ in6_ifinit(struct ifnet *ifp, struct in6
  if ((ifp->if_flags & (IFF_LOOPBACK | IFF_POINTOPOINT)) == 0)
  ia6->ia_ifa.ifa_rtrequest = nd6_rtrequest;
 
- rt_ifa_addloop(&(ia6->ia_ifa));
+ rt_ifa_addlocal(&(ia6->ia_ifa));
  }
 
  return (error);

Reply | Threaded
Open this post in threaded view
|

Re: Rename rt_ifa_addloop(9)

Mike Belopuhov-5
On 20 November 2014 at 15:37, Martin Pieuchot <[hidden email]> wrote:

> When I decided to use in6_ifaddloop() for IPv4 I barely though about
> the name of the function.  Recently mikeb@ told me that the name is
> confusing, especially because I'm trying to turn the "loopback hack"
> into "local routes".
>
> So here's a diff to rename these functions and to make them return
> the error code of rtrequest9(9), ignored for the moment.
>
> Ok?
>

looks good to me.