SCTP Discussions

Text archives Help


[SCTP-Discussion] [PATCH] various sctplib-1.0.0-pre7 improvements and fixes


Chronological Thread 
  • From: Marc Boucher <marc+sctp AT mbsi.ca>
  • To: discussion AT sctp.de
  • Subject: [SCTP-Discussion] [PATCH] various sctplib-1.0.0-pre7 improvements and fixes
  • Date: Fri Mar 23 16:22:01 2001
  • List-id: SCTP Discussions <discussion.sctp.de>

Hello Andreas, Michael, everyone,

Please find enclosed a patch against sctplib-1.0.0-pre7, which
implements the following changes:

- generalized callback mechanism, sctp_[un]registerStdinCallback() replaced
with sctp_[un]registerUserCallback() which works on any user file-descriptor.
Note that sctp_socketCallback and sctp_userCallback functions
are called with different arguments.

- revamped dispatch_event(). please double-check it for possible
new problems. however we have successfully tested on several platforms.

- as initial/invalid value for sctp_sfd and other socket descriptors
use -1 instead of 0 (which can theoretically be a valid socket fd).

- corrected some non-ansi function() prototypes which ought to
be function(void).

- added configure check for random(), else use srand() [may be weaker?]
on platforms that don't have it.

- added missing '=' to (with_ipv[46]=TRUE)? ... tests in event_log* calls.

- read_tracelevels(): globalTrace should default to FALSE if no
tracelevels.in file exists.

- added sctp_setglobaltrace() and sctp_setlogfile() functions
for manipulation of globalTrace and fileTrace by programs using the
library. (TODO: documentation)

- changed debug_print() calls in a few places to output to logfile
(if active) instead of stdout.

- added DLL_NULL_LIST check to get_msecs_to_nexttimer()


Freundliche Gruesse
Marc Boucher


diff -urN sctplib-1.0.0-pre7/config.h.in sctplib-1.0.0-pre7-marc/config.h.in
--- sctplib-1.0.0-pre7/config.h.in Tue Feb 13 12:19:28 2001
+++ sctplib-1.0.0-pre7-marc/config.h.in Fri Mar 23 15:50:21 2001
@@ -86,6 +86,9 @@
/* Define if you have the poll function. */
#undef HAVE_POLL

+/* Define if you have the random function. */
+#undef HAVE_RANDOM
+
/* Define if you have the setuid function. */
#undef HAVE_SETUID

diff -urN sctplib-1.0.0-pre7/configure sctplib-1.0.0-pre7-marc/configure
--- sctplib-1.0.0-pre7/configure Fri Mar 16 18:51:40 2001
+++ sctplib-1.0.0-pre7-marc/configure Fri Mar 23 15:50:21 2001
@@ -1994,7 +1994,7 @@
echo "$ac_t""$ac_cv_func_memcmp_clean" 1>&6
test $ac_cv_func_memcmp_clean = no && LIBOBJS="$LIBOBJS memcmp.${ac_objext}"

-for ac_func in gettimeofday socket strerror poll getuid setuid
+for ac_func in gettimeofday socket strerror poll getuid setuid random
do
echo $ac_n "checking for $ac_func""... $ac_c" 1>&6
echo "configure:2001: checking for $ac_func" >&5
diff -urN sctplib-1.0.0-pre7/configure.in sctplib-1.0.0-pre7-marc/configure.in
--- sctplib-1.0.0-pre7/configure.in Fri Mar 16 02:51:26 2001
+++ sctplib-1.0.0-pre7-marc/configure.in Fri Mar 23 15:47:50 2001
@@ -146,7 +146,7 @@
dnl Checks for library functions.
AC_FUNC_VPRINTF
AC_FUNC_MEMCMP
-AC_CHECK_FUNCS(gettimeofday socket strerror poll getuid setuid)
+AC_CHECK_FUNCS(gettimeofday socket strerror poll getuid setuid random)

AC_CHECK_FUNCS(getaddrinfo, [have_getaddrinfo=yes], [have_getaddrinfo=no])

diff -urN sctplib-1.0.0-pre7/sctplib/sctp/adaptation.c
sctplib-1.0.0-pre7-marc/sctplib/sctp/adaptation.c
--- sctplib-1.0.0-pre7/sctplib/sctp/adaptation.c Fri Mar 16 14:44:26
2001
+++ sctplib-1.0.0-pre7-marc/sctplib/sctp/adaptation.c Thu Mar 22 21:25:35
2001
@@ -118,24 +118,22 @@
#define POLL_FD_UNUSED -1
#define NUM_FDS 20

+#define EVENTCB_TYPE_SCTP 1
+#define EVENTCB_TYPE_UDP 2
+#define EVENTCB_TYPE_USER 3
+
/**
* Structure for callback events. The function "action" is called by the
event-handler,
- * when a socket gets data or the ULP is to be notified of some conditions.
- * The function (action) takes five arguments :
- * 1. socket fd, where event occurred
- * 2. pointer to a (static) buffer where the data sits
- * 3. an integer that contains the length of the data
- * 4. pointer to the address where data came from
- * @param size of the address/sockaddr_in, the origin of the message
+ * when an event occurs on the file-descriptor.
*/
struct event_cb
{
int sfd;
- int event_type;
+ int eventcb_type;
/* pointer to possible arguments, associations etc. */
void *arg1;
void *arg2;
- void (*action) (int, unsigned char *, int, unsigned char[], unsigned
short);
+ void (*action) ();
};


@@ -148,15 +146,13 @@
static struct pollfd poll_fds[NUM_FDS];
static int num_of_fds = 0;

-static sctp_stdinCallback stdinCB = NULL;
-
-static int sctp_sfd = 0; /* socket fd for standard SCTP port.... */
+static int sctp_sfd = -1; /* socket fd for standard SCTP port.... */
#ifdef HAVE_IPV6
-static int sctpv6_sfd = 0;
+static int sctpv6_sfd = -1;
#endif

/* will be added back later....
- static int icmp_sfd = 0; */ /* socket fd for ICMP messages */
+ static int icmp_sfd = -1; */ /* socket fd for ICMP messages */

static struct event_cb *event_callbacks[NUM_FDS];

@@ -369,7 +365,11 @@
int dest_len;
int result;

- if ((sfd == sctp_sfd) || (sfd == 0)
+ if (sfd < 0) {
+ error_log(ERROR_MAJOR, "You are trying to send UDP data to an
invalid file descriptor");
+ return -1;
+ }
+ if ((sfd == sctp_sfd)
#ifdef HAVE_IPV6
|| (sfd == sctpv6_sfd)
#endif
@@ -538,8 +538,8 @@
* that are pointed to by the event_callback struct
*/
int
-adl_register_fd_cb(int sfd, int event_mask,
- void (*action) (int, unsigned char *, int, unsigned
char[], unsigned short))
+adl_register_fd_cb(int sfd, int eventcb_type, int event_mask,
+ void *action)
{
if (num_of_fds < NUM_FDS) {
assign_poll_fd(num_of_fds, sfd, event_mask);
@@ -547,7 +547,7 @@
if (!event_callbacks[num_of_fds])
error_log(ERROR_FATAL, "Could not allocate memory in
register_fd_cb \n");
event_callbacks[num_of_fds]->sfd = sfd;
- event_callbacks[num_of_fds]->event_type = 0;
+ event_callbacks[num_of_fds]->eventcb_type = eventcb_type;
event_callbacks[num_of_fds]->action = action;
num_of_fds++;
return num_of_fds;
@@ -580,12 +580,11 @@
* this function is responsible for calling the callback functions belonging
* to all of the file descriptors that have indicated an event !
* TODO : check handling of POLLERR situation
- * TODO : check handling of several read events at once
* @param num_of_events number of events indicated by poll()
*/
void dispatch_event(int num_of_events)
{
- int i = 0, j = 0;
+ int i = 0;
int length=0, src_len;
union sockunion src;
struct sockaddr_in *src_in;
@@ -599,113 +598,97 @@
#endif
int hlen;

- if (num_of_events > 1)
- error_log(ERROR_MINOR, "Several events in one poll !");
-
- for (j = 0; j < num_of_events; j++) {
- for (i = 0; i < num_of_fds; i++) {
- if (poll_fds[i].revents) {
- if (poll_fds[i].revents & POLLERR) {
- /* We must have specified this callback funtion for
treating/logging the error */
- error_log(ERROR_MINOR, "Poll Error Condition ");
- hlen = 0;
- length = 0;
- src_len = 0;
- (*(event_callbacks[i]->action)) (poll_fds[i].fd,
&rbuf[hlen], length, NULL, src_len);
- break;
- }
-
- src_len = sizeof(src);
-
- if ((poll_fds[i].revents & POLLPRI) || (poll_fds[i].revents
& POLLIN)) {
+ for (i = 0; i < num_of_fds; i++) {
+ if (!poll_fds[i].revents)
+ continue;
+
+ if (poll_fds[i].revents & POLLERR) {
+ /* We must have specified this callback funtion for
treating/logging the error */
+ if (event_callbacks[i]->eventcb_type == EVENTCB_TYPE_USER) {
+ event_logi(VERBOSE, "Poll Error Condition on user fd %d",
poll_fds[i].fd);
+ ((sctp_userCallback)*(event_callbacks[i]->action))
(poll_fds[i].fd, poll_fds[i].revents);
+ } else {
+ error_logi(ERROR_MINOR, "Poll Error Condition on fd %d",
poll_fds[i].fd);
+ ((sctp_socketCallback)*(event_callbacks[i]->action))
(poll_fds[i].fd, NULL, 0, NULL, 0);
+ }
+ }

- if ( ((sctp_sfd !=0) && (poll_fds[i].fd != sctp_sfd))
+ if ((poll_fds[i].revents & POLLPRI) || (poll_fds[i].revents &
POLLIN)) {
+ if (event_callbacks[i]->eventcb_type == EVENTCB_TYPE_USER) {
+ event_logi(VERBOSE, "Activity on user fd %d - Activating
USER callback", poll_fds[i].fd);
+ ((sctp_userCallback)*(event_callbacks[i]->action))
(poll_fds[i].fd, poll_fds[i].revents);
+ } else if (event_callbacks[i]->eventcb_type == EVENTCB_TYPE_UDP)
{
+ src_len = sizeof(src);
+ length = adl_get_message(poll_fds[i].fd, rbuf,
MAX_MTU_SIZE, &src, &src_len);
+ event_logi(VERBOSE, "Message %d bytes - Activating UDP
callback", length);
+ adl_sockunion2str(&src, src_address, SCTP_MAX_IP_LEN);
+ switch (sockunion_family(&src)) {
+ case AF_INET :
+ portnum = ntohs(src.sin.sin_port);
+ break;
#ifdef HAVE_IPV6
- && ((sctpv6_sfd != 0) && (poll_fds[i].fd !=
sctpv6_sfd))
+ case AF_INET6:
+ portnum = ntohs(src.sin6.sin6_port);
+ break;
#endif
- ) {
- /* then it must either be STDIN or a UDP callback */
- if (poll_fds[i].fd == 0) {
- src_len = 0;
+ default:
portnum = 0;
- event_logi(VERBOSE, "Message %d bytes -
Activating STDIN callback", length);
- (*(event_callbacks[i]->action)) (0, rbuf,
length, NULL, portnum);
- }else {
- length = adl_get_message(poll_fds[i].fd, rbuf,
MAX_MTU_SIZE, &src, &src_len);
-
- event_logi(VERBOSE, "Message %d bytes -
Activating UDP callback", length);
- adl_sockunion2str(&src, src_address,
SCTP_MAX_IP_LEN);
- switch (sockunion_family(&src)) {
- case AF_INET :
- portnum = ntohs(src.sin.sin_port);
- break;
-#ifdef HAVE_IPV6
- case AF_INET6:
- portnum = ntohs(src.sin6.sin6_port);
- break;
-#endif
- default:
- portnum = 0;
- break;
- }
- (*(event_callbacks[i]->action)) (poll_fds[i].fd,
rbuf, length, src_address, portnum);
- }
- } else {
- length = adl_get_message(poll_fds[i].fd, rbuf,
MAX_MTU_SIZE, &src, &src_len);
-
- event_logiii(VERBOSE, "SCTP-Message on socket %u ,
len=%d, portnum=%d",
- poll_fds[i].fd, length, portnum);
- switch (sockunion_family(&src)) {
-
- case AF_INET:
- src_in = (struct sockaddr_in *) &src;
- src_len = sizeof(struct sockaddr_in);
- event_logi(VERBOSE, "IPv4/SCTP-Message from %s
-> activating callback",
- inet_ntoa(src_in->sin_addr));
+ break;
+ }
+ ((sctp_socketCallback)*(event_callbacks[i]->action))
(poll_fds[i].fd, rbuf, length, src_address, portnum);
+ } else if (event_callbacks[i]->eventcb_type ==
EVENTCB_TYPE_SCTP) {
+ src_len = sizeof(src);
+ length = adl_get_message(poll_fds[i].fd, rbuf, MAX_MTU_SIZE,
&src, &src_len);
+
+ event_logiii(VERBOSE, "SCTP-Message on socket %u , len=%d,
portnum=%d",
+ poll_fds[i].fd, length, portnum);
+ switch (sockunion_family(&src)) {
+
+ case AF_INET:
+ src_in = (struct sockaddr_in *) &src;
+ src_len = sizeof(struct sockaddr_in);
+ event_logi(VERBOSE, "IPv4/SCTP-Message from %s ->
activating callback",
+ inet_ntoa(src_in->sin_addr));
#if !defined (LINUX)
- iph = (struct ip *) rbuf;
- hlen = iph->ip_hl << 2;
+ iph = (struct ip *) rbuf;
+ hlen = iph->ip_hl << 2;
#else
- iph = (struct iphdr *) rbuf;
- hlen = iph->ihl << 2;
+ iph = (struct iphdr *) rbuf;
+ hlen = iph->ihl << 2;
#endif
- if (length < hlen) {
- error_logii(ERROR_MINOR,
- "dispatch_event : packet too
short (%d bytes) from %s",
- length,
inet_ntoa(src_in->sin_addr));
- } else {
- length -= hlen;
- adl_sockunion2str(&src, src_address,
SCTP_MAX_IP_LEN);
- (*(event_callbacks[i]->action))
- (poll_fds[i].fd, &rbuf[hlen], length,
src_address, 0);
- }
- break;
+ if (length < hlen) {
+ error_logii(ERROR_MINOR,
+ "dispatch_event : packet too short (%d
bytes) from %s",
+ length, inet_ntoa(src_in->sin_addr));
+ } else {
+ length -= hlen;
+ adl_sockunion2str(&src, src_address,
SCTP_MAX_IP_LEN);
+ ((sctp_socketCallback)*(event_callbacks[i]->action))
+ (poll_fds[i].fd, &rbuf[hlen], length,
src_address, 0);
+ }
+ break;
#ifdef HAVE_IPV6
- case AF_INET6:
- adl_sockunion2str(&src, src_address,
SCTP_MAX_IP_LEN);
- /* if we have additional options, we must parse
them, and deduct the sizes :-( */
- event_logii(VERBOSE, "IPv6/SCTP-Message from %s
(%d bytes) -> activating callback",
- src_address, length);
+ case AF_INET6:
+ adl_sockunion2str(&src, src_address, SCTP_MAX_IP_LEN);
+ /* if we have additional options, we must parse them,
and deduct the sizes :-( */
+ event_logii(VERBOSE, "IPv6/SCTP-Message from %s (%d
bytes) -> activating callback",
+ src_address, length);

- (*(event_callbacks[i]->action))
- (poll_fds[i].fd, rbuf, length,
src_address, 0);
- break;
+ ((sctp_socketCallback)*(event_callbacks[i]->action))
+ (poll_fds[i].fd, rbuf, length, src_address,
0);
+ break;

#endif /* HAVE_IPV6 */
- default:
- error_logi(ERROR_MAJOR,
- "Unsupported Address Family Type ",
sockunion_family(&src));
- break;
+ default:
+ error_logi(ERROR_MAJOR,
+ "Unsupported Address Family Type ",
sockunion_family(&src));
+ break;

- }
- } /* else */
}
-
- } /* if (poll_fds[i].revents) */
- poll_fds[i].revents = 0;
-
- } /* for(i = 0; i < num_of_fds; i++) */
- } /* for(j = 0; i < num_of_events; j++) */
+ }
+ }
+ poll_fds[i].revents = 0;
+ } /* for(i = 0; i < num_of_fds; i++) */
}


@@ -941,7 +924,7 @@
new_sfd = adl_open_udp_socket(&my_address);

if (new_sfd != -1) {
- result = adl_register_fd_cb(new_sfd, POLLIN | POLLPRI, scf);
+ result = adl_register_fd_cb(new_sfd, EVENTCB_TYPE_UDP, POLLIN |
POLLPRI, scf);
event_logi(INTERNAL_EVENT_0, "Registered ULP-Callback: now %d
registered callbacks !!!",result);
return new_sfd;
}
@@ -949,18 +932,6 @@
}


-static void adl_ReceiveStdin(gint socket_fd, unsigned char *buffer, int
bufferLength,
- unsigned char *hoststring, unsigned short
fromAddressLength)
-{
- if (stdinCB == NULL) {
- error_log(ERROR_MAJOR, " stdinCB is NULL, still STDIN Receiver
Function was invoked !");
- return;
- }
- (*stdinCB) ();
-}
-
-
-
/**
* this function is supposed to register a callback function for catching
* input from the Unix STDIN file descriptor. We expect this to be useful
@@ -968,39 +939,30 @@
* @param scf callback funtion that is called (when return is hit)
* @return 0, or -1 if error ocurred
*/
-int sctp_registerStdinCallback(sctp_stdinCallback sdf)
+int sctp_registerUserCallback(int fd, sctp_userCallback sdf)
{
int result;
- if (stdinCB != NULL) return -1; /* i.e. already used */
- stdinCB = sdf;
/* 0 is the standard input ! */
- result = adl_register_socket_cb(0, &adl_ReceiveStdin);
- if (result == -1) {
- stdinCB = NULL;
+ result = adl_register_fd_cb(fd, EVENTCB_TYPE_USER, POLLIN | POLLPRI,
sdf);
+ if (result != -1) {
+ event_logii(EXTERNAL_EVENT,"----------> Registered User Callback:
fd=%d result=%d -------\n", fd, result);
}
- event_logi(EXTERNAL_EVENT,"----------> Registered Stdin Callback:
result=%d -------\n", result);
return result;
}



-int sctp_unregisterStdinCallback(void)
+int sctp_unregisterUserCallback(int fd)
{
- if (stdinCB == NULL) return -1;
- adl_remove_poll_fd(0);
- stdinCB = NULL;
+ adl_remove_poll_fd(fd);
return 0;
}


-/**
- * This function should only be called in exceptional cases...e.g. when we
- * communicate with the ULP via an additional socket
- */
int
adl_register_socket_cb(gint sfd, sctp_socketCallback scf)
{
- return (adl_register_fd_cb(sfd, POLLIN | POLLPRI, scf));
+ return (adl_register_fd_cb(sfd, EVENTCB_TYPE_SCTP, POLLIN | POLLPRI,
scf));
}


diff -urN sctplib-1.0.0-pre7/sctplib/sctp/auxiliary.c
sctplib-1.0.0-pre7-marc/sctplib/sctp/auxiliary.c
--- sctplib-1.0.0-pre7/sctplib/sctp/auxiliary.c Thu Feb 15 15:19:38 2001
+++ sctplib-1.0.0-pre7-marc/sctplib/sctp/auxiliary.c Thu Mar 22 21:06:30
2001
@@ -39,6 +39,10 @@
#include <stdlib.h>
#include <stdio.h>

+#ifndef HAVE_RANDOM
+#define random() rand()
+#endif
+
#define BASE 65521L /* largest prime smaller than 65536 */
#define NMAX 5552

diff -urN sctplib-1.0.0-pre7/sctplib/sctp/bundling.h
sctplib-1.0.0-pre7-marc/sctplib/sctp/bundling.h
--- sctplib-1.0.0-pre7/sctplib/sctp/bundling.h Mon Mar 12 19:46:17 2001
+++ sctplib-1.0.0-pre7-marc/sctplib/sctp/bundling.h Thu Mar 22 21:06:30
2001
@@ -105,7 +105,7 @@
gint rbu_rcvDatagram(guint address_index, guchar * datagram, guint len);


-void bu_lock_sender();
+void bu_lock_sender(void);
void bu_unlock_sender(guint* ad_idx);

/**
diff -urN sctplib-1.0.0-pre7/sctplib/sctp/distribution.c
sctplib-1.0.0-pre7-marc/sctplib/sctp/distribution.c
--- sctplib-1.0.0-pre7/sctplib/sctp/distribution.c Tue Mar 13 15:14:45
2001
+++ sctplib-1.0.0-pre7-marc/sctplib/sctp/distribution.c Thu Mar 22 21:06:30
2001
@@ -237,7 +237,9 @@
static unsigned int lastPortSeized;
static unsigned int numberOfSeizedPorts;

+#ifdef HAVE_RANDOM
static long rstate[2];
+#endif


/* ---------------------- Internal Function Prototypes
------------------------------------------- */
@@ -1013,7 +1015,7 @@
event_logi(VERBOSE, "sctp_registerInstance : with_ipv4 : %s
",(with_ipv4==TRUE)?"TRUE":"FALSE" );
/* if not IPv6 callback must be registered too ! */
#ifdef HAVE_IPV6
- event_logi(VERBOSE, "sctp_registerInstance : with_ipv6: %s
",(with_ipv6=TRUE)?"TRUE":"FALSE" );
+ event_logi(VERBOSE, "sctp_registerInstance : with_ipv6: %s
",(with_ipv6==TRUE)?"TRUE":"FALSE" );
#endif

if ((with_ipv4 != TRUE)
@@ -1050,10 +1052,15 @@

/* initialize random number generator */
gettimeofday(&curTime, NULL);
+#ifdef HAVE_RANDOM
rstate[0] = curTime.tv_sec;
rstate[1] = curTime.tv_usec;
initstate(curTime.tv_sec, (char *) rstate, 8);
setstate((char *) rstate);
+#else
+ srand(curTime.tv_usec);
+#define random() rand()
+#endif

/* initialize bundling, i.e. the common buffer for sending chunks
when no association
exists. */
@@ -1164,12 +1171,12 @@
}
event_logi(INTERNAL_EVENT_0, "sctp_unregisterInstance: SCTP Instance
%u found !!!", instance_name);
#ifdef HAVE_IPV6
- event_logi(VERBOSE, "sctp_unregisterInstance : with_ipv6: %s
",(with_ipv6=TRUE)?"TRUE":"FALSE" );
+ event_logi(VERBOSE, "sctp_unregisterInstance : with_ipv6: %s
",(with_ipv6==TRUE)?"TRUE":"FALSE" );
if (with_ipv6 == TRUE) ipv6_users--;
event_logi(VERBOSE, "sctp_unregisterInstance : ipv6_users: %u
",ipv6_users);
#endif
if (with_ipv4 == TRUE) ipv4_users--;
- event_logi(VERBOSE, "sctp_unregisterInstance : with_ipv4: %s
",(with_ipv4=TRUE)?"TRUE":"FALSE" );
+ event_logi(VERBOSE, "sctp_unregisterInstance : with_ipv4: %s
",(with_ipv4==TRUE)?"TRUE":"FALSE" );
event_logi(VERBOSE, "sctp_unregisterInstance : ipv4_users: %u
",ipv4_users);

if (sctp_socket != 0 && ipv4_users == 0) {
diff -urN sctplib-1.0.0-pre7/sctplib/sctp/distribution.h
sctplib-1.0.0-pre7-marc/sctplib/sctp/distribution.h
--- sctplib-1.0.0-pre7/sctplib/sctp/distribution.h Mon Mar 12 19:27:57
2001
+++ sctplib-1.0.0-pre7-marc/sctplib/sctp/distribution.h Thu Mar 22 21:06:30
2001
@@ -131,10 +131,10 @@

/* indicates that communication has been gracefully terminated (10.2.H).
*/
-void mdi_shutdownCompleteNotif();
+void mdi_shutdownCompleteNotif(void);

/* indicates that a restart has occured (10.2.G.) */
-void mdi_restartNotif();
+void mdi_restartNotif(void);



@@ -300,7 +300,7 @@
int mdi_getDefaultPathMaxRetransmits(void* sctpInstance);
int mdi_getDefaultRtoMin(void* sctpInstance);
int mdi_getDefaultMaxInitRetransmits(void* sctpInstance);
-int mdi_getDefaultMyRwnd();
+int mdi_getDefaultMyRwnd(void);
int mdi_getDefaultDelay(void* sctpInstance);
int mdi_getDefaultIpTos(void* sctpInstance);
int mdi_getDefaultMaxSendQueue(void* sctpInstance);
diff -urN sctplib-1.0.0-pre7/sctplib/sctp/globals.c
sctplib-1.0.0-pre7-marc/sctplib/sctp/globals.c
--- sctplib-1.0.0-pre7/sctplib/sctp/globals.c Fri Feb 23 19:21:53 2001
+++ sctplib-1.0.0-pre7-marc/sctplib/sctp/globals.c Thu Mar 22 21:06:58
2001
@@ -112,13 +112,27 @@
if (i<= 1) globalTrace = TRUE;
// printf(" globalTrace = %s \n",
(globalTrace==TRUE)?"TRUE":"FALSE");
} else {
- globalTrace = TRUE;
+ globalTrace = FALSE;
}
// printf("global = %d, #of modules = %d\n", (int) globalTrace,
noOftracedModules);
// for (i = 0; i < noOftracedModules; i++)
// printf("%20s %2d %2d\n", tracedModules[i], errorTraceLevel[i],
eventTraceLevel[i]);
}

+void
+sctp_setglobaltrace(int flag)
+{
+ globalTrace = flag;
+}
+
+void
+sctp_setlogfile(FILE *file)
+{
+ fileTrace = FALSE;
+ logfile = file;
+ if(logfile != NULL)
+ fileTrace = TRUE;
+}


boolean traceModule(char *moduleName, int *moduleIndex)
@@ -185,7 +199,7 @@
#ifdef HAVE_GETTIMEOFDAY
gettimeofday(&now, NULL);
#endif
- debug_print(stdout, "Time now: %ld sec, %ld usec \n", now.tv_sec,
now.tv_usec);
+ debug_print((fileTrace == TRUE)?logfile:stdout, "Time now: %ld sec, %ld
usec \n", now.tv_sec, now.tv_usec);
}


@@ -213,11 +227,7 @@
&& event_log_level <= eventTraceLevel[mi])) {

if (event_log_level < VERBOSE) {
- if (fileTrace == TRUE) {
- debug_print(logfile, "Event in Module: %s............\n",
module_name);
- } else {
- debug_print(stdout, "Event in Module: %s............\n",
module_name);
- }
+ debug_print((fileTrace == TRUE)?logfile:stdout, "Event in
Module: %s............\n", module_name);
}
gettimeofday(&tv, NULL);
the_time = localtime((time_t *) & (tv.tv_sec));
diff -urN sctplib-1.0.0-pre7/sctplib/sctp/globals.h
sctplib-1.0.0-pre7-marc/sctplib/sctp/globals.h
--- sctplib-1.0.0-pre7/sctplib/sctp/globals.h Fri Mar 16 18:49:44 2001
+++ sctplib-1.0.0-pre7-marc/sctplib/sctp/globals.h Thu Mar 22 21:06:30
2001
@@ -241,5 +241,7 @@

#define sockunion_family(X) (X)->sa.sa_family

+extern FILE* logfile;
+extern boolean fileTrace;

#endif
diff -urN sctplib-1.0.0-pre7/sctplib/sctp/pathmanagement.h
sctplib-1.0.0-pre7-marc/sctplib/sctp/pathmanagement.h
--- sctplib-1.0.0-pre7/sctplib/sctp/pathmanagement.h Fri Mar 16 14:44:26
2001
+++ sctplib-1.0.0-pre7-marc/sctplib/sctp/pathmanagement.h Thu Mar 22
21:06:30 2001
@@ -119,7 +119,7 @@

/* pm_disableAllHB is called when on shutdown to disable all heartbeats.
*/
-void pm_disableAllHB();
+void pm_disableAllHB(void);



@@ -183,7 +183,7 @@
/* pm_readPrimaryPath returns the primary path.
Params: returns primary path
*/
-short pm_readPrimaryPath();
+short pm_readPrimaryPath(void);



diff -urN sctplib-1.0.0-pre7/sctplib/sctp/recvctrl.h
sctplib-1.0.0-pre7-marc/sctplib/sctp/recvctrl.h
--- sctplib-1.0.0-pre7/sctplib/sctp/recvctrl.h Mon Mar 5 16:23:27 2001
+++ sctplib-1.0.0-pre7-marc/sctplib/sctp/recvctrl.h Thu Mar 22 21:06:30
2001
@@ -77,7 +77,7 @@
/**
* Function returns the current cumulative TSN, that this association has
RECEIVED
*/
-unsigned int rxc_read_cummulativeTSNacked();
+unsigned int rxc_read_cummulativeTSNacked(void);

/**
* function called by bundling when a SACK is actually sent, to stop
diff -urN sctplib-1.0.0-pre7/sctplib/sctp/sctp.h
sctplib-1.0.0-pre7-marc/sctplib/sctp/sctp.h
--- sctplib-1.0.0-pre7/sctplib/sctp/sctp.h Fri Mar 16 14:44:26 2001
+++ sctplib-1.0.0-pre7-marc/sctplib/sctp/sctp.h Thu Mar 22 21:06:30 2001
@@ -421,16 +421,22 @@
int sctp_deleteAssociation(unsigned int associationID);


-/* Defines the callback function that is called when new data have been
received
- (Events POLLIN||POLLPRI )
- Params: 1. socketdescriptor of the socket where the datagramm has been
received
- 2. pointer to the datagramm data
- 3. length of datagramm data
+/* Defines the callback function that is called when an event occurs
+ on an internal SCTP or UDP socket
+ Params: 1. file-descriptor of the socket
+ 2. pointer to the datagram data, if any was received
+ 3. length of datagram data, if any was received
4. source Address (as string, may be IPv4 or IPv6 address
string, in numerical format)
- 5. source port number for UDP sockets, 0 for STDIN file
descriptor, 0 for SCTP raw sockets
+ 5. source port number for UDP sockets, 0 for SCTP raw sockets
*/
typedef void (*sctp_socketCallback) (int, unsigned char *, int, unsigned
char[] , unsigned short);
-typedef void (*sctp_stdinCallback) (void);
+
+/* Defines the callback function that is called when an event occurs
+ on a user file-descriptor
+ Params: 1. file-descriptor
+ Params: 2. received events mask
+*/
+typedef void (*sctp_userCallback) (int, short int);

/**
* this function is supposed to open and bind a UDP socket listening on a
port
@@ -450,14 +456,15 @@
unsigned char destination[], unsigned short dest_port);

/**
- * this function is supposed to register a callback function for catching
- * input from the Unix STDIN file descriptor. We expect this to be useful
+ * this function registers a callback function for catching
+ * activity on a Unix file descriptor. We expect this to be useful
* in test programs mainly, so it is provided here for convenience.
+ * @param fd file-descriptor
* @param scf callback funtion that is called (when return is hit)
* @return 0, or -1 if error ocurred (i.e. already used)
*/
-int sctp_registerStdinCallback(sctp_stdinCallback sdf);
-int sctp_unregisterStdinCallback(void);
+int sctp_registerUserCallback(int fd, sctp_userCallback sdf);
+int sctp_unregisterUserCallback(int fd);


/* Defines the callback function that is called when an timer expires.
@@ -511,5 +518,11 @@
int sctp_getEvents(void);

int sctp_eventLoop(void);
+
+void sctp_setglobaltrace(int flag);
+
+#include <stdio.h>
+void sctp_setlogfile(FILE *file);
+

#endif
diff -urN sctplib-1.0.0-pre7/sctplib/sctp/timer_list.c
sctplib-1.0.0-pre7-marc/sctplib/sctp/timer_list.c
--- sctplib-1.0.0-pre7/sctplib/sctp/timer_list.c Fri Feb 23 19:21:53
2001
+++ sctplib-1.0.0-pre7-marc/sctplib/sctp/timer_list.c Thu Mar 22 21:06:30
2001
@@ -235,18 +235,18 @@
{
AlarmTimer tmp;
if (event_log_level <= Current_event_log_) {
- printf("-------------Entering print_debug_list()
------------------------\n");
+ fprintf((fileTrace == TRUE)?logfile:stdout, "-------------Entering
print_debug_list() ------------------------\n");
if (timer_list == NULL) {
- printf("tlist pointer == NULL\n");
+ fprintf((fileTrace == TRUE)?logfile:stdout, "tlist pointer ==
NULL\n");
return;
}

if (DLL_CurrentPointerToHead(timer_list) != DLL_NORMAL) {
- printf("Timer-List is empty !\n");
+ fprintf((fileTrace == TRUE)?logfile:stdout, "Timer-List is empty
!\n");
return;
}
print_time();
- printf("List Length : %ld \n", DLL_GetNumberOfRecords(timer_list));
+ fprintf((fileTrace == TRUE)?logfile:stdout, "List Length : %ld \n",
DLL_GetNumberOfRecords(timer_list));

do {
DLL_GetCurrentRecord(timer_list, &tmp);
@@ -254,7 +254,7 @@
}
while (DLL_IncrementCurrentPointer(timer_list) == DLL_NORMAL);

- printf("-------------Leaving print_debug_list()
------------------------\n");
+ fprintf((fileTrace == TRUE)?logfile:stdout, "-------------Leaving
print_debug_list() ------------------------\n");
}
return;
}
@@ -279,6 +279,8 @@
#endif
result = DLL_CurrentPointerToHead(timer_list);
result = DLL_GetCurrentRecord(timer_list, &next);
+ if( result == DLL_NULL_LIST )
+ return -1;
secs = next.action_time.tv_sec - now.tv_sec;
usecs = next.action_time.tv_usec - now.tv_usec;
if (secs < 0)
diff -urN sctplib-1.0.0-pre7/sctplib/terminal/terminal.c
sctplib-1.0.0-pre7-marc/sctplib/terminal/terminal.c
--- sctplib-1.0.0-pre7/sctplib/terminal/terminal.c Fri Mar 16 18:49:44
2001
+++ sctplib-1.0.0-pre7-marc/sctplib/terminal/terminal.c Thu Mar 22 21:29:24
2001
@@ -231,7 +231,7 @@
sctp_deleteAssociation(assocID);
}

-void stdinCallback()
+void stdinCallback(int fd, short int revents)
{
unsigned char readBuffer[256];

@@ -280,7 +280,7 @@

associationID = sctp_associate(sctpInstance,
MAXIMUM_NUMBER_OF_OUT_STREAMS, destinationAddress, remotePort, NULL);

- sctp_registerStdinCallback(&stdinCallback);
+ sctp_registerUserCallback(fileno(stdin), &stdinCallback);

/* run the event handler forever */
while (sctp_eventLoop() >= 0);
diff -urN sctplib-1.0.0-pre7/sctplib/ulp/main.c
sctplib-1.0.0-pre7-marc/sctplib/ulp/main.c
--- sctplib-1.0.0-pre7/sctplib/ulp/main.c Mon Mar 12 19:27:57 2001
+++ sctplib-1.0.0-pre7-marc/sctplib/ulp/main.c Thu Mar 22 21:27:15 2001
@@ -494,7 +494,7 @@
}
}

- sctp_registerStdinCallback(&ulp_stdin_cb);
+ sctp_registerUserCallback(fileno(stdin), &ulp_stdin_cb);

printf("******* Main : Entering Event Loop ! ************ \n");

diff -urN sctplib-1.0.0-pre7/sctplib/ulp/mini-ulp.c
sctplib-1.0.0-pre7-marc/sctplib/ulp/mini-ulp.c
--- sctplib-1.0.0-pre7/sctplib/ulp/mini-ulp.c Fri Mar 16 18:49:45 2001
+++ sctplib-1.0.0-pre7-marc/sctplib/ulp/mini-ulp.c Thu Mar 22 21:28:43
2001
@@ -255,7 +255,7 @@
}


-void ulp_stdin_cb(void)
+void ulp_stdin_cb(int fd, short int revents)
{
int lenread,i;

diff -urN sctplib-1.0.0-pre7/sctplib/ulp/mini-ulp.h
sctplib-1.0.0-pre7-marc/sctplib/ulp/mini-ulp.h
--- sctplib-1.0.0-pre7/sctplib/ulp/mini-ulp.h Fri Mar 16 18:49:45 2001
+++ sctplib-1.0.0-pre7-marc/sctplib/ulp/mini-ulp.h Thu Mar 22 21:28:52
2001
@@ -49,7 +49,7 @@
/* function to handle typed user commands */
/* FOR THE BAKEOFF */
void
-ulp_stdin_cb(void);
+ulp_stdin_cb(int fd, short int revents);
void
ulp_socket_error(gint sin_fd,
unsigned char *buffer,



  • [SCTP-Discussion] [PATCH] various sctplib-1.0.0-pre7 improvements and fixes, Marc Boucher, 03/23/2001

Archive powered by MHonArc 2.6.19+.

Top of page