* Copyright (c) 1984, 1988 Regents of the University of California.
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* @(#)ns_error.c 7.8 (Berkeley) 6/28/90
#include "../net/route.h"
* NS_ERR routines: error generation, receive packet processing, and
* routines to turnaround packets back to the originator.
register u_short
*w
, *lim
, *base
= ns_errstat
.ns_es_codes
;
* zero is a legit error code, handle specially
lim
= base
+ NS_ERR_MAX
- 1;
for (w
= base
+ 1; w
< lim
; w
++) {
* Generate an error packet of type error
* in response to bad packet.
ns_error(om
, type
, param
)
register struct ns_epidp
*ep
;
register struct idp
*oip
= mtod(om
, struct idp
*);
* If this packet was sent to the echo port,
* and nobody was there, just echo it.
if (type
== NS_ERR_NOSOCK
&&
oip
->idp_dna
.x_port
== htons(2) &&
printf("ns_err_error(%x, %d, %d)\n", oip
, type
, param
);
* Don't Generate error packets in response to multicasts.
if (oip
->idp_dna
.x_host
.c_host
[0] & 1)
ns_errstat
.ns_es_error
++;
* Make sure that the old IDP packet had 30 bytes of data to return;
* if not, don't bother. Also don't EVER error if the old
* packet protocol was NS_ERR.
if (oip
->idp_len
< sizeof(struct idp
)) {
ns_errstat
.ns_es_oldshort
++;
if (oip
->idp_pt
== NSPROTO_ERROR
) {
ns_errstat
.ns_es_oldns_err
++;
* First, formulate ns_err message
m
= m_gethdr(M_DONTWAIT
, MT_HEADER
);
ep
= mtod(m
, struct ns_epidp
*);
if ((u_int
)type
> NS_ERR_TOO_BIG
)
ns_errstat
.ns_es_outhist
[ns_err_x(type
)]++;
ep
->ns_ep_errp
.ns_err_num
= htons((u_short
)type
);
ep
->ns_ep_errp
.ns_err_param
= htons((u_short
)param
);
bcopy((caddr_t
)oip
, (caddr_t
)&ep
->ns_ep_errp
.ns_err_idp
, 42);
nip
->idp_len
= sizeof(*ep
);
nip
->idp_len
= htons((u_short
)nip
->idp_len
);
nip
->idp_pt
= NSPROTO_ERROR
;
nip
->idp_dna
= oip
->idp_sna
;
nip
->idp_sna
= oip
->idp_dna
;
nip
->idp_sum
= ns_cksum(m
, sizeof(*ep
));
(void) ns_output(m
, (struct route
*)0, 0);
register struct ns_addr
*p
;
printf("<net:%x%x,host:%x%x%x,port:%x>",
* Process a received NS_ERR message.
register struct ns_errp
*ep
;
register struct ns_epidp
*epidp
= mtod(m
, struct ns_epidp
*);
* Locate ns_err structure in mbuf, and check
* that not corrupted and of at least minimum length.
printf("ns_err_input from ");
ns_printhost(&epidp
->ns_ep_idp
.idp_sna
);
printf("len %d\n", ntohs(epidp
->ns_ep_idp
.idp_len
));
i
= sizeof (struct ns_epidp
);
if (((m
->m_flags
& M_EXT
) || m
->m_len
< i
) &&
(m
= m_pullup(m
, i
)) == 0) {
ns_errstat
.ns_es_tooshort
++;
ep
= &(mtod(m
, struct ns_epidp
*)->ns_ep_errp
);
type
= ntohs(ep
->ns_err_num
);
param
= ntohs(ep
->ns_err_param
);
ns_errstat
.ns_es_inhist
[ns_err_x(type
)]++;
* Message type specific processing.
printf("ns_err_input, type %d param %d\n", type
, param
);
if (type
>= NS_ERR_TOO_BIG
) {
ns_errstat
.ns_es_outhist
[ns_err_x(type
)]++;
case NS_ERR_UNREACH_HOST
:
code
= PRC_TIMXCEED_INTRANS
;
* Problem with datagram; advise higher level routines.
printf("deliver to protocol %d\n",
switch(ep
->ns_err_idp
.idp_pt
) {
spp_ctlinput(code
, (caddr_t
)ep
);
idp_ctlinput(code
, (caddr_t
)ep
);
ns_errstat
.ns_es_badcode
++;
t
= (time
.tv_sec
% (24*60*60)) * 1000 + time
.tv_usec
/ 1000;
register struct idp
*idp
= mtod(m
, struct idp
*);
u_short ec_op
; /* Operation, 1 = request, 2 = reply */
} *ec
= (struct echo
*)idp
;
if (idp
->idp_pt
!=NSPROTO_ECHO
) return(NS_ERR_NOSOCK
);
if (ec
->ec_op
!=htons(1)) return(NS_ERR_UNSPEC
);
idp
->idp_dna
= idp
->idp_sna
;
if (idp
->idp_sum
!= 0xffff) {
idp
->idp_sum
= ns_cksum(m
,
(int)(((ntohs(idp
->idp_len
) - 1)|1)+1));
(void) ns_output(m
, (struct route
*)0, NS_FORWARDING
);