The function implements a limited version of the rules from Source Address selection algorithm defined section of RFC 3484.
(source_a, source_b)
| 133 | return -1 |
| 134 | |
| 135 | def rfc3484_cmp(source_a, source_b): |
| 136 | # type: (str, str) -> int |
| 137 | """ |
| 138 | The function implements a limited version of the rules from Source |
| 139 | Address selection algorithm defined section of RFC 3484. |
| 140 | """ |
| 141 | |
| 142 | # Rule 1: Prefer same address |
| 143 | if source_a == dst: |
| 144 | return 1 |
| 145 | if source_b == dst: |
| 146 | return 1 |
| 147 | |
| 148 | # Rule 2: Prefer appropriate scope |
| 149 | tmp = scope_cmp(source_a, source_b) |
| 150 | if tmp == -1: |
| 151 | if scope_cmp(source_a, dst) == -1: |
| 152 | return 1 |
| 153 | else: |
| 154 | return -1 |
| 155 | elif tmp == 1: |
| 156 | if scope_cmp(source_b, dst) == -1: |
| 157 | return 1 |
| 158 | else: |
| 159 | return -1 |
| 160 | |
| 161 | # Rule 3: cannot be easily implemented |
| 162 | # Rule 4: cannot be easily implemented |
| 163 | # Rule 5: does not make sense here |
| 164 | # Rule 6: cannot be implemented |
| 165 | # Rule 7: cannot be implemented |
| 166 | |
| 167 | # Rule 8: Longest prefix match |
| 168 | tmp1 = in6_get_common_plen(source_a, dst) |
| 169 | tmp2 = in6_get_common_plen(source_b, dst) |
| 170 | if tmp1 > tmp2: |
| 171 | return 1 |
| 172 | elif tmp2 > tmp1: |
| 173 | return -1 |
| 174 | return 0 |
| 175 | |
| 176 | if not candidate_set: |
| 177 | # Should not happen |
nothing calls this directly
no test coverage detected