Date: Tue, 11 Apr 2000 13:40:49 -0700 From: "Wilbert de Graaf" <wilbertdg@hetnet.nl> To: "FreeBSD-hackers" <FreeBSD-hackers@FreeBSD.ORG> Subject: Refresh a list that could be used Message-ID: <007501bfa3f6$556cf6f0$fec92080@alias>
next in thread | raw e-mail | index | archive | help
[-- Attachment #1 --]
Hi,
As part of an IGMPv3 implementation on FreeBSD I had to add a list to a datastructure (in_multi). This list can be set by users (using ioctl) and be replaced later. While replacing this list, there is the possibility (ad1) of a concurrent reader (the process when an incoming packet has to be passed to a socket). So just replacing this list and deleting the old one makes no sense.
There could think of two ways to implement this:
1) a locking strategy: lock when updating and while being used ... however, this slows down the process of incoming packets
-or-
2) simply save the old list, and delete it at the next replacement of the list (ad 2)
Or is there a common strategy in FreeBSD to handle a situation like this ? Could anybody comment on this.
Thanks, Wilbert
Ad 1)
It is true that this replacement of the list will *not* preempt in this case since the reader is delivery of an ip packet to a socket, which is done at splnet(), while this routine doesn't even use splimp(). But this precaution is just to make sure it will be safe in the case of multi-processors. Or did I miss something ?
Ad 2)
struct in_multi {
...
struct isf_entry *inm_sflist, *inm_sfoldlist; /* source filter list */
...
};
While replacing the list, the old one is stored in inm_sfoldlist, so current readers won't be harmed by invalid pointers while deleting the list. At a next replacement, the old list is simply deleted since the assumption is really valid that there won't be any readers of the old list. (Not eve when a multi-threaded program starts to fool around with the filterlist).
Btw. There will be a hashing schema over this structure, to determine whether a source ip is in the set.
[-- Attachment #2 --]
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META content="text/html; charset=iso-8859-1" http-equiv=Content-Type>
<META content="MSHTML 5.00.2920.0" name=GENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=#ffffff>
<DIV><FONT face=Arial size=2>Hi,</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=Arial size=2>As part of an IGMPv3 implementation on FreeBSD I
had to add a list to a datastructure (in_multi). This list can be set by users
(using ioctl) and be replaced later.</FONT><FONT face=Arial size=2> While
replacing this list, there is the possibility (ad1) of a concurrent reader (the
process when an incoming packet has to be passed to a socket). So just
replacing this list and deleting the old one makes no sense.</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=Arial size=2>There could think of two ways to implement
this:</FONT></DIV>
<DIV><FONT face=Arial size=2>1) a locking strategy: lock when updating and while
being used ... however, this slows down the process of incoming
packets</FONT></DIV>
<DIV><FONT face=Arial size=2>-or-</FONT></DIV>
<DIV><FONT face=Arial size=2>2) simply save the old list, and delete it at the
next replacement of the list (ad 2)</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=Arial size=2>Or is there a common strategy in FreeBSD to handle
a situation like this ? Could anybody comment on this. </FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=Arial size=2>Thanks, Wilbert</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=Arial size=2>Ad 1)</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=Arial size=2>
<DIV><FONT face=Arial size=2>It is true that this replacement of the
list will *not* preempt in this case since the reader is delivery of
an ip packet to a socket, which is done at splnet(), while this routine
doesn't even use splimp(). But this precaution is just to make sure it will be
safe in the case of multi-processors. Or did I miss something ?</FONT></DIV>
<DIV> </DIV>Ad 2)</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=Arial size=2>struct in_multi {</FONT></DIV>
<DIV><FONT face=Arial size=2> ...</FONT></DIV>
<DIV><FONT face=Arial size=2> struct isf_entry *inm_sflist,
*inm_sfoldlist; /* source filter list
*/</FONT></DIV>
<DIV><FONT face=Arial size=2> ...</FONT></DIV>
<DIV><FONT face=Arial size=2>};</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=Arial size=2>While replacing the list, the old one is stored in
inm_sfoldlist, so current readers won't be harmed by invalid pointers while
deleting the list. At a next replacement, the old list is simply deleted since
the assumption is really valid that there won't be any readers of the old list.
(Not eve when a multi-threaded program starts to fool around with the
filterlist).</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>Btw. There will be a hashing schema over this
structure, to determine whether a source ip is in the set.</FONT></DIV>
<DIV> </DIV></BODY></HTML>
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?007501bfa3f6$556cf6f0$fec92080>
