@@ -712,10 +712,11 @@ int prefix_same(const struct prefix *p1, const struct prefix *p2)
712
712
}
713
713
714
714
/*
715
- * Return 0 if the network prefixes represented by the struct prefix
716
- * arguments are the same prefix, and 1 otherwise. Network prefixes
717
- * are considered the same if the prefix lengths are equal and the
718
- * network parts are the same. Host bits (which are considered masked
715
+ * Return -1/0/1 comparing the prefixes in a way that gives a full/linear
716
+ * order.
717
+ *
718
+ * Network prefixes are considered the same if the prefix lengths are equal
719
+ * and the network parts are the same. Host bits (which are considered masked
719
720
* by the prefix length) are not significant. Thus, 10.0.0.1/8 and
720
721
* 10.0.0.2/8 are considered equivalent by this routine. Note that
721
722
* this routine has the same return sense as strcmp (which is different
@@ -725,44 +726,43 @@ int prefix_cmp(const struct prefix *p1, const struct prefix *p2)
725
726
{
726
727
int offset ;
727
728
int shift ;
729
+ int i ;
728
730
729
731
/* Set both prefix's head pointer. */
730
732
const uint8_t * pp1 ;
731
733
const uint8_t * pp2 ;
732
734
733
735
if (p1 -> family != p2 -> family )
734
- return 1 ;
736
+ return numcmp ( p1 -> family , p2 -> family ) ;
735
737
if (p1 -> family == AF_FLOWSPEC ) {
736
738
pp1 = (const uint8_t * )p1 -> u .prefix_flowspec .ptr ;
737
739
pp2 = (const uint8_t * )p2 -> u .prefix_flowspec .ptr ;
738
740
739
741
if (p1 -> u .prefix_flowspec .prefixlen !=
740
742
p2 -> u .prefix_flowspec .prefixlen )
741
- return 1 ;
743
+ return numcmp (p1 -> u .prefix_flowspec .prefixlen ,
744
+ p2 -> u .prefix_flowspec .prefixlen );
742
745
743
746
offset = p1 -> u .prefix_flowspec .prefixlen ;
744
747
while (offset -- )
745
748
if (pp1 [offset ] != pp2 [offset ])
746
- return 1 ;
749
+ return numcmp ( pp1 [ offset ], pp2 [ offset ]) ;
747
750
return 0 ;
748
751
}
749
752
pp1 = p1 -> u .val ;
750
753
pp2 = p2 -> u .val ;
751
754
752
755
if (p1 -> prefixlen != p2 -> prefixlen )
753
- return 1 ;
756
+ return numcmp ( p1 -> prefixlen , p2 -> prefixlen ) ;
754
757
offset = p1 -> prefixlen / PNBBY ;
755
758
shift = p1 -> prefixlen % PNBBY ;
756
759
757
- if (shift )
758
- if (maskbit [shift ] & (pp1 [offset ] ^ pp2 [offset ]))
759
- return 1 ;
760
-
761
- while (offset -- )
762
- if (pp1 [offset ] != pp2 [offset ])
763
- return 1 ;
760
+ i = memcmp (pp1 , pp2 , offset );
761
+ if (i )
762
+ return i ;
764
763
765
- return 0 ;
764
+ return numcmp (pp1 [offset ] & maskbit [shift ],
765
+ pp2 [offset ] & maskbit [shift ]);
766
766
}
767
767
768
768
/*
0 commit comments