AF:
NF:0
PS:10
SRH:1
SFN:
DSR:
MID:<20070521140910.0a086221@ripper.onstor.net>
CFG:
PT:0
S:andy.sharp@onstor.com
RQ:
SSV:onstor-exch02.onstor.net
NSV:
SSH:
R:<wencheng.chai@onstor.com>
MAID:1
X-Sylpheed-Privacy-System:
X-Sylpheed-Sign:0
SCF:#mh/Mailbox/sent
X-Sylpheed-End-Special-Headers: 1
Date: Mon, 21 May 2007 14:10:48 -0700
From: Andrew Sharp <andy.sharp@onstor.com>
To: Wencheng Chai <wencheng.chai@onstor.com>
Subject: example vs-ipm.c file
Message-ID: <20070521141048.1f357970@ripper.onstor.net>
Organization: Onstor
X-Mailer: Sylpheed-Claws 2.6.0 (GTK+ 2.8.20; x86_64-pc-linux-gnu)
Mime-Version: 1.0
Content-Type: multipart/mixed; boundary=MP_S.mHy2S4Eu0VeRevFxbxB6I

--MP_S.mHy2S4Eu0VeRevFxbxB6I
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

Wencheng,

Attached is the example vs-imp.c file.  Note that the function I
currently have in here probably doesn't need to be in here at all, but
is just meant to show you how you can approach some of these functions.

Cheers,

a


--MP_S.mHy2S4Eu0VeRevFxbxB6I
Content-Type: text/x-csrc; name=vs-ipm.c
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment; filename=vs-ipm.c

#include OS_INCL

/*-----------------------------------------------------------------
 * Routine     : vsd_addKernRt
 *
 * Description: Directly interact to kernel to add a route.
 *
 *-----------------------------------------------------------------
 */
static int32
vsd_addKernRt(uint32 ip, uint32 mask, uint32 nhop)
{
    int     pid;
    char    ip_str[IPM_STR_SIZE];
    char    mask_str[IPM_STR_SIZE];
    char    nhop_str[IPM_STR_SIZE];
    int     status;

    strncpy(ip_str, inet_ntoa(*(struct in_addr*)&ip), IPM_STR_SIZE);
    strncpy(mask_str, inet_ntoa(*(struct in_addr*)&mask), IPM_STR_SIZE);
    strncpy(nhop_str, inet_ntoa(*(struct in_addr*)&nhop), IPM_STR_SIZE);

	status = OS_ADD_ROUTE(ip_str, mask, mask_str, nhop_str);

	VSD_DBG_PRT(("%s[%u] : Add route completed with status=0x%x(%u)",
			 __FUNCTION__, __LINE__, status, WEXITSTATUS(status)));

	if (WEXITSTATUS(status)) {
		return NFX_ERR;
	}

	if (!ip && !mask) {  /* It's the default route */
		modify_readonly_file("/etc/mygate", string_to_file, nhop_str);
	}

    return NFX_OK;
}


vs-ipm-linux.h:

#define OS_ADD_ROUTE(A, B, C, D) \
	status = do_system("/sbin/route add %s %s %s %s", A, ntohl(B) & 1 ? "" : "-netmask", ntohl(B) & 1 ? "" : C, D);


vs-ipm-openbsd.h:

#define OS_ADD_ROUTE(A, B, C, D) \
	status = do_system("/sbin/route foo %s %s %s %s", A, ntohl(B) & 1 ? "" : "-netmask", ntohl(B) & 1 ? "" : C, D);

--MP_S.mHy2S4Eu0VeRevFxbxB6I--
