Portability: POSIXize some of inet's error codes

This commit is contained in:
David van Moolenbroek 2009-11-28 13:18:33 +00:00
parent 709a739b52
commit c6cce1823d
13 changed files with 61 additions and 48 deletions

View file

@ -79,12 +79,12 @@ extern int errno; /* place where the error numbers go */
/* The following errors relate to networking. */ /* The following errors relate to networking. */
#define EPACKSIZE (_SIGN 50) /* invalid packet size for some protocol */ #define EPACKSIZE (_SIGN 50) /* invalid packet size for some protocol */
#define EOUTOFBUFS (_SIGN 51) /* not enough buffers left */ #define ENOBUFS (_SIGN 51) /* not enough buffers left */
#define EBADIOCTL (_SIGN 52) /* illegal ioctl for device */ #define EBADIOCTL (_SIGN 52) /* illegal ioctl for device */
#define EBADMODE (_SIGN 53) /* badmode in ioctl */ #define EBADMODE (_SIGN 53) /* badmode in ioctl */
#define EWOULDBLOCK (_SIGN 54) /* call would block on nonblocking socket */ #define EWOULDBLOCK (_SIGN 54) /* call would block on nonblocking socket */
#define EBADDEST (_SIGN 55) /* not a valid destination address */ #define ENETUNREACH (_SIGN 55) /* network unreachable */
#define EDSTNOTRCH (_SIGN 56) /* destination not reachable */ #define EHOSTUNREACH (_SIGN 56) /* host unreachable */
#define EISCONN (_SIGN 57) /* already connected */ #define EISCONN (_SIGN 57) /* already connected */
#define EADDRINUSE (_SIGN 58) /* address in use */ #define EADDRINUSE (_SIGN 58) /* address in use */
#define ECONNREFUSED (_SIGN 59) /* connection refused */ #define ECONNREFUSED (_SIGN 59) /* connection refused */
@ -105,6 +105,7 @@ extern int errno; /* place where the error numbers go */
#define ENOTSOCK (_SIGN 74) /* Socket operation on non-socket */ #define ENOTSOCK (_SIGN 74) /* Socket operation on non-socket */
#define ENOPROTOOPT (_SIGN 75) /* Protocol not available */ #define ENOPROTOOPT (_SIGN 75) /* Protocol not available */
#define EOPNOTSUPP (_SIGN 76) /* Operation not supported */ #define EOPNOTSUPP (_SIGN 76) /* Operation not supported */
#define ENETDOWN (_SIGN 77) /* network is down */
/* The following are not POSIX errors, but they can still happen. /* The following are not POSIX errors, but they can still happen.
* All of these are generated by the kernel and relate to message passing. * All of these are generated by the kernel and relate to message passing.

View file

@ -52,7 +52,7 @@ const char *_sys_errlist[] = {
"Too many levels of symbolic links", /* ELOOP */ "Too many levels of symbolic links", /* ELOOP */
"Driver restarted", /* ERESTART */ "Driver restarted", /* ERESTART */
unknown, /* 42 */ unknown, /* 42 */
unknown, /* 43 */ "Identifier removed", /* EIDRM */
unknown, /* 44 */ unknown, /* 44 */
unknown, /* 45 */ unknown, /* 45 */
unknown, /* 46 */ unknown, /* 46 */
@ -60,12 +60,12 @@ const char *_sys_errlist[] = {
unknown, /* 48 */ unknown, /* 48 */
unknown, /* 49 */ unknown, /* 49 */
"Invalid packet size", /* EPACKSIZE */ "Invalid packet size", /* EPACKSIZE */
"Not enough buffers left", /* EOUTOFBUFS */ "Not enough buffers left", /* ENOBUFS */
"Illegal ioctl for device", /* EBADIOCTL */ "Illegal ioctl for device", /* EBADIOCTL */
"Bad mode for ioctl", /* EBADMODE */ "Bad mode for ioctl", /* EBADMODE */
"Would block", /* EWOULDBLOCK */ "Would block", /* EWOULDBLOCK */
"Bad destination address", /* EBADDEST */ "Network unreachable", /* ENETUNREACH */
"Destination not reachable", /* EDSTNOTRCH */ "Host unreachable", /* EHOSTUNREACH */
"Already connected", /* EISCONN */ "Already connected", /* EISCONN */
"Address in use", /* EADDRINUSE */ "Address in use", /* EADDRINUSE */
"Connection refused", /* ECONNREFUSED */ "Connection refused", /* ECONNREFUSED */
@ -86,6 +86,7 @@ const char *_sys_errlist[] = {
"Socket operation on non-socket", /* ENOTSOCK */ "Socket operation on non-socket", /* ENOTSOCK */
"Protocol not available", /* ENOPROTOOPT */ "Protocol not available", /* ENOPROTOOPT */
"Operation not supported", /* EOPNOTSUPP */ "Operation not supported", /* EOPNOTSUPP */
"Network is down", /* ENETDOWN */
}; };
const int _sys_nerr = sizeof(_sys_errlist) / sizeof(_sys_errlist[0]); const int _sys_nerr = sizeof(_sys_errlist) / sizeof(_sys_errlist[0]);

View file

@ -32,7 +32,7 @@ variable \fBerrno\fP, which is not cleared
on successful calls. on successful calls.
Thus \fBerrno\fP should be tested only after an error has occurred. Thus \fBerrno\fP should be tested only after an error has occurred.
.PP .PP
The following is a complete list of the errors and their The following is a list of the errors and their
names as given in names as given in
.RI < sys/errno.h >: .RI < sys/errno.h >:
.en 0 OK "Error 0 .en 0 OK "Error 0
@ -228,16 +228,16 @@ system.
A directory with entries other than \*(lq.\*(rq and \*(lq..\*(rq A directory with entries other than \*(lq.\*(rq and \*(lq..\*(rq
was supplied to a remove directory or rename call. was supplied to a remove directory or rename call.
.en 40 ELOOP "Too many symbolic links" .en 40 ELOOP "Too many symbolic links"
A path name lookup involved more than SYMLOOP symbolic links. SYMLOOP A path name lookup involved too many symbolic links.
equals 8 as distributed. .en 41 ERESTART "Device driver restarted
(Minix-vmd) .en 43 EIDRM "Identifier removed
.en 50 EPACKSIZE "Invalid packet size .en 50 EPACKSIZE "Invalid packet size
.en 51 EOUTOFBUFS "Not enough buffers left .en 51 ENOBUFS "Not enough buffers left
.en 52 EBADIOCTL "Illegal ioctl for device .en 52 EBADIOCTL "Illegal ioctl for device
.en 53 EBADMODE "Bad mode in ioctl .en 53 EBADMODE "Bad mode in ioctl
.en 54 EWOULDBLOCK "Would block .en 54 EWOULDBLOCK "Would block
.en 55 EBADDEST "Bad destination address .en 55 ENETUNREACH "Network unreachable
.en 56 EDSTNOTRCH "Destination not reachable .en 56 EHOSTUNREACH "Host unreachable
.en 57 EISCONN "Already connected .en 57 EISCONN "Already connected
.en 58 EADDRINUSE "Address in use .en 58 EADDRINUSE "Address in use
.en 59 ECONNREFUSED "Connection refused .en 59 ECONNREFUSED "Connection refused
@ -248,8 +248,17 @@ equals 8 as distributed.
.en 64 ENOTCONN "No connection .en 64 ENOTCONN "No connection
.en 65 ESHUTDOWN "Already shutdown .en 65 ESHUTDOWN "Already shutdown
.en 66 ENOCONN "No such connection .en 66 ENOCONN "No such connection
.en 67 EINPROGRESS "Operation now in progress .en 67 EAFNOSUPPORT "Address family not supported
.en 68 EALREADY "Operation already in progress .en 68 EPROTONOSUPPORT "Protocol not supported by AF
.en 69 EPROTOTYPE "Protocol wrong type for socket
.en 70 EINPROGRESS "Operation now in progress
.en 71 EADDRNOTAVAIL "Can't assign requested address
.en 72 EALREADY "Operation already in progress
.en 73 EMSGSIZE "Message too long
.en 74 ENOTSOCK "Socket operation on non-socket
.en 75 ENOPROTOOPT "Protocol not available
.en 76 EOPNOTSUPP "Operation not supported
.en 77 ENETDOWN "Network is down
.ig .ig
.en XXX EDQUOT "Disc quota exceeded" .en XXX EDQUOT "Disc quota exceeded"
A A

View file

@ -1414,11 +1414,11 @@ variable if the
.BR write , .BR write ,
or or
.B ioctl .B ioctl
call returns -1. The TCP/IP error codes defined in <errno.h> are: call returns -1. The TCP/IP error codes defined in <errno.h> are, among others:
.IP EPACKSIZE 5c .IP EPACKSIZE 5c
This indicates an attempt to read or write with a buffer that is too This indicates an attempt to read or write with a buffer that is too
large or too small. large or too small.
.IP EOUTOFBUFS .IP ENOBUFS
The TCP/IP server has insufficient memory to execute the request. The TCP/IP server has insufficient memory to execute the request.
.IP EBADIOCTL .IP EBADIOCTL
This indicates an attempt to execute a command the particular server This indicates an attempt to execute a command the particular server
@ -1429,10 +1429,10 @@ on an ETH channel.
.IP EBADMODE .IP EBADMODE
The request is refused because the channel is not fully configured, in the The request is refused because the channel is not fully configured, in the
wrong state or the parameters are invalid. wrong state or the parameters are invalid.
.IP EBADDEST .IP ENETUNREACH
This indicates an illegal destination address for a packet. The destination network is not reachable.
.IP EDSTNORCH .IP EHOSTUNREACH
The destination is not reachable. The destination host is not reachable.
.IP EISCONN .IP EISCONN
The channel is already connected so a second request is refused. The channel is already connected so a second request is refused.
.IP EADDRINUSE .IP EADDRINUSE

View file

@ -920,7 +920,7 @@ ether_addr_t *ethaddr;
return NW_OK; return NW_OK;
} }
if (ce->ac_state == ACS_UNREACHABLE) if (ce->ac_state == ACS_UNREACHABLE)
return EDSTNOTRCH; return EHOSTUNREACH;
assert(ce->ac_state == ACS_INCOMPLETE); assert(ce->ac_state == ACS_INCOMPLETE);
return NW_SUSPEND; return NW_SUSPEND;

View file

@ -346,10 +346,10 @@ int type;
ip_port->ip_dl.dl_eth.de_arp_tail= eth_pack; ip_port->ip_dl.dl_eth.de_arp_tail= eth_pack;
return NW_OK; return NW_OK;
} }
if (r == EDSTNOTRCH) if (r == EHOSTUNREACH)
{ {
bf_afree(eth_pack); bf_afree(eth_pack);
return EDSTNOTRCH; return r;
} }
assert(r == NW_OK); assert(r == NW_OK);
} }
@ -599,7 +599,7 @@ ether_addr_t *eth_addr;
/* Dequeue the packet */ /* Dequeue the packet */
ip_port->ip_dl.dl_eth.de_arp_head= eth_pack->acc_ext_link; ip_port->ip_dl.dl_eth.de_arp_head= eth_pack->acc_ext_link;
if (r == EDSTNOTRCH) if (r == EHOSTUNREACH)
{ {
bf_afree(eth_pack); bf_afree(eth_pack);
continue; continue;

View file

@ -299,7 +299,7 @@ ioreq_t req;
{ {
/* Interface is down, no changes allowed */ /* Interface is down, no changes allowed */
return (*ip_fd->if_put_userdata)(ip_fd->if_srfd, return (*ip_fd->if_put_userdata)(ip_fd->if_srfd,
EINVAL, NULL, TRUE); ENETDOWN, NULL, TRUE);
} }
data= bf_packIffLess (data, sizeof(nwio_route_t) ); data= bf_packIffLess (data, sizeof(nwio_route_t) );
@ -375,7 +375,7 @@ ioreq_t req;
{ {
/* Interface is down, no changes allowed */ /* Interface is down, no changes allowed */
return (*ip_fd->if_put_userdata)(ip_fd->if_srfd, return (*ip_fd->if_put_userdata)(ip_fd->if_srfd,
EINVAL, NULL, TRUE); ENETDOWN, NULL, TRUE);
} }
data= bf_packIffLess (data, sizeof(nwio_route_t) ); data= bf_packIffLess (data, sizeof(nwio_route_t) );

View file

@ -822,7 +822,7 @@ ev_arg_t ev_arg;
r= next_port->ip_dev_send(next_port, r= next_port->ip_dev_send(next_port,
iroute->irt_gateway, iroute->irt_gateway,
pack, IP_LT_NORMAL); pack, IP_LT_NORMAL);
if (r == EDSTNOTRCH) if (r == EHOSTUNREACH)
{ {
printf("ip[%d]: gw ", printf("ip[%d]: gw ",
ip_port-ip_port_table); ip_port-ip_port_table);
@ -894,7 +894,7 @@ ev_arg_t ev_arg;
/* Just send the packet to it's destination */ /* Just send the packet to it's destination */
pack->acc_linkC++; /* Extra ref for ICMP */ pack->acc_linkC++; /* Extra ref for ICMP */
r= next_port->ip_dev_send(next_port, dest, pack, type); r= next_port->ip_dev_send(next_port, dest, pack, type);
if (r == EDSTNOTRCH) if (r == EHOSTUNREACH)
{ {
DBLOCK(1, printf("ip[%d]: next hop ", DBLOCK(1, printf("ip[%d]: next hop ",
ip_port-ip_port_table); ip_port-ip_port_table);

View file

@ -78,11 +78,9 @@ size_t data_len;
if (!(ip_fd->if_port->ip_flags & IPF_IPADDRSET)) if (!(ip_fd->if_port->ip_flags & IPF_IPADDRSET))
{ {
/* Interface is down. What kind of error do we want? For /* Interface is down. */
* the moment, we return OK.
*/
bf_afree(data); bf_afree(data);
return NW_OK; return ENETDOWN;
} }
data_len= bf_bufsize(data); data_len= bf_bufsize(data);
@ -198,17 +196,17 @@ size_t data_len;
else if ((hostrep_dst & 0xe0000000l) == 0xe0000000l) else if ((hostrep_dst & 0xe0000000l) == 0xe0000000l)
; /* OK, Multicast */ ; /* OK, Multicast */
else if ((hostrep_dst & 0xf0000000l) == 0xf0000000l) else if ((hostrep_dst & 0xf0000000l) == 0xf0000000l)
r= EBADDEST; /* Bad class */ r= EAFNOSUPPORT; /* Bad class */
else if ((dstaddr ^ my_ipaddr) & netmask) else if ((dstaddr ^ my_ipaddr) & netmask)
; /* OK, remote destination */ ; /* OK, remote destination */
else if (!(dstaddr & ~netmask) && else if (!(dstaddr & ~netmask) &&
(ip_port->ip_flags & IPF_SUBNET_BCAST)) (ip_port->ip_flags & IPF_SUBNET_BCAST))
{ {
r= EBADDEST; /* Zero host part */ r= EAFNOSUPPORT; /* Zero host part */
} }
if (r<0) if (r<0)
{ {
DIFBLOCK(1, r == EBADDEST, DIFBLOCK(1, r == EAFNOSUPPORT,
printf("bad destination: "); printf("bad destination: ");
writeIpAddr(ip_hdr->ih_dst); writeIpAddr(ip_hdr->ih_dst);
printf("\n")); printf("\n"));

View file

@ -195,7 +195,7 @@ ipaddr_t *nexthop;
oroute= oroute_find_ent(port_nr, dest); oroute= oroute_find_ent(port_nr, dest);
if (!oroute || oroute->ort_dist > ttl) if (!oroute || oroute->ort_dist > ttl)
return EDSTNOTRCH; return ENETUNREACH;
if (msgsize && oroute->ort_mtu && if (msgsize && oroute->ort_mtu &&
oroute->ort_mtu < msgsize) oroute->ort_mtu < msgsize)
{ {

View file

@ -392,12 +392,14 @@ assert (count == sizeof(struct nwio_ipopt));
result= (int)offset; result= (int)offset;
if (result<0) if (result<0)
{ {
if (result == EDSTNOTRCH) if (result == EHOSTUNREACH ||
result == ENETUNREACH ||
result == ENETDOWN)
{ {
if (tcp_port->tp_snd_head) if (tcp_port->tp_snd_head)
{ {
tcp_notreach(tcp_port-> tcp_notreach(tcp_port->
tp_snd_head); tp_snd_head, result);
} }
} }
else else
@ -2414,7 +2416,7 @@ int priority;
{ {
continue; continue;
} }
tcp_close_connection (tcp_conn, EOUTOFBUFS); tcp_close_connection (tcp_conn, ENOBUFS);
} }
} }
@ -2434,7 +2436,7 @@ int priority;
{ {
continue; continue;
} }
tcp_close_connection (tcp_conn, EOUTOFBUFS); tcp_close_connection (tcp_conn, ENOBUFS);
} }
} }
} }
@ -2470,8 +2472,9 @@ PRIVATE void tcp_bufcheck()
} }
#endif #endif
PUBLIC void tcp_notreach(tcp_conn) PUBLIC void tcp_notreach(tcp_conn, error)
tcp_conn_t *tcp_conn; tcp_conn_t *tcp_conn;
int error;
{ {
int new_ttl; int new_ttl;
@ -2479,7 +2482,7 @@ tcp_conn_t *tcp_conn;
if (new_ttl == IP_MAX_TTL) if (new_ttl == IP_MAX_TTL)
{ {
if (tcp_conn->tc_state == TCS_SYN_SENT) if (tcp_conn->tc_state == TCS_SYN_SENT)
tcp_close_connection(tcp_conn, EDSTNOTRCH); tcp_close_connection(tcp_conn, error);
return; return;
} }
else if (new_ttl < TCP_DEF_TTL_NEXT) else if (new_ttl < TCP_DEF_TTL_NEXT)

View file

@ -243,7 +243,7 @@ int tcp_su4listen ARGS(( tcp_fd_t *tcp_fd, tcp_conn_t *tcp_conn,
void tcp_reply_ioctl ARGS(( tcp_fd_t *tcp_fd, int reply )); void tcp_reply_ioctl ARGS(( tcp_fd_t *tcp_fd, int reply ));
void tcp_reply_write ARGS(( tcp_fd_t *tcp_fd, size_t reply )); void tcp_reply_write ARGS(( tcp_fd_t *tcp_fd, size_t reply ));
void tcp_reply_read ARGS(( tcp_fd_t *tcp_fd, size_t reply )); void tcp_reply_read ARGS(( tcp_fd_t *tcp_fd, size_t reply ));
void tcp_notreach ARGS(( tcp_conn_t *tcp_conn )); void tcp_notreach ARGS(( tcp_conn_t *tcp_conn, int error ));
void tcp_mtu_exceeded ARGS(( tcp_conn_t *tcp_conn )); void tcp_mtu_exceeded ARGS(( tcp_conn_t *tcp_conn ));
void tcp_mtu_incr ARGS(( tcp_conn_t *tcp_conn )); void tcp_mtu_incr ARGS(( tcp_conn_t *tcp_conn ));

View file

@ -121,12 +121,13 @@ tcp_port_t *tcp_port;
tcp_mtu_exceeded(tcp_conn); tcp_mtu_exceeded(tcp_conn);
continue; continue;
} }
if (r == EDSTNOTRCH) if (r == EHOSTUNREACH || r == ENETUNREACH ||
r == ENETDOWN)
{ {
tcp_notreach(tcp_conn); tcp_notreach(tcp_conn, r);
continue; continue;
} }
if (r == EBADDEST) if (r == EAFNOSUPPORT)
continue; continue;
} }
assert(r == NW_OK || assert(r == NW_OK ||