📄 watt-32 tcp-ip src-ppp_c source file.htm
字号:
00799
00800 <SPAN class=comment>/*</SPAN>
00801 <SPAN class=comment> * Check for time-outs</SPAN>
00802 <SPAN class=comment> */</SPAN>
00803 <SPAN class=keyword>static</SPAN> <SPAN class=keywordtype>void</SPAN> check_timeouts (<SPAN class=keywordtype>void</SPAN>)
00804 {
00805 time_t now;
00806 <SPAN class=keywordtype>int</SPAN> i;
00807
00808 <SPAN class=keywordflow>if</SPAN> (mystate.timeout_period < MAX_TIMEOUT)
00809 mystate.timeout_period <<= 1;
00810 now = time (NULL);
00811
00812 <SPAN class=keywordflow>for</SPAN> (i = 0; i < DIM(mystate.xcps); i++)
00813 {
00814 <SPAN class=keywordflow>if</SPAN> (mystate.xcps[i].timeout && now >= mystate.xcps[i].timeout)
00815 {
00816 mystate.xcps[i].timeout = 0;
00817
00818 <SPAN class=comment>/* Hack -- send with same ID on timeout.</SPAN>
00819 <SPAN class=comment> */</SPAN>
00820 <SPAN class=keywordflow>if</SPAN> (mystate.xcps[i].restart > 0)
00821 mystate.xcps[i].ident--;
00822
00823 PRINTF (4, (<SPAN class=stringliteral>"Sending TO%c to %s\n"</SPAN>,
00824 mystate.xcps[i].restart > 0 ? <SPAN class=charliteral>'+'</SPAN> : <SPAN class=charliteral>'-'</SPAN>,
00825 mystate.xcps[i].name));
00826
00827 send_event (&mystate, mystate.xcps+i,
00828 mystate.xcps[i].restart > 0 ? evTOp : evTOm);
00829 }
00830 }
00831 }
00832
00833 <SPAN class=comment>/*</SPAN>
00834 <SPAN class=comment> * PPP input handler.</SPAN>
00835 <SPAN class=comment> */</SPAN>
00836 <SPAN class=keywordtype>void</SPAN> ppp_input (<SPAN class=keyword>const</SPAN> BYTE *inbuffer, <SPAN class=keywordtype>int</SPAN> len)
00837 {
00838 <SPAN class=keyword>struct </SPAN>ppp_state *state = &mystate;
00839 <SPAN class=keywordtype>int</SPAN> i;
00840 <A class=code href="http://www.bgnett.no/~giva/watt-doc/a01345.html#a1">WORD</A> proto;
00841
00842 state->inbuffer = (<A class=code href="http://www.bgnett.no/~giva/watt-doc/a01345.html#a0">BYTE</A>*) inbuffer;
00843
00844 <SPAN class=preprocessor>#if defined(USE_DEBUG)</SPAN>
00845 <SPAN class=preprocessor></SPAN> <SPAN class=keywordflow>if</SPAN> (debug > 3)
00846 buffer_print (<SPAN class=stringliteral>"Received"</SPAN>, state->inbuffer, len);
00847 <SPAN class=preprocessor>#endif</SPAN>
00848 <SPAN class=preprocessor></SPAN>
00849 <SPAN class=preprocessor>#if 0 </SPAN><SPAN class=comment>/* no p-compression used in PPPoE */</SPAN>
00850 <SPAN class=keywordflow>if</SPAN> (state->inbuffer[0] & 0x1)
00851 {
00852 proto = state->inbuffer[0];
00853 state->inbuffer++;
00854 len--;
00855 }
00856 <SPAN class=keywordflow>else</SPAN> <SPAN class=keywordflow>if</SPAN> (state->inbuffer[1] & 0x1)
00857 {
00858 proto = intel16 (*(WORD*)state->inbuffer);
00859 state->inbuffer += 2;
00860 len -=2;
00861 }
00862 <SPAN class=keywordflow>else</SPAN>
00863 {
00864 proto = intel16 (*(WORD*)state->inbuffer);
00865 PRINTF (0, (<SPAN class=stringliteral>"Bad protocol field %04X\n"</SPAN>, proto));
00866 <SPAN class=keywordflow>return</SPAN>;
00867 }
00868 <SPAN class=preprocessor>#else</SPAN>
00869 <SPAN class=preprocessor></SPAN> proto = intel16 (*(WORD*)state->inbuffer);
00870 state->inbuffer += 2;
00871 len -=2;
00872 <SPAN class=preprocessor>#endif</SPAN>
00873 <SPAN class=preprocessor></SPAN>
00874 <SPAN class=keywordflow>if</SPAN> (proto == PPP_IP)
00875 {
00876 _ip4_handler ((<SPAN class=keyword>const</SPAN> <A class=code href="http://www.bgnett.no/~giva/watt-doc/a00732.html">in_Header</A>*)state->inbuffer, FALSE);
00877 <SPAN class=keywordflow>return</SPAN>;
00878 }
00879
00880 <SPAN class=comment>/* Find XCP (IPCP/LCP) for indicated protocol</SPAN>
00881 <SPAN class=comment> */</SPAN>
00882 <SPAN class=keywordflow>for</SPAN> (i = 0; i < DIM(state->xcps); i++)
00883 <SPAN class=keywordflow>if</SPAN> (state->xcps[i].proto == proto)
00884 <SPAN class=keywordflow>break</SPAN>;
00885
00886 <SPAN class=keywordflow>if</SPAN> (i >= DIM(state->xcps))
00887 {
00888 <SPAN class=comment>/* Generate LCP Protocol-Reject for unknown things.</SPAN>
00889 <SPAN class=comment> */</SPAN>
00890 PRINTF (0, (<SPAN class=stringliteral>"Unknown protocol 0x%04X\n"</SPAN>, proto));
00891
00892 <SPAN class=keywordflow>if</SPAN> (state->xcps[XCP_LCP].state == stOpened)
00893 {
00894 <A class=code href="http://www.bgnett.no/~giva/watt-doc/a01345.html#a0">BYTE</A> *bp = code_id (state, &state->xcps[XCP_LCP], CODE_PROTO_REJ);
00895
00896 i = <SPAN class=keyword>sizeof</SPAN>(state->outbuffer) - (bp - state->outbuffer);
00897 <SPAN class=keywordflow>if</SPAN> (len > i)
00898 len = i;
00899 memcpy (bp, state->inbuffer-2, len);
00900 len += bp - state->outbuffer;
00901 *(<A class=code href="http://www.bgnett.no/~giva/watt-doc/a01345.html#a1">WORD</A>*) (state->outbuffer+2) = intel16 (len-4);
00902 ppp_write (state, &state->xcps[XCP_LCP], state->outbuffer, len);
00903 }
00904 <SPAN class=keywordflow>return</SPAN>;
00905 }
00906
00907 state->bp = state->inbuffer;
00908 state->mlen = len;
00909 (*state->xcps[i].deliver) (state, state->xcps + i);
00910 }
00911
00912 <SPAN class=comment>/*</SPAN>
00913 <SPAN class=comment> * Add current option to list of options to be sent in Configure-Reject.</SPAN>
00914 <SPAN class=comment> */</SPAN>
00915 <SPAN class=keyword>static</SPAN> <SPAN class=keywordtype>void</SPAN> set_reject (<SPAN class=keyword>struct</SPAN> ppp_state *state, <SPAN class=keyword>struct</SPAN> ppp_xcp *xcp,
00916 <SPAN class=keyword>const</SPAN> BYTE *bp)
00917 {
00918 <SPAN class=keywordtype>int</SPAN> i;
00919
00920 <SPAN class=keywordflow>if</SPAN> (state->parse_state == psBad)
00921 <SPAN class=keywordflow>return</SPAN>;
00922
00923 <SPAN class=comment>/* If this is the first reject for this packet, then set up.</SPAN>
00924 <SPAN class=comment> */</SPAN>
00925 <SPAN class=keywordflow>if</SPAN> (state->parse_state != psRej)
00926 {
00927 state->up = code_reply (state, xcp, CODE_CONF_REJ);
00928 state->parse_state = psRej;
00929 }
00930
00931 <SPAN class=comment>/* Handle malformed options; make sure we don't send anything illegal</SPAN>
00932 <SPAN class=comment> * to the peer (even if he's sending us junk).</SPAN>
00933 <SPAN class=comment> */</SPAN>
00934 i = bp[1];
00935 <SPAN class=keywordflow>if</SPAN> (i < 2)
00936 i = 2;
00937 memcpy (state->up, bp, i);
00938 state->up[1] = i;
00939 state->up += i;
00940 }
00941
00942 <SPAN class=comment>/*</SPAN>
00943 <SPAN class=comment> * Add current option to list of options to be sent in Configure-Nak.</SPAN>
00944 <SPAN class=comment> */</SPAN>
00945 <SPAN class=keyword>static</SPAN> <SPAN class=keywordtype>void</SPAN> set_nak (<SPAN class=keyword>struct</SPAN> ppp_state *state, <SPAN class=keyword>struct</SPAN> ppp_xcp *xcp, <SPAN class=keywordtype>int</SPAN> type,
00946 <SPAN class=keywordtype>int</SPAN> len, <SPAN class=keyword>const</SPAN> BYTE *bp)
00947 {
00948 <SPAN class=comment>/* If we're rejecting, then no point in doing naks.</SPAN>
00949 <SPAN class=comment> */</SPAN>
00950 <SPAN class=keywordflow>if</SPAN> (state->parse_state == psBad || state->parse_state == psRej)
00951 <SPAN class=keywordflow>return</SPAN>;
00952
00953 <SPAN class=comment>/* If this is the first nak for this packet, then set up.</SPAN>
00954 <SPAN class=comment> */</SPAN>
00955 <SPAN class=keywordflow>if</SPAN> (state->parse_state != psNak)
00956 {
00957 state->up = code_reply (state, xcp, CODE_CONF_NAK);
00958 state->parse_state = psNak;
00959 }
00960 *state->up++ = type;
00961 *state->up++ = len;
00962 <SPAN class=keywordflow>while</SPAN> (--len > 1)
00963 *state->up++ = *bp++;
00964 }
00965
00966 <SPAN class=comment>/*</SPAN>
00967 <SPAN class=comment> * Check Configure-Request options from peer against list of</SPAN>
00968 <SPAN class=comment> * known, valid, and desired options.</SPAN>
00969 <SPAN class=comment> */</SPAN>
00970 <SPAN class=keyword>static</SPAN> <SPAN class=keywordtype>int</SPAN> validate_request (<SPAN class=keyword>struct</SPAN> ppp_state *state, <SPAN class=keyword>struct</SPAN> ppp_xcp *xcp)
00971 {
00972 <SPAN class=keyword>const</SPAN> <SPAN class=keyword>struct </SPAN>xcp_type *tp;
00973 <SPAN class=keyword>const</SPAN> <A class=code href="http://www.bgnett.no/~giva/watt-doc/a01345.html#a0">BYTE</A> *bp;
00974 <SPAN class=keywordtype>int</SPAN> rlen, i;
00975
00976 state->parse_state = psOK;
00977 rlen = state->mlen;
00978 bp = state->bp;
00979
00980 <SPAN class=keywordflow>while</SPAN> (rlen > 0)
00981 {
00982 <SPAN class=keywordflow>if</SPAN> (rlen < 2 || bp[1] > rlen)
00983 {
00984 state->parse_state = psBad;
00985 <SPAN class=keywordflow>break</SPAN>;
00986 }
00987 <SPAN class=keywordflow>for</SPAN> (tp = xcp->types; tp->type != -1; tp++)
00988 <SPAN class=keywordflow>if</SPAN> (tp->type == bp[0])
00989 <SPAN class=keywordflow>break</SPAN>;
00990
00991 <SPAN class=keywordflow>if</SPAN> (tp->type == -1)
00992 set_reject (state, xcp, bp);
00993 <SPAN class=keywordflow>else</SPAN> <SPAN class=keywordflow>if</SPAN> (bp[1] < tp->minlen)
00994 set_nak (s
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -