Browse Source

lib: consolidate ntohf/htonf from ospfd/isisd TE to lib/network

* lib/network.{c,h}: Consolidate the ntohf/htonf functions used in ospfd
  TE to here, using the value-passing variant that fits with existing
  ntoh/hton functions.
* ospfd/ospf_opaque.c: Remove its variants.
* ospfd/ospf_te.c: Update to use the consolidated, by-value variant.
Paul Jakma 3 years ago
parent
commit
4359501e1a
5 changed files with 47 additions and 45 deletions
  1. 22 0
      lib/network.c
  2. 3 0
      lib/network.h
  3. 0 22
      ospfd/ospf_opaque.c
  4. 0 2
      ospfd/ospf_opaque.h
  5. 22 21
      ospfd/ospf_te.c

+ 22 - 0
lib/network.c

@@ -93,3 +93,25 @@ set_nonblocking(int fd)
     }
   return 0;
 }
+
+float
+htonf (float host)
+{
+#ifdef __STDC_IEC_559__
+  u_int32_t lu1, lu2;
+  float convert;
+  
+  memcpy (&lu1, &host, sizeof (u_int32_t));
+  lu2 = htonl (lu1);
+  memcpy (&convert, &lu2, sizeof (u_int32_t));
+  return convert;
+#else
+#error "Please supply htonf implementation for this platform"
+#endif 
+}
+
+float
+ntohf (float net)
+{
+  return htonf (net);
+}

+ 3 - 0
lib/network.h

@@ -37,4 +37,7 @@ extern int set_nonblocking(int fd);
 #define ERRNO_IO_RETRY(EN) \
 	(((EN) == EAGAIN) || ((EN) == EWOULDBLOCK) || ((EN) == EINTR))
 
+extern float htonf (float);
+extern float ntohf (float);
+
 #endif /* _ZEBRA_NETWORK_H */

+ 0 - 22
ospfd/ospf_opaque.c

@@ -2138,28 +2138,6 @@ ospf_opaque_self_originated_lsa_received (struct ospf_neighbor *nbr,
  * Followings are util functions; probably be used by Opaque-LSAs only...
  *------------------------------------------------------------------------*/
 
-void
-htonf (float *src, float *dst)
-{
-  u_int32_t lu1, lu2;
-
-  memcpy (&lu1, src, sizeof (u_int32_t));
-  lu2 = htonl (lu1);
-  memcpy (dst, &lu2, sizeof (u_int32_t));
-  return;
-}
-
-void
-ntohf (float *src, float *dst)
-{
-  u_int32_t lu1, lu2;
-
-  memcpy (&lu1, src, sizeof (u_int32_t));
-  lu2 = ntohl (lu1);
-  memcpy (dst, &lu2, sizeof (u_int32_t));
-  return;
-}
-
 struct ospf *
 oi_to_top (struct ospf_interface *oi)
 {

+ 0 - 2
ospfd/ospf_opaque.h

@@ -137,8 +137,6 @@ extern void ospf_opaque_lsa_flush_schedule (struct ospf_lsa *lsa);
 extern void ospf_opaque_self_originated_lsa_received (struct ospf_neighbor
 						      *nbr,
 						      struct ospf_lsa *lsa);
-extern void htonf (float *src, float *dst);
-extern void ntohf (float *src, float *dst);
 extern struct ospf *oi_to_top (struct ospf_interface *oi);
 
 #endif /* _ZEBRA_OSPF_OPAQUE_H */

+ 22 - 21
ospfd/ospf_te.c

@@ -38,6 +38,7 @@
 #include "thread.h"
 #include "hash.h"
 #include "sockunion.h"		/* for inet_aton() */
+#include "network.h"
 
 #include "ospfd/ospfd.h"
 #include "ospfd/ospf_interface.h"
@@ -451,30 +452,30 @@ set_linkparams_te_metric (struct mpls_te_link *lp, u_int32_t te_metric)
 }
 
 static void
-set_linkparams_max_bw (struct mpls_te_link *lp, float *fp)
+set_linkparams_max_bw (struct mpls_te_link *lp, float fp)
 {
   lp->max_bw.header.type   = htons (TE_LINK_SUBTLV_MAX_BW);
   lp->max_bw.header.length = htons (sizeof (lp->max_bw.value));
-  htonf (fp, &lp->max_bw.value);
+  lp->max_bw.value = htonf (fp);
   return;
 }
 
 static void
-set_linkparams_max_rsv_bw (struct mpls_te_link *lp, float *fp)
+set_linkparams_max_rsv_bw (struct mpls_te_link *lp, float fp)
 {
   lp->max_rsv_bw.header.type   = htons (TE_LINK_SUBTLV_MAX_RSV_BW);
   lp->max_rsv_bw.header.length = htons (sizeof (lp->max_rsv_bw.value));
-  htonf (fp, &lp->max_rsv_bw.value);
+  lp->max_rsv_bw.value = htonf (fp);
   return;
 }
 
 static void
-set_linkparams_unrsv_bw (struct mpls_te_link *lp, int priority, float *fp)
+set_linkparams_unrsv_bw (struct mpls_te_link *lp, int priority, float fp)
 {
   /* Note that TLV-length field is the size of array. */
   lp->unrsv_bw.header.type   = htons (TE_LINK_SUBTLV_UNRSV_BW);
   lp->unrsv_bw.header.length = htons (sizeof (lp->unrsv_bw.value));
-  htonf (fp, &lp->unrsv_bw.value [priority]);
+  lp->unrsv_bw.value [priority] = htonf (fp);
   return;
 }
 
@@ -511,11 +512,11 @@ initialize_linkparams (struct mpls_te_link *lp)
   fval = (float)((ifp->bandwidth ? ifp->bandwidth
                                  : OSPF_DEFAULT_BANDWIDTH) * 1000 / 8);
 
-  set_linkparams_max_bw (lp, &fval);
-  set_linkparams_max_rsv_bw (lp, &fval);
+  set_linkparams_max_bw (lp, fval);
+  set_linkparams_max_rsv_bw (lp, fval);
 
   for (i = 0; i < 8; i++)
-    set_linkparams_unrsv_bw (lp, i, &fval);
+    set_linkparams_unrsv_bw (lp, i, fval);
 
   return;
 }
@@ -1246,7 +1247,7 @@ show_vty_link_subtlv_max_bw (struct vty *vty, struct te_tlv_header *tlvh)
   float fval;
 
   top = (struct te_link_subtlv_max_bw *) tlvh;
-  ntohf (&top->value, &fval);
+  fval = ntohf (top->value);
 
   if (vty != NULL)
     vty_out (vty, "  Maximum Bandwidth: %g (Bytes/sec)%s", fval, VTY_NEWLINE);
@@ -1263,7 +1264,7 @@ show_vty_link_subtlv_max_rsv_bw (struct vty *vty, struct te_tlv_header *tlvh)
   float fval;
 
   top = (struct te_link_subtlv_max_rsv_bw *) tlvh;
-  ntohf (&top->value, &fval);
+  fval = ntohf (top->value);
 
   if (vty != NULL)
     vty_out (vty, "  Maximum Reservable Bandwidth: %g (Bytes/sec)%s", fval, VTY_NEWLINE);
@@ -1283,7 +1284,7 @@ show_vty_link_subtlv_unrsv_bw (struct vty *vty, struct te_tlv_header *tlvh)
   top = (struct te_link_subtlv_unrsv_bw *) tlvh;
   for (i = 0; i < 8; i++)
     {
-      ntohf (&top->value[i], &fval);
+      fval = ntohf (top->value[i]);
       if (vty != NULL)
         vty_out (vty, "  Unreserved Bandwidth (pri %d): %g (Bytes/sec)%s", i, fval, VTY_NEWLINE);
       else
@@ -1434,17 +1435,17 @@ ospf_mpls_te_config_write_if (struct vty *vty, struct interface *ifp)
       vty_out (vty, " mpls-te link metric %u%s",
                (u_int32_t) ntohl (lp->te_metric.value), VTY_NEWLINE);
 
-      ntohf (&lp->max_bw.value, &fval);
+      fval = ntohf (lp->max_bw.value);
       if (fval >= MPLS_TE_MINIMUM_BANDWIDTH)
         vty_out (vty, " mpls-te link max-bw %g%s", fval, VTY_NEWLINE);
 
-      ntohf (&lp->max_rsv_bw.value, &fval);
+      fval = ntohf (lp->max_rsv_bw.value);
       if (fval >= MPLS_TE_MINIMUM_BANDWIDTH)
         vty_out (vty, " mpls-te link max-rsv-bw %g%s", fval, VTY_NEWLINE);
 
       for (i = 0; i < 8; i++)
         {
-          ntohf (&lp->unrsv_bw.value[i], &fval);
+          fval = ntohf (lp->unrsv_bw.value[i]);
           if (fval >= MPLS_TE_MINIMUM_BANDWIDTH)
             vty_out (vty, " mpls-te link unrsv-bw %d %g%s",
                      i, fval, VTY_NEWLINE);
@@ -1637,7 +1638,7 @@ DEFUN (mpls_te_link_maxbw,
       return CMD_WARNING;
     }
 
-  ntohf (&lp->max_bw.value, &f1);
+  f1 = ntohf (lp->max_bw.value);
   if (sscanf (argv[0], "%g", &f2) != 1)
     {
       vty_out (vty, "mpls_te_link_maxbw: fscanf: %s%s", safe_strerror (errno), VTY_NEWLINE);
@@ -1647,7 +1648,7 @@ DEFUN (mpls_te_link_maxbw,
   if (ntohs (lp->max_bw.header.type) == 0
   ||  f1 != f2)
     {
-      set_linkparams_max_bw (lp, &f2);
+      set_linkparams_max_bw (lp, f2);
 
       if (OspfMplsTE.status == enabled)
         if (lp->area != NULL)
@@ -1679,7 +1680,7 @@ DEFUN (mpls_te_link_max_rsv_bw,
       return CMD_WARNING;
     }
 
-  ntohf (&lp->max_rsv_bw.value, &f1);
+  f1 = ntohf (lp->max_rsv_bw.value);
   if (sscanf (argv[0], "%g", &f2) != 1)
     {
       vty_out (vty, "mpls_te_link_max_rsv_bw: fscanf: %s%s", safe_strerror (errno), VTY_NEWLINE);
@@ -1689,7 +1690,7 @@ DEFUN (mpls_te_link_max_rsv_bw,
   if (ntohs (lp->max_rsv_bw.header.type) == 0
   ||  f1 != f2)
     {
-      set_linkparams_max_rsv_bw (lp, &f2);
+      set_linkparams_max_rsv_bw (lp, f2);
 
       if (OspfMplsTE.status == enabled)
         if (lp->area != NULL)
@@ -1730,7 +1731,7 @@ DEFUN (mpls_te_link_unrsv_bw,
       return CMD_WARNING;
     }
 
-  ntohf (&lp->unrsv_bw.value [priority], &f1);
+  f1 = ntohf (lp->unrsv_bw.value [priority]);
   if (sscanf (argv[1], "%g", &f2) != 1)
     {
       vty_out (vty, "mpls_te_link_unrsv_bw: fscanf: %s%s", safe_strerror (errno), VTY_NEWLINE);
@@ -1740,7 +1741,7 @@ DEFUN (mpls_te_link_unrsv_bw,
   if (ntohs (lp->unrsv_bw.header.type) == 0
   ||  f1 != f2)
     {
-      set_linkparams_unrsv_bw (lp, priority, &f2);
+      set_linkparams_unrsv_bw (lp, priority, f2);
 
       if (OspfMplsTE.status == enabled)
         if (lp->area != NULL)