Module Name: src Committed By: knakahara Date: Thu Oct 12 09:47:22 UTC 2017
Modified Files: src/sys/net: if_pppoe.c Log Message: Integrate two locks used to protect PPPoE softc. Contributed by s-yamaguchi@IIJ. PPPOE_SESSION_LOCK protects variables used in PPP packet processing, on the other hand PPPOE_PARAM_LOCK protects the other variables used to establish a PPPoE session id. Those locks isn't acquired in the same time because the PPP packet processing doesn't work without PPPoE session id. By the reason, the locks can be integrated into PPPOE_LOCK. Add locking notes later. To generate a diff of this commit: cvs rdiff -u -r1.126 -r1.127 src/sys/net/if_pppoe.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/sys/net/if_pppoe.c diff -u src/sys/net/if_pppoe.c:1.126 src/sys/net/if_pppoe.c:1.127 --- src/sys/net/if_pppoe.c:1.126 Thu Jul 20 02:34:24 2017 +++ src/sys/net/if_pppoe.c Thu Oct 12 09:47:21 2017 @@ -1,4 +1,4 @@ -/* $NetBSD: if_pppoe.c,v 1.126 2017/07/20 02:34:24 knakahara Exp $ */ +/* $NetBSD: if_pppoe.c,v 1.127 2017/10/12 09:47:21 knakahara Exp $ */ /*- * Copyright (c) 2002, 2008 The NetBSD Foundation, Inc. @@ -30,7 +30,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: if_pppoe.c,v 1.126 2017/07/20 02:34:24 knakahara Exp $"); +__KERNEL_RCSID(0, "$NetBSD: if_pppoe.c,v 1.127 2017/10/12 09:47:21 knakahara Exp $"); #ifdef _KERNEL_OPT #include "pppoe.h" @@ -133,18 +133,12 @@ struct pppoetag { #define IFF_PASSIVE IFF_LINK0 /* wait passively for connection */ #endif -#define PPPOE_SESSION_LOCK(_sc, _op) rw_enter(&(_sc)->sc_session_lock, (_op)) -#define PPPOE_SESSION_UNLOCK(_sc) rw_exit(&(_sc)->sc_session_lock) -#define PPPOE_SESSION_LOCKED(_sc) rw_lock_held(&(_sc)->sc_session_lock) -#define PPPOE_SESSION_WLOCKED(_sc) rw_write_held(&(_sc)->sc_session_lock) -#define PPPOE_SESSION_RLOCKED(_sc) rw_read_held(&(_sc)->sc_session_lock) - -#define PPPOE_PARAM_LOCK(_sc) if ((_sc)->sc_lock) \ - mutex_enter((_sc)->sc_lock) -#define PPPOE_PARAM_UNLOCK(_sc) if ((_sc)->sc_lock) \ - mutex_exit((_sc)->sc_lock) -#define PPPOE_PARAM_LOCKED(_sc) (!(_sc)->sc_lock || \ - mutex_owned((_sc)->sc_lock)) +#define PPPOE_LOCK(_sc, _op) rw_enter(&(_sc)->sc_lock, (_op)) +#define PPPOE_UNLOCK(_sc) rw_exit(&(_sc)->sc_lock) +#define PPPOE_LOCKED(_sc) rw_lock_held(&(_sc)->sc_lock) +#define PPPOE_WLOCKED(_sc) rw_write_held(&(_sc)->sc_lock) +#define PPPOE_RLOCKED(_sc) rw_read_held(&(_sc)->sc_lock) + #ifdef PPPOE_MPSAFE #define DECLARE_SPLNET_VARIABLE #define ACQUIRE_SPLNET() do { } while (0) @@ -165,7 +159,6 @@ struct pppoe_softc { struct ifnet *sc_eth_if; /* ethernet interface we are using */ int sc_state; /* discovery phase or session connected */ - bool sc_state_updating; /* state update in other components */ struct ether_addr sc_dest; /* hardware address of concentrator */ uint16_t sc_session; /* PPPoE session id */ @@ -182,8 +175,7 @@ struct pppoe_softc { callout_t sc_timeout; /* timeout while not in session state */ int sc_padi_retried; /* number of PADI retries already done */ int sc_padr_retried; /* number of PADR retries already done */ - krwlock_t sc_session_lock; /* lock of sc_state, sc_session, and sc_eth_if */ - kmutex_t *sc_lock; /* lock of other parameters */ + krwlock_t sc_lock; /* lock of sc_state, sc_session, and sc_eth_if */ }; /* incoming traffic will be queued here */ @@ -343,8 +335,7 @@ pppoe_clone_create(struct if_clone *ifc, pfil_add_ihook(pppoe_ifattach_hook, NULL, PFIL_IFNET, if_pfil); } - sc->sc_lock = mutex_obj_alloc(MUTEX_DEFAULT, IPL_SOFTNET); - rw_init(&sc->sc_session_lock); + rw_init(&sc->sc_lock); rw_enter(&pppoe_softc_list_lock, RW_WRITER); LIST_INSERT_HEAD(&pppoe_softc_list, sc, sc_list); @@ -359,7 +350,7 @@ pppoe_clone_destroy(struct ifnet *ifp) rw_enter(&pppoe_softc_list_lock, RW_WRITER); - PPPOE_PARAM_LOCK(sc); + PPPOE_LOCK(sc, RW_WRITER); callout_halt(&sc->sc_timeout, NULL); LIST_REMOVE(sc, sc_list); @@ -369,7 +360,6 @@ pppoe_clone_destroy(struct ifnet *ifp) } rw_exit(&pppoe_softc_list_lock); - PPPOE_SESSION_LOCK(sc, RW_WRITER); bpf_detach(ifp); sppp_detach(&sc->sc_sppp.pp_if); @@ -384,11 +374,8 @@ pppoe_clone_destroy(struct ifnet *ifp) free(sc->sc_relay_sid, M_DEVBUF); callout_destroy(&sc->sc_timeout); - PPPOE_PARAM_UNLOCK(sc); - if (sc->sc_lock) - mutex_obj_free(sc->sc_lock); - PPPOE_SESSION_UNLOCK(sc); - rw_destroy(&sc->sc_session_lock); + PPPOE_UNLOCK(sc); + rw_destroy(&sc->sc_lock); free(sc, M_DEVBUF); @@ -410,14 +397,13 @@ pppoe_find_softc_by_session(u_int sessio return NULL; rw_enter(&pppoe_softc_list_lock, RW_READER); LIST_FOREACH(sc, &pppoe_softc_list, sc_list) { - PPPOE_SESSION_LOCK(sc, lock); - if (!sc->sc_state_updating - && sc->sc_state == PPPOE_STATE_SESSION + PPPOE_LOCK(sc, lock); + if ( sc->sc_state == PPPOE_STATE_SESSION && sc->sc_session == session && sc->sc_eth_if == rcvif) break; - PPPOE_SESSION_UNLOCK(sc); + PPPOE_UNLOCK(sc); } rw_exit(&pppoe_softc_list_lock); return sc; @@ -441,7 +427,7 @@ pppoe_find_softc_by_hunique(uint8_t *tok rw_enter(&pppoe_softc_list_lock, RW_READER); LIST_FOREACH(sc, &pppoe_softc_list, sc_list) { if (sc == t) { - PPPOE_SESSION_LOCK(sc, lock); + PPPOE_LOCK(sc, lock); break; } } @@ -454,26 +440,17 @@ pppoe_find_softc_by_hunique(uint8_t *tok return NULL; } - if (sc->sc_state_updating) { -#ifdef PPPOE_DEBUG - printf("%s: host unique tag found, but its state is updating\n", - sc->sc_sppp.pp_if.if_xname); -#endif - PPPOE_SESSION_UNLOCK(sc); - return NULL; - } - /* should be safe to access *sc now */ if (sc->sc_state < PPPOE_STATE_PADI_SENT || sc->sc_state >= PPPOE_STATE_SESSION) { printf("%s: host unique tag found, but it belongs to a connection in state %d\n", sc->sc_sppp.pp_if.if_xname, sc->sc_state); - PPPOE_SESSION_UNLOCK(sc); + PPPOE_UNLOCK(sc); return NULL; } if (sc->sc_eth_if != rcvif) { printf("%s: wrong interface, not accepting host unique\n", sc->sc_sppp.pp_if.if_xname); - PPPOE_SESSION_UNLOCK(sc); + PPPOE_UNLOCK(sc); return NULL; } return sc; @@ -664,7 +641,7 @@ pppoe_dispatch_disc_pkt(struct mbuf *m, if (sc != NULL) { strlcpy(devname, sc->sc_sppp.pp_if.if_xname, sizeof(devname)); - PPPOE_SESSION_UNLOCK(sc); + PPPOE_UNLOCK(sc); } break; } @@ -744,21 +721,20 @@ breakbreak:; goto done; rw_enter(&pppoe_softc_list_lock, RW_READER); LIST_FOREACH(sc, &pppoe_softc_list, sc_list) { - PPPOE_SESSION_LOCK(sc, RW_WRITER); + PPPOE_LOCK(sc, RW_WRITER); if (!(sc->sc_sppp.pp_if.if_flags & IFF_UP)) { - PPPOE_SESSION_UNLOCK(sc); + PPPOE_UNLOCK(sc); continue; } if (!(sc->sc_sppp.pp_if.if_flags & IFF_PASSIVE)) { - PPPOE_SESSION_UNLOCK(sc); + PPPOE_UNLOCK(sc); continue; } - if (!sc->sc_state_updating - && sc->sc_state == PPPOE_STATE_INITIAL) + if (sc->sc_state == PPPOE_STATE_INITIAL) break; - PPPOE_SESSION_UNLOCK(sc); + PPPOE_UNLOCK(sc); } rw_exit(&pppoe_softc_list_lock); @@ -767,15 +743,13 @@ breakbreak:; goto done; } - PPPOE_PARAM_LOCK(sc); if (hunique) { if (sc->sc_hunique) free(sc->sc_hunique, M_DEVBUF); sc->sc_hunique = malloc(hunique_len, M_DEVBUF, M_DONTWAIT); if (sc->sc_hunique == NULL) { - PPPOE_PARAM_UNLOCK(sc); - PPPOE_SESSION_UNLOCK(sc); + PPPOE_UNLOCK(sc); goto done; } sc->sc_hunique_len = hunique_len; @@ -784,8 +758,7 @@ breakbreak:; memcpy(&sc->sc_dest, eh->ether_shost, sizeof sc->sc_dest); sc->sc_state = PPPOE_STATE_PADO_SENT; pppoe_send_pado(sc); - PPPOE_PARAM_UNLOCK(sc); - PPPOE_SESSION_UNLOCK(sc); + PPPOE_UNLOCK(sc); break; #endif /* PPPOE_SERVER */ case PPPOE_CODE_PADR: @@ -817,22 +790,20 @@ breakbreak:; goto done; } - if (sc->sc_state_updating - || sc->sc_state != PPPOE_STATE_PADO_SENT) { + if (sc->sc_state != PPPOE_STATE_PADO_SENT) { printf("%s: received unexpected PADR\n", sc->sc_sppp.pp_if.if_xname); - PPPOE_SESSION_UNLOCK(sc); + PPPOE_UNLOCK(sc); goto done; } - PPPOE_PARAM_LOCK(sc); + if (hunique) { if (sc->sc_hunique) free(sc->sc_hunique, M_DEVBUF); sc->sc_hunique = malloc(hunique_len, M_DEVBUF, M_DONTWAIT); if (sc->sc_hunique == NULL) { - PPPOE_PARAM_UNLOCK(sc); - PPPOE_SESSION_UNLOCK(sc); + PPPOE_UNLOCK(sc); goto done; } sc->sc_hunique_len = hunique_len; @@ -840,8 +811,7 @@ breakbreak:; } pppoe_send_pads(sc); sc->sc_state = PPPOE_STATE_SESSION; - PPPOE_PARAM_UNLOCK(sc); - PPPOE_SESSION_UNLOCK(sc); + PPPOE_UNLOCK(sc); sppp_lock_enter(&sc->sc_sppp); sc->sc_sppp.pp_up(&sc->sc_sppp); @@ -860,17 +830,15 @@ breakbreak:; goto done; } - PPPOE_SESSION_LOCK(sc, RW_WRITER); + PPPOE_LOCK(sc, RW_WRITER); - if (sc->sc_state_updating - || sc->sc_state != PPPOE_STATE_PADI_SENT) { + if (sc->sc_state != PPPOE_STATE_PADI_SENT) { printf("%s: received unexpected PADO\n", sc->sc_sppp.pp_if.if_xname); - PPPOE_SESSION_UNLOCK(sc); + PPPOE_UNLOCK(sc); goto done; } - PPPOE_PARAM_LOCK(sc); if (ac_cookie) { if (sc->sc_ac_cookie) free(sc->sc_ac_cookie, M_DEVBUF); @@ -880,8 +848,7 @@ breakbreak:; printf("%s: FATAL: could not allocate memory " "for AC cookie\n", sc->sc_sppp.pp_if.if_xname); - PPPOE_PARAM_UNLOCK(sc); - PPPOE_SESSION_UNLOCK(sc); + PPPOE_UNLOCK(sc); goto done; } sc->sc_ac_cookie_len = ac_cookie_len; @@ -896,8 +863,7 @@ breakbreak:; printf("%s: FATAL: could not allocate memory " "for relay SID\n", sc->sc_sppp.pp_if.if_xname); - PPPOE_PARAM_UNLOCK(sc); - PPPOE_SESSION_UNLOCK(sc); + PPPOE_UNLOCK(sc); goto done; } sc->sc_relay_sid_len = relay_sid_len; @@ -917,21 +883,13 @@ breakbreak:; PPPOE_DISC_TIMEOUT * (1 + sc->sc_padr_retried), pppoe_timeout, sc); - PPPOE_PARAM_UNLOCK(sc); - PPPOE_SESSION_UNLOCK(sc); + PPPOE_UNLOCK(sc); break; case PPPOE_CODE_PADS: if (sc == NULL) goto done; - PPPOE_SESSION_LOCK(sc, RW_WRITER); - PPPOE_PARAM_LOCK(sc); - - if (sc->sc_state_updating) { - PPPOE_PARAM_UNLOCK(sc); - PPPOE_SESSION_UNLOCK(sc); - goto done; - } + PPPOE_LOCK(sc, RW_WRITER); sc->sc_session = session; callout_stop(&sc->sc_timeout); @@ -939,8 +897,7 @@ breakbreak:; printf("%s: session 0x%x connected\n", sc->sc_sppp.pp_if.if_xname, session); sc->sc_state = PPPOE_STATE_SESSION; - PPPOE_PARAM_UNLOCK(sc); - PPPOE_SESSION_UNLOCK(sc); + PPPOE_UNLOCK(sc); sppp_lock_enter(&sc->sc_sppp); sc->sc_sppp.pp_up(&sc->sc_sppp); /* notify upper layers */ @@ -959,18 +916,16 @@ breakbreak:; if (sc == NULL) goto done; - PPPOE_PARAM_LOCK(sc); pppoe_clear_softc(sc, "received PADT"); - PPPOE_PARAM_UNLOCK(sc); - PPPOE_SESSION_UNLOCK(sc); + PPPOE_UNLOCK(sc); break; } default: if (sc != NULL) { - PPPOE_SESSION_LOCK(sc, RW_READER); + PPPOE_LOCK(sc, RW_READER); strlcpy(devname, sc->sc_sppp.pp_if.if_xname, sizeof(devname)); - PPPOE_SESSION_UNLOCK(sc); + PPPOE_UNLOCK(sc); } else strlcpy(devname, "pppoe", sizeof(devname)); @@ -1074,7 +1029,7 @@ pppoe_data_input(struct mbuf *m) printf("\n"); } #endif - PPPOE_SESSION_UNLOCK(sc); + PPPOE_UNLOCK(sc); if (m->m_pkthdr.len < plen) goto drop; @@ -1098,8 +1053,7 @@ pppoe_output(struct pppoe_softc *sc, str struct ether_header *eh; uint16_t etype; - KASSERT(PPPOE_SESSION_LOCKED(sc)); - KASSERT(PPPOE_PARAM_LOCKED(sc)); + KASSERT(PPPOE_LOCKED(sc)); if (sc->sc_eth_if == NULL) { m_freem(m); @@ -1144,11 +1098,11 @@ pppoe_ioctl(struct ifnet *ifp, unsigned if (parms->eth_ifname[0] != 0) { struct ifnet *eth_if; - PPPOE_SESSION_LOCK(sc, RW_WRITER); + PPPOE_LOCK(sc, RW_WRITER); eth_if = ifunit(parms->eth_ifname); if (eth_if == NULL || eth_if->if_dlt != DLT_EN10MB) { sc->sc_eth_if = NULL; - PPPOE_SESSION_UNLOCK(sc); + PPPOE_UNLOCK(sc); return ENXIO; } @@ -1158,7 +1112,7 @@ pppoe_ioctl(struct ifnet *ifp, unsigned PPPOE_OVERHEAD; } sc->sc_eth_if = eth_if; - PPPOE_SESSION_UNLOCK(sc); + PPPOE_UNLOCK(sc); } if (parms->ac_name != NULL) { size_t s; @@ -1177,11 +1131,11 @@ pppoe_ioctl(struct ifnet *ifp, unsigned return EINVAL; } - PPPOE_PARAM_LOCK(sc); + PPPOE_LOCK(sc, RW_WRITER); if (sc->sc_concentrator_name) free(sc->sc_concentrator_name, M_DEVBUF); sc->sc_concentrator_name = b; - PPPOE_PARAM_UNLOCK(sc); + PPPOE_UNLOCK(sc); } if (parms->service_name != NULL) { size_t s; @@ -1200,11 +1154,11 @@ pppoe_ioctl(struct ifnet *ifp, unsigned return EINVAL; } - PPPOE_PARAM_LOCK(sc); + PPPOE_LOCK(sc, RW_WRITER); if (sc->sc_service_name) free(sc->sc_service_name, M_DEVBUF); sc->sc_service_name = b; - PPPOE_PARAM_UNLOCK(sc); + PPPOE_UNLOCK(sc); } return 0; } @@ -1213,25 +1167,23 @@ pppoe_ioctl(struct ifnet *ifp, unsigned { struct pppoediscparms *parms = (struct pppoediscparms*)data; memset(parms, 0, sizeof *parms); - PPPOE_SESSION_LOCK(sc, RW_READER); + PPPOE_LOCK(sc, RW_READER); if (sc->sc_eth_if) strlcpy(parms->ifname, sc->sc_eth_if->if_xname, sizeof(parms->ifname)); - PPPOE_SESSION_UNLOCK(sc); + PPPOE_UNLOCK(sc); return 0; } break; case PPPOEGETSESSION: { struct pppoeconnectionstate *state = (struct pppoeconnectionstate*)data; - PPPOE_SESSION_LOCK(sc, RW_READER); - PPPOE_PARAM_LOCK(sc); + PPPOE_LOCK(sc, RW_READER); state->state = sc->sc_state; state->session_id = sc->sc_session; state->padi_retry_no = sc->sc_padi_retried; state->padr_retry_no = sc->sc_padr_retried; - PPPOE_PARAM_UNLOCK(sc); - PPPOE_SESSION_UNLOCK(sc); + PPPOE_UNLOCK(sc); return 0; } break; @@ -1240,8 +1192,7 @@ pppoe_ioctl(struct ifnet *ifp, unsigned * Prevent running re-establishment timers overriding * administrators choice. */ - PPPOE_SESSION_LOCK(sc, RW_WRITER); - PPPOE_PARAM_LOCK(sc); + PPPOE_LOCK(sc, RW_WRITER); if ((ifr->ifr_flags & IFF_UP) == 0 && sc->sc_state >= PPPOE_STATE_PADI_SENT @@ -1252,18 +1203,12 @@ pppoe_ioctl(struct ifnet *ifp, unsigned sc->sc_padr_retried = 0; memcpy(&sc->sc_dest, etherbroadcastaddr, sizeof(sc->sc_dest)); - sc->sc_state_updating = 1; } - PPPOE_PARAM_UNLOCK(sc); - PPPOE_SESSION_UNLOCK(sc); + PPPOE_UNLOCK(sc); error = sppp_ioctl(ifp, cmd, data); - PPPOE_SESSION_LOCK(sc, RW_WRITER); - sc->sc_state_updating = 0; - PPPOE_SESSION_UNLOCK(sc); - return error; case SIOCSIFMTU: if (ifr->ifr_mtu > (sc->sc_eth_if == NULL ? @@ -1312,8 +1257,7 @@ pppoe_send_padi(struct pppoe_softc *sc) int len, l1 = 0, l2 = 0; /* XXX: gcc */ uint8_t *p; - KASSERT(PPPOE_SESSION_LOCKED(sc)); - KASSERT(PPPOE_PARAM_LOCKED(sc)); + KASSERT(PPPOE_LOCKED(sc)); if (sc->sc_state >PPPOE_STATE_PADI_SENT) panic("pppoe_send_padi in state %d", sc->sc_state); @@ -1386,8 +1330,7 @@ pppoe_timeout(void *arg) printf("%s: timeout\n", sc->sc_sppp.pp_if.if_xname); #endif - PPPOE_SESSION_LOCK(sc, RW_WRITER); - PPPOE_PARAM_LOCK(sc); + PPPOE_LOCK(sc, RW_WRITER); switch (sc->sc_state) { case PPPOE_STATE_INITIAL: /* delayed connect from pppoe_tls() */ @@ -1416,8 +1359,7 @@ pppoe_timeout(void *arg) } else { pppoe_abort_connect(sc); RELEASE_SPLNET(); - PPPOE_PARAM_UNLOCK(sc); - PPPOE_SESSION_UNLOCK(sc); + PPPOE_UNLOCK(sc); return; } } @@ -1452,8 +1394,7 @@ pppoe_timeout(void *arg) PPPOE_DISC_TIMEOUT * (1 + sc->sc_padi_retried), pppoe_timeout, sc); RELEASE_SPLNET(); - PPPOE_PARAM_UNLOCK(sc); - PPPOE_SESSION_UNLOCK(sc); + PPPOE_UNLOCK(sc); return; } if ((err = pppoe_send_padr(sc)) != 0) { @@ -1472,12 +1413,10 @@ pppoe_timeout(void *arg) pppoe_disconnect(sc); break; default: - PPPOE_PARAM_UNLOCK(sc); - PPPOE_SESSION_UNLOCK(sc); + PPPOE_UNLOCK(sc); return; /* all done, work in peace */ } - PPPOE_PARAM_UNLOCK(sc); - PPPOE_SESSION_UNLOCK(sc); + PPPOE_UNLOCK(sc); } /* Start a connection (i.e. initiate discovery phase) */ @@ -1487,8 +1426,7 @@ pppoe_connect(struct pppoe_softc *sc) int err; DECLARE_SPLNET_VARIABLE; - KASSERT(PPPOE_SESSION_WLOCKED(sc)); - KASSERT(PPPOE_PARAM_LOCKED(sc)); + KASSERT(PPPOE_WLOCKED(sc)); if (sc->sc_state != PPPOE_STATE_INITIAL) return EBUSY; @@ -1518,8 +1456,7 @@ pppoe_disconnect(struct pppoe_softc *sc) int err; DECLARE_SPLNET_VARIABLE; - KASSERT(PPPOE_SESSION_WLOCKED(sc)); - KASSERT(PPPOE_PARAM_LOCKED(sc)); + KASSERT(PPPOE_WLOCKED(sc)); ACQUIRE_SPLNET(); @@ -1534,7 +1471,6 @@ pppoe_disconnect(struct pppoe_softc *sc) /* cleanup softc */ sc->sc_state = PPPOE_STATE_INITIAL; - sc->sc_state_updating = 1; memcpy(&sc->sc_dest, etherbroadcastaddr, sizeof(sc->sc_dest)); if (sc->sc_ac_cookie) { @@ -1556,17 +1492,14 @@ pppoe_disconnect(struct pppoe_softc *sc) #endif sc->sc_session = 0; - PPPOE_PARAM_UNLOCK(sc); - PPPOE_SESSION_UNLOCK(sc); + PPPOE_UNLOCK(sc); /* notify upper layer */ sppp_lock_enter(&sc->sc_sppp); sc->sc_sppp.pp_down(&sc->sc_sppp); sppp_lock_exit(&sc->sc_sppp); - PPPOE_SESSION_LOCK(sc, RW_WRITER); - PPPOE_PARAM_LOCK(sc); - sc->sc_state_updating = 0; + PPPOE_LOCK(sc, RW_WRITER); RELEASE_SPLNET(); return err; @@ -1576,26 +1509,20 @@ pppoe_disconnect(struct pppoe_softc *sc) static void pppoe_abort_connect(struct pppoe_softc *sc) { - KASSERT(PPPOE_SESSION_WLOCKED(sc)); - KASSERT(PPPOE_PARAM_LOCKED(sc)); + KASSERT(PPPOE_WLOCKED(sc)); printf("%s: could not establish connection\n", sc->sc_sppp.pp_if.if_xname); sc->sc_state = PPPOE_STATE_CLOSING; - sc->sc_state_updating = 1; - PPPOE_PARAM_UNLOCK(sc); - PPPOE_SESSION_UNLOCK(sc); + PPPOE_UNLOCK(sc); /* notify upper layer */ sppp_lock_enter(&sc->sc_sppp); sc->sc_sppp.pp_down(&sc->sc_sppp); sppp_lock_exit(&sc->sc_sppp); - PPPOE_SESSION_LOCK(sc, RW_WRITER); - PPPOE_PARAM_LOCK(sc); - - sc->sc_state_updating = 0; + PPPOE_LOCK(sc, RW_WRITER); /* clear connection state */ memcpy(&sc->sc_dest, etherbroadcastaddr, sizeof(sc->sc_dest)); @@ -1610,8 +1537,7 @@ pppoe_send_padr(struct pppoe_softc *sc) uint8_t *p; size_t len, l1 = 0; /* XXX: gcc */ - KASSERT(PPPOE_SESSION_LOCKED(sc)); - KASSERT(PPPOE_PARAM_LOCKED(sc)); + KASSERT(PPPOE_LOCKED(sc)); if (sc->sc_state != PPPOE_STATE_PADR_SENT) return EIO; @@ -1706,8 +1632,7 @@ pppoe_send_pado(struct pppoe_softc *sc) uint8_t *p; size_t len; - KASSERT(PPPOE_SESSION_LOCKED(sc)); /* required by pppoe_output(). */ - KASSERT(PPPOE_PARAM_LOCKED(sc)); + KASSERT(PPPOE_LOCKED(sc)); /* required by pppoe_output(). */ if (sc->sc_state != PPPOE_STATE_PADO_SENT) return EIO; @@ -1741,8 +1666,7 @@ pppoe_send_pads(struct pppoe_softc *sc) uint8_t *p; size_t len, l1 = 0; /* XXX: gcc */ - KASSERT(PPPOE_SESSION_WLOCKED(sc)); - KASSERT(PPPOE_PARAM_LOCKED(sc)); + KASSERT(PPPOE_WLOCKED(sc)); if (sc->sc_state != PPPOE_STATE_PADO_SENT) return EIO; @@ -1783,18 +1707,15 @@ pppoe_tls(struct sppp *sp) struct pppoe_softc *sc = (void *)sp; int wtime; - KASSERT(!PPPOE_SESSION_LOCKED(sc)); - KASSERT(!PPPOE_PARAM_LOCKED(sc)); + KASSERT(!PPPOE_LOCKED(sc)); - PPPOE_SESSION_LOCK(sc, RW_READER); + PPPOE_LOCK(sc, RW_READER); if (sc->sc_state != PPPOE_STATE_INITIAL) { - PPPOE_SESSION_UNLOCK(sc); + PPPOE_UNLOCK(sc); return; } - PPPOE_PARAM_LOCK(sc); - if (sc->sc_sppp.pp_phase == SPPP_PHASE_ESTABLISH && sc->sc_sppp.pp_auth_failures > 0) { /* @@ -1809,8 +1730,7 @@ pppoe_tls(struct sppp *sp) } callout_reset(&sc->sc_timeout, wtime, pppoe_timeout, sc); - PPPOE_PARAM_UNLOCK(sc); - PPPOE_SESSION_UNLOCK(sc); + PPPOE_UNLOCK(sc); } static void @@ -1818,13 +1738,12 @@ pppoe_tlf(struct sppp *sp) { struct pppoe_softc *sc = (void *)sp; - KASSERT(!PPPOE_SESSION_LOCKED(sc)); - KASSERT(!PPPOE_PARAM_LOCKED(sc)); + KASSERT(!PPPOE_LOCKED(sc)); - PPPOE_SESSION_LOCK(sc, RW_WRITER); + PPPOE_LOCK(sc, RW_WRITER); if (sc->sc_state < PPPOE_STATE_SESSION) { - PPPOE_SESSION_UNLOCK(sc); + PPPOE_UNLOCK(sc); return; } /* @@ -1833,12 +1752,10 @@ pppoe_tlf(struct sppp *sp) * function and defer disconnecting to the timeout handler. */ sc->sc_state = PPPOE_STATE_CLOSING; - PPPOE_PARAM_LOCK(sc); callout_reset(&sc->sc_timeout, hz/50, pppoe_timeout, sc); - PPPOE_PARAM_UNLOCK(sc); - PPPOE_SESSION_UNLOCK(sc); + PPPOE_UNLOCK(sc); } static void @@ -1853,8 +1770,10 @@ pppoe_start(struct ifnet *ifp) return; /* are we ready to process data yet? */ + PPPOE_LOCK(sc, RW_READER); if (sc->sc_state < PPPOE_STATE_SESSION) { sppp_flush(&sc->sc_sppp.pp_if); + PPPOE_UNLOCK(sc); return; } @@ -1866,16 +1785,13 @@ pppoe_start(struct ifnet *ifp) continue; } p = mtod(m, uint8_t *); - PPPOE_SESSION_LOCK(sc, RW_READER); PPPOE_ADD_HEADER(p, 0, sc->sc_session, len); bpf_mtap(&sc->sc_sppp.pp_if, m); - PPPOE_PARAM_LOCK(sc); pppoe_output(sc, m); - PPPOE_PARAM_UNLOCK(sc); - PPPOE_SESSION_UNLOCK(sc); } + PPPOE_UNLOCK(sc); } #ifdef PPPOE_MPSAFE @@ -1890,9 +1806,9 @@ pppoe_transmit(struct ifnet *ifp, struct return EINVAL; /* are we ready to process data yet? */ - PPPOE_SESSION_LOCK(sc, RW_READER); + PPPOE_LOCK(sc, RW_READER); if (sc->sc_state < PPPOE_STATE_SESSION) { - PPPOE_SESSION_UNLOCK(sc); + PPPOE_UNLOCK(sc); m_free(m); return ENOBUFS; } @@ -1900,7 +1816,7 @@ pppoe_transmit(struct ifnet *ifp, struct len = m->m_pkthdr.len; M_PREPEND(m, PPPOE_HEADERLEN, M_DONTWAIT); if (m == NULL) { - PPPOE_SESSION_UNLOCK(sc); + PPPOE_UNLOCK(sc); ifp->if_oerrors++; return ENETDOWN; } @@ -1909,10 +1825,8 @@ pppoe_transmit(struct ifnet *ifp, struct bpf_mtap(&sc->sc_sppp.pp_if, m); - PPPOE_PARAM_LOCK(sc); pppoe_output(sc, m); - PPPOE_PARAM_UNLOCK(sc); - PPPOE_SESSION_UNLOCK(sc); + PPPOE_UNLOCK(sc); return 0; } #endif /* PPPOE_MPSAFE */ @@ -1930,9 +1844,9 @@ pppoe_ifattach_hook(void *arg, unsigned ACQUIRE_SPLNET(); rw_enter(&pppoe_softc_list_lock, RW_READER); LIST_FOREACH(sc, &pppoe_softc_list, sc_list) { - PPPOE_SESSION_LOCK(sc, RW_WRITER); + PPPOE_LOCK(sc, RW_WRITER); if (sc->sc_eth_if != ifp) { - PPPOE_SESSION_UNLOCK(sc); + PPPOE_UNLOCK(sc); continue; } sppp_lock_enter(&sc->sc_sppp); @@ -1943,10 +1857,8 @@ pppoe_ifattach_hook(void *arg, unsigned } sppp_lock_exit(&sc->sc_sppp); sc->sc_eth_if = NULL; - PPPOE_PARAM_LOCK(sc); pppoe_clear_softc(sc, "ethernet interface detached"); - PPPOE_PARAM_UNLOCK(sc); - PPPOE_SESSION_UNLOCK(sc); + PPPOE_UNLOCK(sc); } rw_exit(&pppoe_softc_list_lock); RELEASE_SPLNET(); @@ -1955,8 +1867,7 @@ pppoe_ifattach_hook(void *arg, unsigned static void pppoe_clear_softc(struct pppoe_softc *sc, const char *message) { - KASSERT(PPPOE_SESSION_WLOCKED(sc)); - KASSERT(PPPOE_PARAM_LOCKED(sc)); + KASSERT(PPPOE_WLOCKED(sc)); /* stop timer */ callout_stop(&sc->sc_timeout); @@ -1966,20 +1877,15 @@ pppoe_clear_softc(struct pppoe_softc *sc /* fix our state */ sc->sc_state = PPPOE_STATE_INITIAL; - sc->sc_state_updating = 1; - PPPOE_PARAM_UNLOCK(sc); - PPPOE_SESSION_UNLOCK(sc); + PPPOE_UNLOCK(sc); /* signal upper layer */ sppp_lock_enter(&sc->sc_sppp); sc->sc_sppp.pp_down(&sc->sc_sppp); sppp_lock_exit(&sc->sc_sppp); - PPPOE_SESSION_LOCK(sc, RW_WRITER); - PPPOE_PARAM_LOCK(sc); - - sc->sc_state_updating = 0; + PPPOE_LOCK(sc, RW_WRITER); /* clean up softc */ memcpy(&sc->sc_dest, etherbroadcastaddr, sizeof(sc->sc_dest));