X-Git-Url: https://git.ozlabs.org/?a=blobdiff_plain;f=solaris%2Fppp.c;h=98f4f91b297d922139de8781ecba4bd4bdb8d897;hb=b2c36e6c0e1655aea9b1b0a03a8160f42a26c884;hp=85d7fc70643b78f4b30f075d76b95755a9fc9d4d;hpb=69dda243ba613a88ffd951de15b6906e14c49a65;p=ppp.git diff --git a/solaris/ppp.c b/solaris/ppp.c index 85d7fc7..98f4f91 100644 --- a/solaris/ppp.c +++ b/solaris/ppp.c @@ -31,8 +31,6 @@ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - * - * $Id: ppp.c,v 1.3 2004/11/15 00:57:54 carlsonj Exp $ */ /* @@ -85,12 +83,6 @@ #include /* leave this outside of PRIOQ for htons */ -#ifdef __STDC__ -#define __P(x) x -#else -#define __P(x) () -#endif - /* * The IP module may use this SAP value for IP packets. */ @@ -254,43 +246,45 @@ static upperstr_t *minor_devs = NULL; static upperstr_t *ppas = NULL; #ifdef SVR4 -static int pppopen __P((queue_t *, dev_t *, int, int, cred_t *)); -static int pppclose __P((queue_t *, int, cred_t *)); +static int pppopen(queue_t *, dev_t *, int, int, cred_t *); +static int pppclose(queue_t *, int, cred_t *); #else -static int pppopen __P((queue_t *, int, int, int)); -static int pppclose __P((queue_t *, int)); +static int pppopen(queue_t *, int, int, int); +static int pppclose(queue_t *, int); #endif /* SVR4 */ -static int pppurput __P((queue_t *, mblk_t *)); -static int pppuwput __P((queue_t *, mblk_t *)); -static int pppursrv __P((queue_t *)); -static int pppuwsrv __P((queue_t *)); -static int ppplrput __P((queue_t *, mblk_t *)); -static int ppplwput __P((queue_t *, mblk_t *)); -static int ppplrsrv __P((queue_t *)); -static int ppplwsrv __P((queue_t *)); +static int pppurput(queue_t *, mblk_t *); +static int pppuwput(queue_t *, mblk_t *); +static int pppursrv(queue_t *); +static int pppuwsrv(queue_t *); +static int ppplrput(queue_t *, mblk_t *); +static int ppplwput(queue_t *, mblk_t *); +static int ppplrsrv(queue_t *); +static int ppplwsrv(queue_t *); #ifndef NO_DLPI -static void dlpi_request __P((queue_t *, mblk_t *, upperstr_t *)); -static void dlpi_error __P((queue_t *, upperstr_t *, int, int, int)); -static void dlpi_ok __P((queue_t *, int)); +static void dlpi_request(queue_t *, mblk_t *, upperstr_t *); +static void dlpi_error(queue_t *, upperstr_t *, int, int, int); +static void dlpi_ok(queue_t *, int); #endif -static int send_data __P((mblk_t *, upperstr_t *)); -static void new_ppa __P((queue_t *, mblk_t *)); -static void attach_ppa __P((queue_t *, mblk_t *)); -static void detach_ppa __P((queue_t *, mblk_t *)); -static void detach_lower __P((queue_t *, mblk_t *)); -static void debug_dump __P((queue_t *, mblk_t *)); -static upperstr_t *find_dest __P((upperstr_t *, int)); +static int send_data(mblk_t *, upperstr_t *); +static void new_ppa(queue_t *, mblk_t *); +static void attach_ppa(queue_t *, mblk_t *); +#ifndef NO_DLPI +static void detach_ppa(queue_t *, mblk_t *); +#endif +static void detach_lower(queue_t *, mblk_t *); +static void debug_dump(queue_t *, mblk_t *); +static upperstr_t *find_dest(upperstr_t *, int); #if defined(SOL2) -static upperstr_t *find_promisc __P((upperstr_t *, int)); -static mblk_t *prepend_ether __P((upperstr_t *, mblk_t *, int)); -static mblk_t *prepend_udind __P((upperstr_t *, mblk_t *, int)); -static void promisc_sendup __P((upperstr_t *, mblk_t *, int, int)); +static upperstr_t *find_promisc(upperstr_t *, int); +static mblk_t *prepend_ether(upperstr_t *, mblk_t *, int); +static mblk_t *prepend_udind(upperstr_t *, mblk_t *, int); +static void promisc_sendup(upperstr_t *, mblk_t *, int, int); #endif /* defined(SOL2) */ -static int putctl2 __P((queue_t *, int, int, int)); -static int putctl4 __P((queue_t *, int, int, int)); -static int pass_packet __P((upperstr_t *ppa, mblk_t *mp, int outbound)); +static int putctl2(queue_t *, int, int, int); +static int putctl4(queue_t *, int, int, int); +static int pass_packet(upperstr_t *ppa, mblk_t *mp, int outbound); #ifdef FILTER_PACKETS -static int ip_hard_filter __P((upperstr_t *ppa, mblk_t *mp, int outbound)); +static int ip_hard_filter(upperstr_t *ppa, mblk_t *mp, int outbound); #endif /* FILTER_PACKETS */ #define PPP_ID 0xb1a6 @@ -645,11 +639,12 @@ pppuwput(q, mp) break; } #ifdef NO_DLPI + /* pass_packet frees the packet on returning 0 */ if ((us->flags & US_CONTROL) == 0 && !pass_packet(us, mp, 1)) break; #endif - if (!send_data(mp, us)) - putq(q, mp); + if (!send_data(mp, us) && !putq(q, mp)) + freemsg(mp); break; case M_IOCTL: @@ -722,6 +717,7 @@ pppuwput(q, mp) #endif iop->ioc_count = 0; qwriter(q, mp, detach_lower, PERIM_OUTER); + /* mp is now gone */ error = -1; break; @@ -748,6 +744,7 @@ pppuwput(q, mp) iop->ioc_count = sizeof(int); mq->b_wptr = mq->b_rptr + sizeof(int); qwriter(q, mp, new_ppa, PERIM_OUTER); + /* mp is now gone */ error = -1; break; @@ -769,6 +766,7 @@ pppuwput(q, mp) us->ppa = ppa; iop->ioc_count = 0; qwriter(q, mp, attach_ppa, PERIM_OUTER); + /* mp is now gone */ error = -1; break; @@ -851,8 +849,8 @@ pppuwput(q, mp) } n = *(int *)mp->b_cont->b_rptr; if (n == PPPDBG_DUMP + PPPDBG_DRIVER) { - qwriter(q, NULL, debug_dump, PERIM_OUTER); - iop->ioc_count = 0; + qwriter(q, mp, debug_dump, PERIM_OUTER); + /* mp is now gone */ error = -1; } else if (n == PPPDBG_LOG + PPPDBG_DRIVER) { DPRINT1("ppp/%d: debug log enabled\n", us->mn); @@ -863,6 +861,7 @@ pppuwput(q, mp) if (us->ppa == 0 || us->ppa->lowerq == 0) break; putnext(us->ppa->lowerq, mp); + /* mp is now gone */ error = -1; } break; @@ -1010,7 +1009,8 @@ pppuwput(q, mp) ((union DL_primitives *)mq->b_rptr)->dl_primitive = DL_INFO_REQ; mq->b_wptr = mq->b_rptr + sizeof(dl_info_req_t); dlpi_request(q, mq, us); - error = 0; + /* mp is now gone */ + error = -1; break; case SIOCGIFNETMASK: @@ -1345,9 +1345,10 @@ dlpi_request(q, mp, us) mp->b_rptr[1] = PPP_UI; mp->b_rptr[2] = us->sap >> 8; mp->b_rptr[3] = us->sap; + /* pass_packet frees the packet on returning 0 */ if (pass_packet(us, mp, 1)) { - if (!send_data(mp, us)) - putq(q, mp); + if (!send_data(mp, us) && !putq(q, mp)) + freemsg(mp); } return; @@ -1484,6 +1485,9 @@ dlpi_ok(q, prim) } #endif /* NO_DLPI */ +/* + * If return value is 0, then the packet has already been freed. + */ static int pass_packet(us, mp, outbound) upperstr_t *us; @@ -1676,9 +1680,11 @@ attach_ppa(q, mp) #ifndef NO_DLPI dlpi_ok(q, DL_ATTACH_REQ); #endif + freemsg(mp); } } +#ifndef NO_DLPI static void detach_ppa(q, mp) queue_t *q; @@ -1699,11 +1705,11 @@ detach_ppa(q, mp) } us->next = 0; us->ppa = 0; -#ifndef NO_DLPI us->state = DL_UNATTACHED; dlpi_ok(q, DL_DETACH_REQ); -#endif + freemsg(mp); } +#endif /* * We call this with qwriter in order to give the upper queue procedures @@ -1873,53 +1879,54 @@ pppurput(q, mp) putnext(ppa->q, mp); break; - default: - if (mp->b_datap->db_type == M_DATA) { - len = msgdsize(mp); - if (mp->b_wptr - mp->b_rptr < PPP_HDRLEN) { - PULLUP(mp, PPP_HDRLEN); - if (mp == 0) { - DPRINT1("ppp_urput: msgpullup failed (len=%d)\n", len); - break; - } + case M_DATA: + len = msgdsize(mp); + if (mp->b_wptr - mp->b_rptr < PPP_HDRLEN) { + PULLUP(mp, PPP_HDRLEN); + if (mp == 0) { + DPRINT1("ppp_urput: msgpullup failed (len=%d)\n", len); + break; } - MT_ENTER(&ppa->stats_lock); - ppa->stats.ppp_ipackets++; - ppa->stats.ppp_ibytes += len; + } + MT_ENTER(&ppa->stats_lock); + ppa->stats.ppp_ipackets++; + ppa->stats.ppp_ibytes += len; #ifdef INCR_IPACKETS - INCR_IPACKETS(ppa); + INCR_IPACKETS(ppa); #endif - MT_EXIT(&ppa->stats_lock); + MT_EXIT(&ppa->stats_lock); - proto = PPP_PROTOCOL(mp->b_rptr); + proto = PPP_PROTOCOL(mp->b_rptr); #if defined(SOL2) - /* - * Should there be any promiscuous stream(s), send the data - * up for each promiscuous stream that we recognize. - */ - promisc_sendup(ppa, mp, proto, 1); + /* + * Should there be any promiscuous stream(s), send the data + * up for each promiscuous stream that we recognize. + */ + promisc_sendup(ppa, mp, proto, 1); #endif /* defined(SOL2) */ - if (proto < 0x8000 && (us = find_dest(ppa, proto)) != 0) { - /* - * A data packet for some network protocol. - * Queue it on the upper stream for that protocol. - * XXX could we just putnext it? (would require thought) - * The rblocked flag is there to ensure that we keep - * messages in order for each network protocol. - */ - if (!pass_packet(us, mp, 0)) - break; - if (!us->rblocked && !canput(us->q)) - us->rblocked = 1; - if (!us->rblocked) - putq(us->q, mp); - else - putq(q, mp); + if (proto < 0x8000 && (us = find_dest(ppa, proto)) != 0) { + /* + * A data packet for some network protocol. + * Queue it on the upper stream for that protocol. + * XXX could we just putnext it? (would require thought) + * The rblocked flag is there to ensure that we keep + * messages in order for each network protocol. + */ + /* pass_packet frees the packet on returning 0 */ + if (!pass_packet(us, mp, 0)) break; - } + if (!us->rblocked && !canput(us->q)) + us->rblocked = 1; + if (!putq(us->rblocked ? q : us->q, mp)) + freemsg(mp); + break; } + + /* FALLTHROUGH */ + + default: /* * A control frame, a frame for an unknown protocol, * or some other message type. @@ -1927,8 +1934,8 @@ pppurput(q, mp) */ if (queclass(mp) == QPCTL || canputnext(ppa->q)) putnext(ppa->q, mp); - else - putq(q, mp); + else if (!putq(q, mp)) + freemsg(mp); break; } @@ -1980,7 +1987,8 @@ pppursrv(q) if (proto < 0x8000 && (as = find_dest(us, proto)) != 0) { if (!canput(as->q)) break; - putq(as->q, mp); + if (!putq(as->q, mp)) + freemsg(mp); } else { if (!canputnext(q)) break; @@ -2187,11 +2195,12 @@ promisc_sendup(ppa, mp, proto, skip) if (canputnext(prus->q)) { if (prus->flags & US_RAWDATA) { dup_dup_mp = prepend_ether(prus, dup_dup_mp, proto); - putnext(prus->q, dup_dup_mp); } else { dup_dup_mp = prepend_udind(prus, dup_dup_mp, proto); - putnext(prus->q, dup_dup_mp); } + if (dup_dup_mp == 0) + continue; + putnext(prus->q, dup_dup_mp); } else { DPRINT("ppp_urput: data to promisc q dropped\n"); freemsg(dup_dup_mp); @@ -2202,11 +2211,11 @@ promisc_sendup(ppa, mp, proto, skip) if (canputnext(prus->q)) { if (prus->flags & US_RAWDATA) { dup_mp = prepend_ether(prus, dup_mp, proto); - putnext(prus->q, dup_mp); } else { dup_mp = prepend_udind(prus, dup_mp, proto); - putnext(prus->q, dup_mp); } + if (dup_mp != 0) + putnext(prus->q, dup_mp); } else { DPRINT("ppp_urput: data to promisc q dropped\n"); freemsg(dup_mp); @@ -2253,7 +2262,8 @@ ppplrput(q, mp) * rather than blocking, to avoid the possibility of deadlock. */ if (!TRYLOCK_LOWER_R) { - putq(q, mp); + if (!putq(q, mp)) + freemsg(mp); return 0; } @@ -2276,8 +2286,8 @@ ppplrput(q, mp) */ if (queclass(mp) == QPCTL || (qsize(q) == 0 && canput(uq))) put(uq, mp); - else - putq(q, mp); + else if (!putq(q, mp)) + freemsg(mp); UNLOCK_LOWER; return 0; @@ -2411,6 +2421,9 @@ static struct pktfilt_tab { }; +/* + * Packet has already been freed if return value is 0. + */ static int ip_hard_filter(us, mp, outbound) upperstr_t *us; @@ -2484,7 +2497,10 @@ ip_hard_filter(us, mp, outbound) us->mn, pft->proto, pft->port); /* Discard if not connected, or if not pass_with_link_up */ /* else, if link is up let go by, but don't update time */ - return pft->ok_if_link_up? -1: 0; + if (pft->ok_if_link_up) + return -1; + freemsg(mp); + return 0; } break; } /* end switch (proto) */