ieee80211_node.c (140753) | ieee80211_node.c (140766) |
---|---|
1/*- 2 * Copyright (c) 2001 Atsushi Onoe 3 * Copyright (c) 2002-2005 Sam Leffler, Errno Consulting 4 * 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: --- 17 unchanged lines hidden (view full) --- 26 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 30 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 */ 32 33#include <sys/cdefs.h> | 1/*- 2 * Copyright (c) 2001 Atsushi Onoe 3 * Copyright (c) 2002-2005 Sam Leffler, Errno Consulting 4 * 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: --- 17 unchanged lines hidden (view full) --- 26 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 30 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 */ 32 33#include <sys/cdefs.h> |
34__FBSDID("$FreeBSD: head/sys/net80211/ieee80211_node.c 140753 2005-01-24 19:32:10Z sam $"); | 34__FBSDID("$FreeBSD: head/sys/net80211/ieee80211_node.c 140766 2005-01-24 20:50:20Z sam $"); |
35 36#include <sys/param.h> 37#include <sys/systm.h> 38#include <sys/mbuf.h> 39#include <sys/malloc.h> 40#include <sys/kernel.h> 41 42#include <sys/socket.h> --- 835 unchanged lines hidden (view full) --- 878static void 879ieee80211_setup_node(struct ieee80211_node_table *nt, 880 struct ieee80211_node *ni, const u_int8_t *macaddr) 881{ 882 struct ieee80211com *ic = nt->nt_ic; 883 int hash; 884 885 IEEE80211_DPRINTF(ic, IEEE80211_MSG_NODE, | 35 36#include <sys/param.h> 37#include <sys/systm.h> 38#include <sys/mbuf.h> 39#include <sys/malloc.h> 40#include <sys/kernel.h> 41 42#include <sys/socket.h> --- 835 unchanged lines hidden (view full) --- 878static void 879ieee80211_setup_node(struct ieee80211_node_table *nt, 880 struct ieee80211_node *ni, const u_int8_t *macaddr) 881{ 882 struct ieee80211com *ic = nt->nt_ic; 883 int hash; 884 885 IEEE80211_DPRINTF(ic, IEEE80211_MSG_NODE, |
886 "%s %s in %s table\n", __func__, | 886 "%s %p<%s> in %s table\n", __func__, ni, |
887 ether_sprintf(macaddr), nt->nt_name); 888 889 IEEE80211_ADDR_COPY(ni->ni_macaddr, macaddr); 890 hash = IEEE80211_NODE_HASH(macaddr); 891 ieee80211_node_initref(ni); /* mark referenced */ 892 ni->ni_chan = IEEE80211_CHAN_ANYC; 893 ni->ni_authmode = IEEE80211_AUTH_OPEN; 894 ni->ni_txpower = ic->ic_txpowlimit; /* max power */ --- 62 unchanged lines hidden (view full) --- 957 IEEE80211_NODE_LOCK_ASSERT(nt); 958 959 hash = IEEE80211_NODE_HASH(macaddr); 960 LIST_FOREACH(ni, &nt->nt_hash[hash], ni_hash) { 961 if (IEEE80211_ADDR_EQ(ni->ni_macaddr, macaddr)) { 962 ieee80211_ref_node(ni); /* mark referenced */ 963#ifdef IEEE80211_DEBUG_REFCNT 964 IEEE80211_DPRINTF(nt->nt_ic, IEEE80211_MSG_NODE, | 887 ether_sprintf(macaddr), nt->nt_name); 888 889 IEEE80211_ADDR_COPY(ni->ni_macaddr, macaddr); 890 hash = IEEE80211_NODE_HASH(macaddr); 891 ieee80211_node_initref(ni); /* mark referenced */ 892 ni->ni_chan = IEEE80211_CHAN_ANYC; 893 ni->ni_authmode = IEEE80211_AUTH_OPEN; 894 ni->ni_txpower = ic->ic_txpowlimit; /* max power */ --- 62 unchanged lines hidden (view full) --- 957 IEEE80211_NODE_LOCK_ASSERT(nt); 958 959 hash = IEEE80211_NODE_HASH(macaddr); 960 LIST_FOREACH(ni, &nt->nt_hash[hash], ni_hash) { 961 if (IEEE80211_ADDR_EQ(ni->ni_macaddr, macaddr)) { 962 ieee80211_ref_node(ni); /* mark referenced */ 963#ifdef IEEE80211_DEBUG_REFCNT 964 IEEE80211_DPRINTF(nt->nt_ic, IEEE80211_MSG_NODE, |
965 "%s (%s:%u) %s refcnt %d\n", __func__, func, line, 966 ether_sprintf(ni->ni_macaddr), 967 ieee80211_node_refcnt(ni)); | 965 "%s (%s:%u) %p<%s> refcnt %d\n", __func__, 966 func, line, 967 ni, ether_sprintf(ni->ni_macaddr), 968 ieee80211_node_refcnt(ni)); |
968#endif 969 return ni; 970 } 971 } 972 return NULL; 973} 974#ifdef IEEE80211_DEBUG_REFCNT 975#define _ieee80211_find_node(nt, mac) \ --- 154 unchanged lines hidden (view full) --- 1130 hash = IEEE80211_NODE_HASH(macaddr); 1131 IEEE80211_NODE_LOCK(nt); 1132 LIST_FOREACH(ni, &nt->nt_hash[hash], ni_hash) { 1133 if (IEEE80211_ADDR_EQ(ni->ni_macaddr, macaddr) && 1134 ni->ni_chan == chan) { 1135 ieee80211_ref_node(ni); /* mark referenced */ 1136 IEEE80211_DPRINTF(nt->nt_ic, IEEE80211_MSG_NODE, 1137#ifdef IEEE80211_DEBUG_REFCNT | 969#endif 970 return ni; 971 } 972 } 973 return NULL; 974} 975#ifdef IEEE80211_DEBUG_REFCNT 976#define _ieee80211_find_node(nt, mac) \ --- 154 unchanged lines hidden (view full) --- 1131 hash = IEEE80211_NODE_HASH(macaddr); 1132 IEEE80211_NODE_LOCK(nt); 1133 LIST_FOREACH(ni, &nt->nt_hash[hash], ni_hash) { 1134 if (IEEE80211_ADDR_EQ(ni->ni_macaddr, macaddr) && 1135 ni->ni_chan == chan) { 1136 ieee80211_ref_node(ni); /* mark referenced */ 1137 IEEE80211_DPRINTF(nt->nt_ic, IEEE80211_MSG_NODE, 1138#ifdef IEEE80211_DEBUG_REFCNT |
1138 "%s (%s:%u) %s refcnt %d\n", __func__, func, line, | 1139 "%s (%s:%u) %p<%s> refcnt %d\n", __func__, 1140 func, line, |
1139#else | 1141#else |
1140 "%s %s refcnt %d\n", __func__, | 1142 "%s %p<%s> refcnt %d\n", __func__, |
1141#endif | 1143#endif |
1142 ether_sprintf(ni->ni_macaddr), 1143 ieee80211_node_refcnt(ni)); | 1144 ni, ether_sprintf(ni->ni_macaddr), 1145 ieee80211_node_refcnt(ni)); |
1144 break; 1145 } 1146 } 1147 IEEE80211_NODE_UNLOCK(nt); 1148 return ni; 1149} 1150 1151/* --- 17 unchanged lines hidden (view full) --- 1169 IEEE80211_NODE_LOCK(nt); 1170 LIST_FOREACH(ni, &nt->nt_hash[hash], ni_hash) { 1171 if (IEEE80211_ADDR_EQ(ni->ni_macaddr, macaddr) && 1172 ni->ni_esslen == ic->ic_des_esslen && 1173 memcmp(ni->ni_essid, ic->ic_des_essid, ni->ni_esslen) == 0) { 1174 ieee80211_ref_node(ni); /* mark referenced */ 1175 IEEE80211_DPRINTF(ic, IEEE80211_MSG_NODE, 1176#ifdef IEEE80211_DEBUG_REFCNT | 1146 break; 1147 } 1148 } 1149 IEEE80211_NODE_UNLOCK(nt); 1150 return ni; 1151} 1152 1153/* --- 17 unchanged lines hidden (view full) --- 1171 IEEE80211_NODE_LOCK(nt); 1172 LIST_FOREACH(ni, &nt->nt_hash[hash], ni_hash) { 1173 if (IEEE80211_ADDR_EQ(ni->ni_macaddr, macaddr) && 1174 ni->ni_esslen == ic->ic_des_esslen && 1175 memcmp(ni->ni_essid, ic->ic_des_essid, ni->ni_esslen) == 0) { 1176 ieee80211_ref_node(ni); /* mark referenced */ 1177 IEEE80211_DPRINTF(ic, IEEE80211_MSG_NODE, 1178#ifdef IEEE80211_DEBUG_REFCNT |
1177 "%s (%s:%u) %s refcnt %d\n", __func__, func, line, | 1179 "%s (%s:%u) %p<%s> refcnt %d\n", __func__, 1180 func, line, |
1178#else | 1181#else |
1179 "%s %s refcnt %d\n", __func__, | 1182 "%s %p<%s> refcnt %d\n", __func__, |
1180#endif | 1183#endif |
1181 ether_sprintf(ni->ni_macaddr), | 1184 ni, ether_sprintf(ni->ni_macaddr), |
1182 ieee80211_node_refcnt(ni)); 1183 break; 1184 } 1185 } 1186 IEEE80211_NODE_UNLOCK(nt); 1187 return ni; 1188} 1189 | 1185 ieee80211_node_refcnt(ni)); 1186 break; 1187 } 1188 } 1189 IEEE80211_NODE_UNLOCK(nt); 1190 return ni; 1191} 1192 |
1190 | |
1191static void 1192_ieee80211_free_node(struct ieee80211_node *ni) 1193{ 1194 struct ieee80211com *ic = ni->ni_ic; 1195 struct ieee80211_node_table *nt = ni->ni_table; 1196 1197 IEEE80211_DPRINTF(ic, IEEE80211_MSG_NODE, | 1193static void 1194_ieee80211_free_node(struct ieee80211_node *ni) 1195{ 1196 struct ieee80211com *ic = ni->ni_ic; 1197 struct ieee80211_node_table *nt = ni->ni_table; 1198 1199 IEEE80211_DPRINTF(ic, IEEE80211_MSG_NODE, |
1198 "%s %s in %s table\n", __func__, ether_sprintf(ni->ni_macaddr), | 1200 "%s %p<%s> in %s table\n", __func__, ni, 1201 ether_sprintf(ni->ni_macaddr), |
1199 nt != NULL ? nt->nt_name : "<gone>"); 1200 1201 IEEE80211_AID_CLR(ni->ni_associd, ic->ic_aid_bitmap); 1202 if (nt != NULL) { 1203 TAILQ_REMOVE(&nt->nt_node, ni, ni_list); 1204 LIST_REMOVE(ni, ni_hash); 1205 } 1206 ic->ic_node_free(ni); --- 5 unchanged lines hidden (view full) --- 1212#else 1213ieee80211_free_node(struct ieee80211_node *ni) 1214#endif 1215{ 1216 struct ieee80211_node_table *nt = ni->ni_table; 1217 1218#ifdef IEEE80211_DEBUG_REFCNT 1219 IEEE80211_DPRINTF(ni->ni_ic, IEEE80211_MSG_NODE, | 1202 nt != NULL ? nt->nt_name : "<gone>"); 1203 1204 IEEE80211_AID_CLR(ni->ni_associd, ic->ic_aid_bitmap); 1205 if (nt != NULL) { 1206 TAILQ_REMOVE(&nt->nt_node, ni, ni_list); 1207 LIST_REMOVE(ni, ni_hash); 1208 } 1209 ic->ic_node_free(ni); --- 5 unchanged lines hidden (view full) --- 1215#else 1216ieee80211_free_node(struct ieee80211_node *ni) 1217#endif 1218{ 1219 struct ieee80211_node_table *nt = ni->ni_table; 1220 1221#ifdef IEEE80211_DEBUG_REFCNT 1222 IEEE80211_DPRINTF(ni->ni_ic, IEEE80211_MSG_NODE, |
1220 "%s (%s:%u) %s refcnt %d\n", __func__, func, line, | 1223 "%s (%s:%u) %p<%s> refcnt %d\n", __func__, func, line, ni, |
1221 ether_sprintf(ni->ni_macaddr), ieee80211_node_refcnt(ni)-1); 1222#endif 1223 if (ieee80211_node_dectestref(ni)) { 1224 /* 1225 * Beware; if the node is marked gone then it's already 1226 * been removed from the table and we cannot assume the 1227 * table still exists. Regardless, there's no need to lock 1228 * the table. --- 11 unchanged lines hidden (view full) --- 1240 * Reclaim a node. If this is the last reference count then 1241 * do the normal free work. Otherwise remove it from the node 1242 * table and mark it gone by clearing the back-reference. 1243 */ 1244static void 1245node_reclaim(struct ieee80211_node_table *nt, struct ieee80211_node *ni) 1246{ 1247 | 1224 ether_sprintf(ni->ni_macaddr), ieee80211_node_refcnt(ni)-1); 1225#endif 1226 if (ieee80211_node_dectestref(ni)) { 1227 /* 1228 * Beware; if the node is marked gone then it's already 1229 * been removed from the table and we cannot assume the 1230 * table still exists. Regardless, there's no need to lock 1231 * the table. --- 11 unchanged lines hidden (view full) --- 1243 * Reclaim a node. If this is the last reference count then 1244 * do the normal free work. Otherwise remove it from the node 1245 * table and mark it gone by clearing the back-reference. 1246 */ 1247static void 1248node_reclaim(struct ieee80211_node_table *nt, struct ieee80211_node *ni) 1249{ 1250 |
1251 IEEE80211_DPRINTF(ni->ni_ic, IEEE80211_MSG_NODE, 1252 "%s: remove %p<%s> from %s table, refcnt %d\n", 1253 __func__, ni, ether_sprintf(ni->ni_macaddr), 1254 nt->nt_name, ieee80211_node_refcnt(ni)-1); |
|
1248 if (!ieee80211_node_dectestref(ni)) { 1249 /* 1250 * Other references are present, just remove the 1251 * node from the table so it cannot be found. When 1252 * the references are dropped storage will be 1253 * reclaimed. 1254 */ 1255 TAILQ_REMOVE(&nt->nt_node, ni, ni_list); --- 48 unchanged lines hidden (view full) --- 1304 m_freem(ni->ni_rxfrag[0]); 1305 ni->ni_rxfrag[0] = NULL; 1306 } 1307 TAILQ_FOREACH_SAFE(ni, &nt->nt_node, ni_list, tni) { 1308 if (ni->ni_inact && --ni->ni_inact == 0) { 1309 IEEE80211_DPRINTF(ic, IEEE80211_MSG_NODE, 1310 "[%s] scan candidate purged from cache " 1311 "(refcnt %u)\n", ether_sprintf(ni->ni_macaddr), | 1255 if (!ieee80211_node_dectestref(ni)) { 1256 /* 1257 * Other references are present, just remove the 1258 * node from the table so it cannot be found. When 1259 * the references are dropped storage will be 1260 * reclaimed. 1261 */ 1262 TAILQ_REMOVE(&nt->nt_node, ni, ni_list); --- 48 unchanged lines hidden (view full) --- 1311 m_freem(ni->ni_rxfrag[0]); 1312 ni->ni_rxfrag[0] = NULL; 1313 } 1314 TAILQ_FOREACH_SAFE(ni, &nt->nt_node, ni_list, tni) { 1315 if (ni->ni_inact && --ni->ni_inact == 0) { 1316 IEEE80211_DPRINTF(ic, IEEE80211_MSG_NODE, 1317 "[%s] scan candidate purged from cache " 1318 "(refcnt %u)\n", ether_sprintf(ni->ni_macaddr), |
1312 ieee80211_node_refcnt(ni)-1); | 1319 ieee80211_node_refcnt(ni)); |
1313 node_reclaim(nt, ni); 1314 } 1315 } 1316 IEEE80211_NODE_UNLOCK(nt); 1317 1318 nt->nt_inact_timer = IEEE80211_INACT_WAIT; 1319} 1320 --- 12 unchanged lines hidden (view full) --- 1333{ 1334 struct ieee80211com *ic = nt->nt_ic; 1335 struct ieee80211_node *ni; 1336 u_int gen; 1337 1338 IEEE80211_SCAN_LOCK(nt); 1339 gen = nt->nt_scangen++; 1340 IEEE80211_DPRINTF(ic, IEEE80211_MSG_NODE, | 1320 node_reclaim(nt, ni); 1321 } 1322 } 1323 IEEE80211_NODE_UNLOCK(nt); 1324 1325 nt->nt_inact_timer = IEEE80211_INACT_WAIT; 1326} 1327 --- 12 unchanged lines hidden (view full) --- 1340{ 1341 struct ieee80211com *ic = nt->nt_ic; 1342 struct ieee80211_node *ni; 1343 u_int gen; 1344 1345 IEEE80211_SCAN_LOCK(nt); 1346 gen = nt->nt_scangen++; 1347 IEEE80211_DPRINTF(ic, IEEE80211_MSG_NODE, |
1341 "%s: sta scangen %u\n", __func__, gen); | 1348 "%s: %s scangen %u\n", __func__, nt->nt_name, gen); |
1342restart: 1343 IEEE80211_NODE_LOCK(nt); 1344 TAILQ_FOREACH(ni, &nt->nt_node, ni_list) { 1345 if (ni->ni_scangen == gen) /* previously handled */ 1346 continue; 1347 ni->ni_scangen = gen; 1348 /* 1349 * Free fragment if not needed anymore --- 521 unchanged lines hidden --- | 1349restart: 1350 IEEE80211_NODE_LOCK(nt); 1351 TAILQ_FOREACH(ni, &nt->nt_node, ni_list) { 1352 if (ni->ni_scangen == gen) /* previously handled */ 1353 continue; 1354 ni->ni_scangen = gen; 1355 /* 1356 * Free fragment if not needed anymore --- 521 unchanged lines hidden --- |