* compare two secasindex structure. * flag can specify to compare 2 saidxes. * compare two secasindex structure without both mode and reqid. * don't compare port. * IN: * saidx0: source, it can be in SAD. * saidx1: object. * OUT: * 1 : equal * 0 : not equal */
| 4106 | * 0 : not equal |
| 4107 | */ |
| 4108 | static int |
| 4109 | key_cmpsaidx(const struct secasindex *saidx0, const struct secasindex *saidx1, |
| 4110 | int flag) |
| 4111 | { |
| 4112 | |
| 4113 | /* sanity */ |
| 4114 | if (saidx0 == NULL && saidx1 == NULL) |
| 4115 | return 1; |
| 4116 | |
| 4117 | if (saidx0 == NULL || saidx1 == NULL) |
| 4118 | return 0; |
| 4119 | |
| 4120 | if (saidx0->proto != saidx1->proto) |
| 4121 | return 0; |
| 4122 | |
| 4123 | if (flag == CMP_EXACTLY) { |
| 4124 | if (saidx0->mode != saidx1->mode) |
| 4125 | return 0; |
| 4126 | if (saidx0->reqid != saidx1->reqid) |
| 4127 | return 0; |
| 4128 | if (bcmp(&saidx0->src, &saidx1->src, |
| 4129 | saidx0->src.sa.sa_len) != 0 || |
| 4130 | bcmp(&saidx0->dst, &saidx1->dst, |
| 4131 | saidx0->dst.sa.sa_len) != 0) |
| 4132 | return 0; |
| 4133 | } else { |
| 4134 | /* CMP_MODE_REQID, CMP_REQID, CMP_HEAD */ |
| 4135 | if (flag == CMP_MODE_REQID || flag == CMP_REQID) { |
| 4136 | /* |
| 4137 | * If reqid of SPD is non-zero, unique SA is required. |
| 4138 | * The result must be of same reqid in this case. |
| 4139 | */ |
| 4140 | if (saidx1->reqid != 0 && |
| 4141 | saidx0->reqid != saidx1->reqid) |
| 4142 | return 0; |
| 4143 | } |
| 4144 | |
| 4145 | if (flag == CMP_MODE_REQID) { |
| 4146 | if (saidx0->mode != IPSEC_MODE_ANY |
| 4147 | && saidx0->mode != saidx1->mode) |
| 4148 | return 0; |
| 4149 | } |
| 4150 | |
| 4151 | if (key_sockaddrcmp(&saidx0->src.sa, &saidx1->src.sa, 0) != 0) |
| 4152 | return 0; |
| 4153 | if (key_sockaddrcmp(&saidx0->dst.sa, &saidx1->dst.sa, 0) != 0) |
| 4154 | return 0; |
| 4155 | } |
| 4156 | |
| 4157 | return 1; |
| 4158 | } |
| 4159 | |
| 4160 | /* |
| 4161 | * compare two secindex structure exactly. |
no test coverage detected