Commit 123031c0eeda6144b4002dc3285375aa9ae9dc11

Authored by Joe Perches
Committed by David S. Miller
1 parent e199e6136c

sctp: fix test for end of loop

Add a list_has_sctp_addr function to simplify loop

Based on a patches by Dan Carpenter and David Miller

Signed-off-by: Joe Perches <joe@perches.com>
Acked-by: Vlad Yasevich <vladislav.yasevich@hp.com>
Signed-off-by: David S. Miller <davem@davemloft.net>

Showing 1 changed file with 23 additions and 23 deletions Side-by-side Diff

net/sctp/sm_statefuns.c
... ... @@ -1232,6 +1232,18 @@
1232 1232 return 0;
1233 1233 }
1234 1234  
  1235 +static bool list_has_sctp_addr(const struct list_head *list,
  1236 + union sctp_addr *ipaddr)
  1237 +{
  1238 + struct sctp_transport *addr;
  1239 +
  1240 + list_for_each_entry(addr, list, transports) {
  1241 + if (sctp_cmp_addr_exact(ipaddr, &addr->ipaddr))
  1242 + return true;
  1243 + }
  1244 +
  1245 + return false;
  1246 +}
1235 1247 /* A restart is occurring, check to make sure no new addresses
1236 1248 * are being added as we may be under a takeover attack.
1237 1249 */
1238 1250  
... ... @@ -1240,10 +1252,10 @@
1240 1252 struct sctp_chunk *init,
1241 1253 sctp_cmd_seq_t *commands)
1242 1254 {
1243   - struct sctp_transport *new_addr, *addr;
1244   - int found;
  1255 + struct sctp_transport *new_addr;
  1256 + int ret = 1;
1245 1257  
1246   - /* Implementor's Guide - Sectin 5.2.2
  1258 + /* Implementor's Guide - Section 5.2.2
1247 1259 * ...
1248 1260 * Before responding the endpoint MUST check to see if the
1249 1261 * unexpected INIT adds new addresses to the association. If new
1250 1262  
1251 1263  
1252 1264  
1253 1265  
... ... @@ -1254,31 +1266,19 @@
1254 1266 /* Search through all current addresses and make sure
1255 1267 * we aren't adding any new ones.
1256 1268 */
1257   - new_addr = NULL;
1258   - found = 0;
1259   -
1260 1269 list_for_each_entry(new_addr, &new_asoc->peer.transport_addr_list,
1261   - transports) {
1262   - found = 0;
1263   - list_for_each_entry(addr, &asoc->peer.transport_addr_list,
1264   - transports) {
1265   - if (sctp_cmp_addr_exact(&new_addr->ipaddr,
1266   - &addr->ipaddr)) {
1267   - found = 1;
1268   - break;
1269   - }
1270   - }
1271   - if (!found)
  1270 + transports) {
  1271 + if (!list_has_sctp_addr(&asoc->peer.transport_addr_list,
  1272 + &new_addr->ipaddr)) {
  1273 + sctp_sf_send_restart_abort(&new_addr->ipaddr, init,
  1274 + commands);
  1275 + ret = 0;
1272 1276 break;
  1277 + }
1273 1278 }
1274 1279  
1275   - /* If a new address was added, ABORT the sender. */
1276   - if (!found && new_addr) {
1277   - sctp_sf_send_restart_abort(&new_addr->ipaddr, init, commands);
1278   - }
1279   -
1280 1280 /* Return success if all addresses were found. */
1281   - return found;
  1281 + return ret;
1282 1282 }
1283 1283  
1284 1284 /* Populate the verification/tie tags based on overlapping INIT