Index: ospfd/ospf_interface.c =================================================================== RCS file: /var/cvsroot/quagga/ospfd/ospf_interface.c,v retrieving revision 1.20 diff -u -w -b -r1.20 ospf_interface.c --- ospfd/ospf_interface.c 11 Feb 2004 21:52:13 -0000 1.20 +++ ospfd/ospf_interface.c 17 Feb 2004 19:17:51 -0000 @@ -487,20 +487,11 @@ void ospf_if_stream_unset (struct ospf_interface *oi) { - struct ospf *ospf = oi->ospf; - if (oi->obuf) { ospf_fifo_free (oi->obuf); oi->obuf = NULL; - - if (oi->on_write_q) - { - listnode_delete (ospf->oi_write_q, oi); - if (list_isempty(ospf->oi_write_q)) - OSPF_TIMER_OFF (ospf->t_write); - oi->on_write_q = 0; - } + OSPF_TIMER_OFF (oi->t_write); } } @@ -705,12 +696,20 @@ if (oi == NULL) return 0; + if (oi->type == OSPF_IFTYPE_LOOPBACK) OSPF_ISM_EVENT_SCHEDULE (oi, ISM_LoopInd); else { if (oi->type != OSPF_IFTYPE_VIRTUALLINK) - ospf_if_add_allspfrouters (oi->ospf, oi->address, oi->ifp->ifindex); + { + /* setup socket and read thread */ + oi->fd = ospf_sock_init (); + if (oi->fd < 0) + return 0; + ospf_if_add_allspfrouters (oi, oi->address, oi->ifp->ifindex); + oi->t_read = thread_add_read (master, ospf_read, oi, oi->fd); + } ospf_if_stream_set (oi); OSPF_ISM_EVENT_SCHEDULE (oi, ISM_InterfaceUp); } @@ -728,8 +727,9 @@ /* Shutdown packet reception and sending */ ospf_if_stream_unset (oi); if (oi->type != OSPF_IFTYPE_VIRTUALLINK) - ospf_if_drop_allspfrouters (oi->ospf, oi->address, oi->ifp->ifindex); + ospf_if_drop_allspfrouters (oi, oi->address, oi->ifp->ifindex); + close (oi->fd); return 1; } Index: ospfd/ospf_interface.h =================================================================== RCS file: /var/cvsroot/quagga/ospfd/ospf_interface.h,v retrieving revision 1.2 diff -u -w -b -r1.2 ospf_interface.h --- ospfd/ospf_interface.h 11 Feb 2004 21:52:13 -0000 1.2 +++ ospfd/ospf_interface.h 17 Feb 2004 19:17:52 -0000 @@ -100,6 +100,13 @@ /* This interface's parent ospf instance. */ struct ospf *ospf; + /* Interfaces read and write threads */ + struct thread *t_write; + struct thread *t_read; + + /* socket file descriptor */ + int fd; + /* OSPF Area. */ struct ospf_area *area; Index: ospfd/ospf_ism.c =================================================================== RCS file: /var/cvsroot/quagga/ospfd/ospf_ism.c,v retrieving revision 1.3 diff -u -w -b -r1.3 ospf_ism.c --- ospfd/ospf_ism.c 25 Mar 2003 05:07:53 -0000 1.3 +++ ospfd/ospf_ism.c 17 Feb 2004 19:17:52 -0000 @@ -254,15 +254,16 @@ !IPV4_ADDR_SAME (&old_bdr, &BDR (oi))) ospf_dr_change (oi->ospf, oi->nbrs); - if (oi->type == OSPF_IFTYPE_BROADCAST || oi->type == OSPF_IFTYPE_POINTOPOINT) + if (oi->type == OSPF_IFTYPE_BROADCAST + || oi->type == OSPF_IFTYPE_POINTOPOINT) { /* Multicast group change. */ if ((old_state != ISM_DR && old_state != ISM_Backup) && (new_state == ISM_DR || new_state == ISM_Backup)) - ospf_if_add_alldrouters (oi->ospf, oi->address, oi->ifp->ifindex); + ospf_if_add_alldrouters (oi, oi->address, oi->ifp->ifindex); else if ((old_state == ISM_DR || old_state == ISM_Backup) && (new_state != ISM_DR && new_state != ISM_Backup)) - ospf_if_drop_alldrouters (oi->ospf, oi->address, oi->ifp->ifindex); + ospf_if_drop_alldrouters (oi, oi->address, oi->ifp->ifindex); } return new_state; Index: ospfd/ospf_ism.h =================================================================== RCS file: /var/cvsroot/quagga/ospfd/ospf_ism.h,v retrieving revision 1.1.1.2 diff -u -w -b -r1.1.1.2 ospf_ism.h --- ospfd/ospf_ism.h 4 Apr 2003 02:35:30 -0000 1.1.1.2 +++ ospfd/ospf_ism.h 17 Feb 2004 19:17:52 -0000 @@ -47,13 +47,7 @@ #define OSPF_ISM_EVENT_MAX 8 #define OSPF_ISM_WRITE_ON(O) \ - do \ - { \ - if (oi->on_write_q == 0) \ - { \ - listnode_add ((O)->oi_write_q, oi); \ - oi->on_write_q = 1; \ - } \ + do { \ if ((O)->t_write == NULL) \ (O)->t_write = \ thread_add_write (master, ospf_write, (O), (O)->fd); \ Index: ospfd/ospf_network.c =================================================================== RCS file: /var/cvsroot/quagga/ospfd/ospf_network.c,v retrieving revision 1.3 diff -u -w -b -r1.3 ospf_network.c --- ospfd/ospf_network.c 24 Oct 2003 00:49:17 -0000 1.3 +++ ospfd/ospf_network.c 17 Feb 2004 19:17:52 -0000 @@ -46,12 +46,12 @@ /* Join to the OSPF ALL SPF ROUTERS multicast group. */ int -ospf_if_add_allspfrouters (struct ospf *top, struct prefix *p, +ospf_if_add_allspfrouters (struct ospf_interface *oi, struct prefix *p, unsigned int ifindex) { int ret; - ret = setsockopt_multicast_ipv4 (top->fd, IP_ADD_MEMBERSHIP, + ret = setsockopt_multicast_ipv4 (oi->fd, IP_ADD_MEMBERSHIP, p->u.prefix4, htonl (OSPF_ALLSPFROUTERS), ifindex); if (ret < 0) @@ -65,12 +65,12 @@ } int -ospf_if_drop_allspfrouters (struct ospf *top, struct prefix *p, +ospf_if_drop_allspfrouters (struct ospf_interface *oi, struct prefix *p, unsigned int ifindex) { int ret; - ret = setsockopt_multicast_ipv4 (top->fd, IP_DROP_MEMBERSHIP, + ret = setsockopt_multicast_ipv4 (oi->fd, IP_DROP_MEMBERSHIP, p->u.prefix4, htonl (OSPF_ALLSPFROUTERS), ifindex); if (ret < 0) @@ -85,12 +85,12 @@ /* Join to the OSPF ALL Designated ROUTERS multicast group. */ int -ospf_if_add_alldrouters (struct ospf *top, struct prefix *p, unsigned int - ifindex) +ospf_if_add_alldrouters (struct ospf_interface *oi, struct prefix *p, + unsigned int ifindex) { int ret; - ret = setsockopt_multicast_ipv4 (top->fd, IP_ADD_MEMBERSHIP, + ret = setsockopt_multicast_ipv4 (oi->fd, IP_ADD_MEMBERSHIP, p->u.prefix4, htonl (OSPF_ALLDROUTERS), ifindex); if (ret < 0) @@ -104,12 +104,12 @@ } int -ospf_if_drop_alldrouters (struct ospf *top, struct prefix *p, unsigned int - ifindex) +ospf_if_drop_alldrouters (struct ospf_interface *oi, struct prefix *p, + unsigned int ifindex) { int ret; - ret = setsockopt_multicast_ipv4 (top->fd, IP_DROP_MEMBERSHIP, + ret = setsockopt_multicast_ipv4 (oi->fd, IP_DROP_MEMBERSHIP, p->u.prefix4, htonl (OSPF_ALLDROUTERS), ifindex); if (ret < 0) @@ -123,7 +123,8 @@ } int -ospf_if_ipmulticast (struct ospf *top, struct prefix *p, unsigned int ifindex) +ospf_if_ipmulticast (struct ospf_interface *oi, struct prefix *p, + unsigned int ifindex) { u_char val; int ret, len; @@ -132,17 +133,17 @@ len = sizeof (val); /* Prevent receiving self-origined multicast packets. */ - ret = setsockopt (top->fd, IPPROTO_IP, IP_MULTICAST_LOOP, (void *)&val, len); + ret = setsockopt (oi->fd, IPPROTO_IP, IP_MULTICAST_LOOP, (void *)&val, len); if (ret < 0) zlog_warn ("can't setsockopt IP_MULTICAST_LOOP(0): %s", strerror (errno)); /* Explicitly set multicast ttl to 1 -- endo. */ val = 1; - ret = setsockopt (top->fd, IPPROTO_IP, IP_MULTICAST_TTL, (void *)&val, len); + ret = setsockopt (oi->fd, IPPROTO_IP, IP_MULTICAST_TTL, (void *)&val, len); if (ret < 0) zlog_warn ("can't setsockopt IP_MULTICAST_TTL(1): %s", strerror (errno)); - ret = setsockopt_multicast_ipv4 (top->fd, IP_MULTICAST_IF, + ret = setsockopt_multicast_ipv4 (oi->fd, IP_MULTICAST_IF, p->u.prefix4, 0, ifindex); if (ret < 0) zlog_warn ("can't setsockopt IP_MULTICAST_IF: %s", strerror (errno)); Index: ospfd/ospf_network.h =================================================================== RCS file: /var/cvsroot/quagga/ospfd/ospf_network.h,v retrieving revision 1.1.1.1 diff -u -w -b -r1.1.1.1 ospf_network.h --- ospfd/ospf_network.h 13 Dec 2002 20:15:30 -0000 1.1.1.1 +++ ospfd/ospf_network.h 17 Feb 2004 19:17:52 -0000 @@ -24,11 +24,16 @@ #define _ZEBRA_OSPF_NETWORK_H /* Prototypes. */ -int ospf_if_add_allspfrouters (struct ospf *, struct prefix *, unsigned int); -int ospf_if_drop_allspfrouters (struct ospf *, struct prefix *, unsigned int); -int ospf_if_add_alldrouters (struct ospf *, struct prefix *, unsigned int); -int ospf_if_drop_alldrouters (struct ospf *, struct prefix *, unsigned int); -int ospf_if_ipmulticast (struct ospf *, struct prefix *, unsigned int); +int ospf_if_add_allspfrouters (struct ospf_interface *, struct prefix *, + unsigned int); +int ospf_if_drop_allspfrouters (struct ospf_interface *, struct prefix *, + unsigned int); +int ospf_if_add_alldrouters (struct ospf_interface *, struct prefix *, + unsigned int); +int ospf_if_drop_alldrouters (struct ospf_interface *, struct prefix *, + unsigned int); +int ospf_if_ipmulticast (struct ospf_interface *, struct prefix *, + unsigned int); int ospf_sock_init (void); #endif /* _ZEBRA_OSPF_NETWORK_H */ Index: ospfd/ospf_packet.c =================================================================== RCS file: /var/cvsroot/quagga/ospfd/ospf_packet.c,v retrieving revision 1.25 diff -u -w -b -r1.25 ospf_packet.c --- ospfd/ospf_packet.c 11 Feb 2004 21:10:19 -0000 1.25 +++ ospfd/ospf_packet.c 17 Feb 2004 19:17:55 -0000 @@ -482,7 +482,7 @@ int ospf_write (struct thread *thread) { - struct ospf *ospf = THREAD_ARG (thread); + struct ospf *ospf; struct ospf_interface *oi; struct ospf_packet *op; struct sockaddr_in sa_dst; @@ -492,13 +492,12 @@ u_char type; int ret; int flags = 0; - listnode node; - ospf->t_write = NULL; + oi = THREAD_ARG (thread); + ospf = oi->ospf; + + oi->t_write = NULL; - node = listhead (ospf->oi_write_q); - assert (node); - oi = getdata (node); assert (oi); /* Get one packet from queue. */ @@ -508,7 +507,7 @@ if (op->dst.s_addr == htonl (OSPF_ALLSPFROUTERS) || op->dst.s_addr == htonl (OSPF_ALLDROUTERS)) - ospf_if_ipmulticast (ospf, oi->address, oi->ifp->ifindex); + ospf_if_ipmulticast (oi, oi->address, oi->ifp->ifindex); /* Rewrite the md5 signature & update the seq */ ospf_make_md5_digest (oi, op); @@ -555,7 +554,7 @@ iov[1].iov_base = STREAM_DATA (op->s); iov[1].iov_len = op->length; - ret = sendmsg (ospf->fd, &msg, flags); + ret = sendmsg (oi->fd, &msg, flags); if (ret < 0) zlog_warn ("*** sendmsg in ospf_write to %s failed with %s", @@ -586,17 +585,13 @@ /* Now delete packet from queue. */ ospf_packet_delete (oi); - if (ospf_fifo_head (oi->obuf) == NULL) + /* If packets still remain in queue, call write thread. */ + if (ospf_fifo_head (oi->obuf) != NULL) { - oi->on_write_q = 0; - list_delete_node (ospf->oi_write_q, node); + oi->t_write = + thread_add_write (master, ospf_write, oi, oi->fd); } - /* If packets still remain in queue, call write thread. */ - if (!list_isempty (ospf->oi_write_q)) - ospf->t_write = - thread_add_write (master, ospf_write, ospf, ospf->fd); - return 0; } @@ -2275,18 +2270,19 @@ struct interface *ifp; /* first of all get interface pointer. */ - ospf = THREAD_ARG (thread); - ospf->t_read = NULL; + oi = THREAD_ARG (thread); + ospf = oi->ospf; + oi->t_read = NULL; /* read OSPF packet. */ - ibuf = ospf_recv_packet (ospf->fd, &ifp); + ibuf = ospf_recv_packet (oi->fd, &ifp); if (ibuf == NULL) return -1; iph = (struct ip *) STREAM_DATA (ibuf); /* prepare for next packet. */ - ospf->t_read = thread_add_read (master, ospf_read, ospf, ospf->fd); + oi->t_read = thread_add_read (master, ospf_read, oi, oi->fd); /* IP Header dump. */ if (IS_DEBUG_OSPF_PACKET(0, RECV)) @@ -2310,9 +2306,9 @@ /* Get ospf packet header. */ ospfh = (struct ospf_header *) STREAM_PNT (ibuf); - /* associate packet with ospf interface */ - oi = ospf_if_lookup_recv_if (ospf, iph->ip_src); - if (ifp && oi && oi->ifp != ifp) + /* check association of packet with ospf interface */ + if (ospf_if_lookup_recv_if (ospf, iph->ip_src) != oi + || oi->ifp != ifp) { zlog_warn ("Packet from [%s] received on wrong link %s", inet_ntoa (iph->ip_src), ifp->name); @@ -2870,7 +2866,7 @@ ospf_packet_add (oi, op); /* Hook thread to write packet. */ - OSPF_ISM_WRITE_ON (oi->ospf); + OSPF_ISM_WRITE_ON (oi); } void @@ -3005,7 +3001,7 @@ /* Add packet to the interface output queue. */ ospf_packet_add (oi, op_dup); - OSPF_ISM_WRITE_ON (oi->ospf); + OSPF_ISM_WRITE_ON (oi); } } @@ -3023,7 +3019,7 @@ ospf_packet_add (oi, op); /* Hook thread to write packet. */ - OSPF_ISM_WRITE_ON (oi->ospf); + OSPF_ISM_WRITE_ON (oi); } } @@ -3057,7 +3053,7 @@ ospf_packet_add (oi, op); /* Hook thread to write packet. */ - OSPF_ISM_WRITE_ON (oi->ospf); + OSPF_ISM_WRITE_ON (oi); /* Remove old DD packet, then copy new one and keep in neighbor structure. */ if (nbr->last_send) @@ -3078,7 +3074,7 @@ ospf_packet_add (oi, ospf_packet_dup (nbr->last_send)); /* Hook thread to write packet. */ - OSPF_ISM_WRITE_ON (oi->ospf); + OSPF_ISM_WRITE_ON (oi); } /* Send Link State Request. */ @@ -3116,7 +3112,7 @@ ospf_packet_add (oi, op); /* Hook thread to write packet. */ - OSPF_ISM_WRITE_ON (oi->ospf); + OSPF_ISM_WRITE_ON (oi); /* Add Link State Request Retransmission Timer. */ OSPF_NSM_TIMER_ON (nbr->t_ls_req, ospf_ls_req_timer, nbr->v_ls_req); @@ -3169,7 +3165,7 @@ ospf_packet_add (oi, op); /* Hook thread to write packet. */ - OSPF_ISM_WRITE_ON (oi->ospf); + OSPF_ISM_WRITE_ON (oi); } static int @@ -3282,7 +3278,7 @@ ospf_packet_add (oi, op); /* Hook thread to write packet. */ - OSPF_ISM_WRITE_ON (oi->ospf); + OSPF_ISM_WRITE_ON (oi); } static int Index: ospfd/ospfd.c =================================================================== RCS file: /var/cvsroot/quagga/ospfd/ospfd.c,v retrieving revision 1.19 diff -u -w -b -r1.19 ospfd.c --- ospfd/ospfd.c 5 Dec 2003 14:01:43 -0000 1.19 +++ ospfd/ospfd.c 17 Feb 2004 19:17:55 -0000 @@ -230,11 +230,6 @@ new, new->lsa_refresh_interval); new->lsa_refresher_started = time (NULL); - new->fd = ospf_sock_init (); - if (new->fd >= 0) - new->t_read = thread_add_read (master, ospf_read, new, new->fd); - new->oi_write_q = list_new (); - return new; } @@ -382,10 +377,6 @@ OSPF_TIMER_OFF (ospf->t_abr_task); OSPF_TIMER_OFF (ospf->t_distribute_update); OSPF_TIMER_OFF (ospf->t_lsa_refresher); - OSPF_TIMER_OFF (ospf->t_read); - OSPF_TIMER_OFF (ospf->t_write); - - close (ospf->fd); #ifdef HAVE_OPAQUE_LSA LSDB_LOOP (OPAQUE_AS_LSDB (ospf), rn, lsa) Index: ospfd/ospfd.h =================================================================== RCS file: /var/cvsroot/quagga/ospfd/ospfd.h,v retrieving revision 1.8 diff -u -w -b -r1.8 ospfd.h --- ospfd/ospfd.h 12 Jul 2003 21:30:57 -0000 1.8 +++ ospfd/ospfd.h 17 Feb 2004 19:17:56 -0000 @@ -245,11 +245,6 @@ struct thread *t_maxage; /* MaxAge LSA remover timer. */ struct thread *t_maxage_walker; /* MaxAge LSA checking timer. */ - struct thread *t_write; - struct thread *t_read; - int fd; - list oi_write_q; - /* Distribute lists out of other route sources. */ struct {