if_llatbl.c (287318) | if_llatbl.c (287789) |
---|---|
1/* 2 * Copyright (c) 2004 Luigi Rizzo, Alessandro Cerri. All rights reserved. 3 * Copyright (c) 2004-2008 Qing Li. All rights reserved. 4 * Copyright (c) 2008 Kip Macy. All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: --- 11 unchanged lines hidden (view full) --- 20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25 * SUCH DAMAGE. 26 */ 27#include <sys/cdefs.h> | 1/* 2 * Copyright (c) 2004 Luigi Rizzo, Alessandro Cerri. All rights reserved. 3 * Copyright (c) 2004-2008 Qing Li. All rights reserved. 4 * Copyright (c) 2008 Kip Macy. All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: --- 11 unchanged lines hidden (view full) --- 20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25 * SUCH DAMAGE. 26 */ 27#include <sys/cdefs.h> |
28__FBSDID("$FreeBSD: head/sys/net/if_llatbl.c 287318 2015-08-31 05:03:36Z melifaro $"); | 28__FBSDID("$FreeBSD: head/sys/net/if_llatbl.c 287789 2015-09-14 16:48:19Z melifaro $"); |
29 30#include "opt_ddb.h" 31#include "opt_inet.h" 32#include "opt_inet6.h" 33 34#include <sys/param.h> 35#include <sys/systm.h> 36#include <sys/malloc.h> --- 144 unchanged lines hidden (view full) --- 181#if 0 182 lle->lle_tbl = NULL; 183 lle->lle_head = NULL; 184#endif 185 } 186} 187 188struct prefix_match_data { | 29 30#include "opt_ddb.h" 31#include "opt_inet.h" 32#include "opt_inet6.h" 33 34#include <sys/param.h> 35#include <sys/systm.h> 36#include <sys/malloc.h> --- 144 unchanged lines hidden (view full) --- 181#if 0 182 lle->lle_tbl = NULL; 183 lle->lle_head = NULL; 184#endif 185 } 186} 187 188struct prefix_match_data { |
189 const struct sockaddr *prefix; | 189 const struct sockaddr *addr; |
190 const struct sockaddr *mask; 191 struct llentries dchain; 192 u_int flags; 193}; 194 195static int 196htable_prefix_free_cb(struct lltable *llt, struct llentry *lle, void *farg) 197{ 198 struct prefix_match_data *pmd; 199 200 pmd = (struct prefix_match_data *)farg; 201 | 190 const struct sockaddr *mask; 191 struct llentries dchain; 192 u_int flags; 193}; 194 195static int 196htable_prefix_free_cb(struct lltable *llt, struct llentry *lle, void *farg) 197{ 198 struct prefix_match_data *pmd; 199 200 pmd = (struct prefix_match_data *)farg; 201 |
202 if (llt->llt_match_prefix(pmd->prefix, pmd->mask, pmd->flags, lle)) { | 202 if (llt->llt_match_prefix(pmd->addr, pmd->mask, pmd->flags, lle)) { |
203 LLE_WLOCK(lle); 204 LIST_INSERT_HEAD(&pmd->dchain, lle, lle_chain); 205 } 206 207 return (0); 208} 209 210static void | 203 LLE_WLOCK(lle); 204 LIST_INSERT_HEAD(&pmd->dchain, lle, lle_chain); 205 } 206 207 return (0); 208} 209 210static void |
211htable_prefix_free(struct lltable *llt, const struct sockaddr *prefix, | 211htable_prefix_free(struct lltable *llt, const struct sockaddr *addr, |
212 const struct sockaddr *mask, u_int flags) 213{ 214 struct llentry *lle, *next; 215 struct prefix_match_data pmd; 216 217 bzero(&pmd, sizeof(pmd)); | 212 const struct sockaddr *mask, u_int flags) 213{ 214 struct llentry *lle, *next; 215 struct prefix_match_data pmd; 216 217 bzero(&pmd, sizeof(pmd)); |
218 pmd.prefix = prefix; | 218 pmd.addr = addr; |
219 pmd.mask = mask; 220 pmd.flags = flags; 221 LIST_INIT(&pmd.dchain); 222 223 IF_AFDATA_WLOCK(llt->llt_ifp); 224 /* Push matching lles to chain */ 225 lltable_foreach_lle(llt, htable_prefix_free_cb, &pmd); 226 --- 195 unchanged lines hidden (view full) --- 422 LLE_WUNLOCK(lle); 423 } 424 } 425 } 426 LLTABLE_RUNLOCK(); 427} 428#endif 429 | 219 pmd.mask = mask; 220 pmd.flags = flags; 221 LIST_INIT(&pmd.dchain); 222 223 IF_AFDATA_WLOCK(llt->llt_ifp); 224 /* Push matching lles to chain */ 225 lltable_foreach_lle(llt, htable_prefix_free_cb, &pmd); 226 --- 195 unchanged lines hidden (view full) --- 422 LLE_WUNLOCK(lle); 423 } 424 } 425 } 426 LLTABLE_RUNLOCK(); 427} 428#endif 429 |
430/* 431 * Deletes an address from given lltable. 432 * Used for userland interaction to remove 433 * individual entries. Skips entries added by OS. 434 */ 435int 436lltable_delete_addr(struct lltable *llt, u_int flags, 437 const struct sockaddr *l3addr) 438{ 439 struct llentry *lle; 440 struct ifnet *ifp; 441 442 ifp = llt->llt_ifp; 443 IF_AFDATA_WLOCK(ifp); 444 lle = lla_lookup(llt, LLE_EXCLUSIVE, l3addr); 445 446 if (lle == NULL) { 447 IF_AFDATA_WUNLOCK(ifp); 448 return (ENOENT); 449 } 450 if ((lle->la_flags & LLE_IFADDR) != 0 && (flags & LLE_IFADDR) == 0) { 451 IF_AFDATA_WUNLOCK(ifp); 452 LLE_WUNLOCK(lle); 453 return (EPERM); 454 } 455 456 lltable_unlink_entry(llt, lle); 457 IF_AFDATA_WUNLOCK(ifp); 458 459 llt->llt_delete_entry(llt, lle); 460 461 return (0); 462} 463 |
|
430void | 464void |
431lltable_prefix_free(int af, struct sockaddr *prefix, struct sockaddr *mask, | 465lltable_prefix_free(int af, struct sockaddr *addr, struct sockaddr *mask, |
432 u_int flags) 433{ 434 struct lltable *llt; 435 436 LLTABLE_RLOCK(); 437 SLIST_FOREACH(llt, &V_lltables, llt_link) { 438 if (llt->llt_af != af) 439 continue; 440 | 466 u_int flags) 467{ 468 struct lltable *llt; 469 470 LLTABLE_RLOCK(); 471 SLIST_FOREACH(llt, &V_lltables, llt_link) { 472 if (llt->llt_af != af) 473 continue; 474 |
441 llt->llt_prefix_free(llt, prefix, mask, flags); | 475 llt->llt_prefix_free(llt, addr, mask, flags); |
442 } 443 LLTABLE_RUNLOCK(); 444} 445 446struct lltable * 447lltable_allocate_htbl(uint32_t hsize) 448{ 449 struct lltable *llt; --- 196 unchanged lines hidden (view full) --- 646 &((struct sockaddr_in *)dst)->sin_addr, 647 &((struct sockaddr_in *)dst)->sin_addr, 648 (u_char *)LLADDR(dl)); 649#endif 650 651 break; 652 653 case RTM_DELETE: | 476 } 477 LLTABLE_RUNLOCK(); 478} 479 480struct lltable * 481lltable_allocate_htbl(uint32_t hsize) 482{ 483 struct lltable *llt; --- 196 unchanged lines hidden (view full) --- 680 &((struct sockaddr_in *)dst)->sin_addr, 681 &((struct sockaddr_in *)dst)->sin_addr, 682 (u_char *)LLADDR(dl)); 683#endif 684 685 break; 686 687 case RTM_DELETE: |
654 IF_AFDATA_WLOCK(ifp); 655 error = lla_delete(llt, 0, dst); 656 IF_AFDATA_WUNLOCK(ifp); 657 return (error == 0 ? 0 : ENOENT); | 688 return (lltable_delete_addr(llt, 0, dst)); |
658 659 default: 660 error = EINVAL; 661 } 662 663 return (error); 664} 665 --- 141 unchanged lines hidden --- | 689 690 default: 691 error = EINVAL; 692 } 693 694 return (error); 695} 696 --- 141 unchanged lines hidden --- |