2004-09-27 Paul Jakma <paul@dishone.st>

* ospf_dump.c: (ospf_ip_header_dump) Use HAVE_IP_HDRINCL_BSD_ORDER
	  Apply to offset too. Print ip_cksum, lets not worry about
	  possible 2.0.37 compile problems.
	* ospf_packet.c: (ospf_swap_iph_to{n,h}) Use
	  HAVE_IP_HDRINCL_BSD_ORDER.
	  (ospf_recv_packet) ditto.
	  (ospf_write) Fixup iov argument to ospf_write_frags.
This commit is contained in:
paul 2004-09-27 12:56:30 +00:00
parent 9172ee0e5d
commit 6a99f83175
3 changed files with 38 additions and 22 deletions

View File

@ -1,7 +1,13 @@
2004-09-27 Paul Jakma <paul@dishone.st> 2004-09-27 Paul Jakma <paul@dishone.st>
* ospf_packet.c: (ospf_write) (struct msghdr).msg_name is caddr_t * ospf_dump.c: (ospf_ip_header_dump) Use HAVE_IP_HDRINCL_BSD_ORDER
on most platforms. Apply to offset too. Print ip_cksum, lets not worry about
possible 2.0.37 compile problems.
* ospf_packet.c: (ospf_swap_iph_to{n,h}) Use
HAVE_IP_HDRINCL_BSD_ORDER.
(ospf_recv_packet) ditto.
(ospf_write) Fixup iov argument to ospf_write_frags.
(struct msghdr).msg_name is caddr_t on most platforms.
(ospf_recv_packet) ditto. And msg_flags is not always there (ospf_recv_packet) ditto. And msg_flags is not always there
memset struct then set fields we care about rather than memset struct then set fields we care about rather than
initialise all fields individually. initialise all fields individually.

View File

@ -602,15 +602,18 @@ void
ospf_ip_header_dump (struct stream *s) ospf_ip_header_dump (struct stream *s)
{ {
u_int16_t length; u_int16_t length;
u_int16_t offset;
struct ip *iph; struct ip *iph;
iph = (struct ip *) STREAM_PNT (s); iph = (struct ip *) STREAM_PNT (s);
#ifdef GNU_LINUX #ifdef HAVE_IP_HDRINCL_BSD_ORDER
length = ntohs (iph->ip_len);
#else /* GNU_LINUX */
length = iph->ip_len; length = iph->ip_len;
#endif /* GNU_LINUX */ offset = iph->ip_off;
#else /* !HAVE_IP_HDRINCL_BSD_ORDER */
length = ntohs (iph->ip_len);
offset = ntohs (iph->ip_off);
#endif /* HAVE_IP_HDRINCL_BSD_ORDER */
/* IP Header dump. */ /* IP Header dump. */
zlog_info ("ip_v %d", iph->ip_v); zlog_info ("ip_v %d", iph->ip_v);
@ -618,12 +621,10 @@ ospf_ip_header_dump (struct stream *s)
zlog_info ("ip_tos %d", iph->ip_tos); zlog_info ("ip_tos %d", iph->ip_tos);
zlog_info ("ip_len %d", length); zlog_info ("ip_len %d", length);
zlog_info ("ip_id %u", (u_int32_t) iph->ip_id); zlog_info ("ip_id %u", (u_int32_t) iph->ip_id);
zlog_info ("ip_off %u", (u_int32_t) iph->ip_off); zlog_info ("ip_off %u", (u_int32_t) offset);
zlog_info ("ip_ttl %d", iph->ip_ttl); zlog_info ("ip_ttl %d", iph->ip_ttl);
zlog_info ("ip_p %d", iph->ip_p); zlog_info ("ip_p %d", iph->ip_p);
/* There is a report that Linux 2.0.37 does not have ip_sum. But zlog_info ("ip_sum 0x%x", (u_int32_t) ntohs (iph->ip_sum));
I'm not sure. Temporary commented out by kunihiro. */
/* zlog_info ("ip_sum 0x%x", (u_int32_t) ntohs (iph->ip_sum)); */
zlog_info ("ip_src %s", inet_ntoa (iph->ip_src)); zlog_info ("ip_src %s", inet_ntoa (iph->ip_src));
zlog_info ("ip_dst %s", inet_ntoa (iph->ip_dst)); zlog_info ("ip_dst %s", inet_ntoa (iph->ip_dst));
} }

View File

@ -489,10 +489,11 @@ ospf_swab_iph_ton (struct ip *iph)
/* BSD and derived take iph in network order, except for /* BSD and derived take iph in network order, except for
* ip_len and ip_off * ip_len and ip_off
*/ */
#ifdef GNU_LINUX #ifndef HAVE_IP_HDRINCL_BSD_ORDER
iph->ip_len = htons(iph->ip_len); iph->ip_len = htons(iph->ip_len);
iph->ip_off = htons(iph->ip_off); iph->ip_off = htons(iph->ip_off);
#endif #endif /* HAVE_IP_HDRINCL_BSD_ORDER */
iph->ip_id = htons(iph->ip_id); iph->ip_id = htons(iph->ip_id);
} }
@ -500,19 +501,23 @@ ospf_swab_iph_ton (struct ip *iph)
void void
ospf_swab_iph_toh (struct ip *iph) ospf_swab_iph_toh (struct ip *iph)
{ {
#ifdef GNU_LINUX #ifdef HAVE_IP_HDRINCL_BSD_ORDER
iph->ip_len = ntohs(iph->ip_len); iph->ip_len = ntohs(iph->ip_len);
iph->ip_off = ntohs(iph->ip_off); iph->ip_off = ntohs(iph->ip_off);
#endif #endif /* HAVE_IP_HDRINCL_BSD_ORDER */
iph->ip_id = ntohs(iph->ip_id); iph->ip_id = ntohs(iph->ip_id);
} }
#ifdef WANT_OSPF_WRITE_FRAGMENT #ifdef WANT_OSPF_WRITE_FRAGMENT
void void
ospf_write_frags (struct ospf_packet *op, struct ip *ip, struct msghdr *msg, ospf_write_frags (int fd, struct ospf_packet *op, struct ip *iph,
struct iovec *iov, int maxdatasize); struct msghdr *msg, struct iovec **iov,
int maxdatasize, int mtu, int flags)
{ {
#define OSPF_WRITE_FRAG_SHIFT 3 #define OSPF_WRITE_FRAG_SHIFT 3
u_int16_t offset;
int ret;
assert ( op->length == stream_get_endp(op->s) ); assert ( op->length == stream_get_endp(op->s) );
@ -542,11 +547,11 @@ ospf_write_frags (struct ospf_packet *op, struct ip *ip, struct msghdr *msg,
/* data length of this frag is to next offset value */ /* data length of this frag is to next offset value */
iov[1]->iov_len = offset << OSPF_WRITE_FRAG_SHIFT; iov[1]->iov_len = offset << OSPF_WRITE_FRAG_SHIFT;
iph->ip_len = iov[1]->iov_len + sizeof (struct ip); iph->ip_len = iov[1]->iov_len + sizeof (struct ip);
assert (iph->ip_len <= oi->ifp->mtu); assert (iph->ip_len <= mtu);
ospf_swab_iph_ton (iph); ospf_swab_iph_ton (iph);
ret = sendmsg (ospf->fd, msg, flags); ret = sendmsg (fd, msg, flags);
ospf_swab_iph_toh (iph); ospf_swab_iph_toh (iph);
@ -580,7 +585,7 @@ ospf_write (struct thread *thread)
struct sockaddr_in sa_dst; struct sockaddr_in sa_dst;
struct ip iph; struct ip iph;
struct msghdr msg; struct msghdr msg;
struct iovec iov[2]; struct iovec iov[2], *iovp;
u_char type; u_char type;
int ret; int ret;
int flags = 0; int flags = 0;
@ -588,7 +593,7 @@ ospf_write (struct thread *thread)
#ifdef WANT_OSPF_WRITE_FRAGMENT #ifdef WANT_OSPF_WRITE_FRAGMENT
static u_int16_t ipid = 0; static u_int16_t ipid = 0;
#endif /* WANT_OSPF_WRITE_FRAGMENT */ #endif /* WANT_OSPF_WRITE_FRAGMENT */
u_int16_t maxdatasize, offset; u_int16_t maxdatasize;
#define OSPF_WRITE_IPHL_SHIFT 2 #define OSPF_WRITE_IPHL_SHIFT 2
ospf->t_write = NULL; ospf->t_write = NULL;
@ -679,7 +684,11 @@ ospf_write (struct thread *thread)
*/ */
#ifdef WANT_OSPF_WRITE_FRAGMENT #ifdef WANT_OSPF_WRITE_FRAGMENT
if ( op->length > maxdatasize ) if ( op->length > maxdatasize )
ospf_write_frags (&op, &ip, &msg, &iov, maxdatasize); {
iovp = iov;
ospf_write_frags (ospf->fd, op, &iph, &msg, &iovp, maxdatasize,
oi->ifp->mtu, flags);
}
#endif /* WANT_OSPF_WRITE_FRAGMENT */ #endif /* WANT_OSPF_WRITE_FRAGMENT */
/* send final fragment (could be first) */ /* send final fragment (could be first) */
@ -2032,7 +2041,7 @@ ospf_recv_packet (int fd, struct interface **ifp)
return NULL; return NULL;
} }
#if defined(__NetBSD__) || defined(__FreeBSD__) || (defined(__OpenBSD__) && (OpenBSD < 200311)) #ifdef HAVE_IP_HDRINCL_BSD_ORDER
ip_len = iph.ip_len; ip_len = iph.ip_len;
#else #else
ip_len = ntohs (iph.ip_len); ip_len = ntohs (iph.ip_len);