1 #include "mpls_struct.h"
2 #include "mpls_assert.h"
4 int mpls_inet_addr_compare(struct mpls_inet_addr
*addr1
,
5 struct mpls_inet_addr
*addr2
) {
6 if (addr1
->type
!= addr2
->type
) {
10 case MPLS_FAMILY_IPV4
:
11 if (addr1
->u
.ipv4
!= addr2
->u
.ipv4
) {
12 return addr1
->u
.ipv4
> addr2
->u
.ipv4
? 1 : -1;
15 case MPLS_FAMILY_IPV6
:
16 return memcmp(addr1
->u
.ipv6
, addr2
->u
.ipv6
, 16);
23 int mpls_nexthop_compare(struct mpls_nexthop
*nh1
, struct mpls_nexthop
*nh2
) {
27 if (nh1
->type
!= nh2
->type
) {
30 if (nh1
->type
& MPLS_NH_IP
) {
32 if ((retval
= mpls_inet_addr_compare(&nh1
->ip
, &nh2
->ip
))) {
36 if (nh1
->type
& MPLS_NH_IF
) {
38 if ((retval
= mpls_if_handle_compare(nh1
->if_handle
, nh2
->if_handle
))) {
42 if (nh1
->type
& MPLS_NH_OUTSEGMENT
) {
44 if ((retval
= mpls_outsegment_handle_compare(nh1
->outsegment_handle
,
45 nh2
->outsegment_handle
))) {
56 int mpls_label_struct_compare(struct mpls_label_struct
* l1
,
57 struct mpls_label_struct
* l2
) {
58 if (l1
->type
!= l2
->type
) {
62 case MPLS_LABEL_TYPE_GENERIC
:
63 if (l1
->u
.gen
!= l2
->u
.gen
) {
64 return (l1
->u
.gen
> l2
->u
.gen
) ? 1 : -1;
67 case MPLS_LABEL_TYPE_ATM
:
68 if (l1
->u
.atm
.vpi
!= l2
->u
.atm
.vpi
) {
69 return (l1
->u
.atm
.vpi
> l2
->u
.atm
.vpi
) ? 1 : -1;
71 if (l1
->u
.atm
.vci
!= l2
->u
.atm
.vci
) {
72 return (l1
->u
.atm
.vci
> l2
->u
.atm
.vci
) ? 1 : -1;
75 case MPLS_LABEL_TYPE_FR
:
76 if (l1
->u
.fr
.len
!= l2
->u
.fr
.len
) {
77 return (l1
->u
.fr
.dlci
> l2
->u
.fr
.dlci
) ? 1 : -1;
79 if (l1
->u
.fr
.dlci
!= l2
->u
.fr
.dlci
) {
80 return (l1
->u
.fr
.len
> l2
->u
.fr
.len
) ? 1 : -1;
89 int mpls_dest_compare(struct mpls_dest
* d1
, struct mpls_dest
* d2
) {
91 if ((retval
= mpls_inet_addr_compare(&d1
->addr
, &d2
->addr
))) {
94 if (d1
->port
!= d2
->port
) {
95 return (d1
->port
> d2
->port
) ? 1 : -1;
97 if ((retval
= mpls_if_handle_compare(d1
->if_handle
, d2
->if_handle
))) {
103 int mpls_range_compare(struct mpls_range
* r1
, struct mpls_range
* r2
) {
105 if ((retval
= mpls_label_struct_compare(&r1
->min
, &r2
->min
))) {
108 if ((retval
= mpls_label_struct_compare(&r1
->max
, &r2
->max
))) {
114 int mpls_fec_compare(struct mpls_fec
* f1
, struct mpls_fec
* f2
) {
117 if (f1
->type
!= f2
->type
) {
122 case MPLS_FEC_PREFIX
:
123 if ((retval
= mpls_inet_addr_compare(&f1
->u
.prefix
.network
,
124 &f2
->u
.prefix
.network
))) {
127 if (f1
->u
.prefix
.length
> f2
->u
.prefix
.length
) {
128 return (f1
->u
.prefix
.length
!= f2
->u
.prefix
.length
) ? 1 : -1;
132 return mpls_inet_addr_compare(&f1
->u
.host
, &f2
->u
.host
);
134 if (f1
->u
.l2cc
.connection_id
!= f2
->u
.l2cc
.connection_id
) {
135 return (f1
->u
.l2cc
.connection_id
>f2
->u
.l2cc
.connection_id
) ? 1 : -1;
137 if (f1
->u
.l2cc
.group_id
!= f2
->u
.l2cc
.group_id
) {
138 return (f1
->u
.l2cc
.group_id
> f2
->u
.l2cc
.group_id
) ? 1 : -1;
140 if (f1
->u
.l2cc
.type
!= f2
->u
.l2cc
.type
) {