/* HINT: Search archives @ http://www.indyramp.com/masq/ before posting! */
>I know I saw some stuff on a new NM3 module...was I hallucinating? If not,
>does anyone know where I can find it and how I install the new modules. I
>have the newer ICQ module which I'm hoping will fix some issues I've had in
>the past, but I'm not sure about the procedure for installing modules...is it
>the <make modules><make modules install>?
Here is an old version of the patch which should work for 2.2.x kernels
and NM 2.x. I just emailed the author of the patch regarding NM3.x
support and we'll see what he says.
--David
/*
* IP_MASQ_H323, H.323 masquerading module
*
*
* Version: 0.5 beta, Tue Nov 2 12:40:21 IST 1999
*
* Author: Rajkumar. S
* Archana V. S.
* Sheenarani I.
*
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version
* 2 of the License, or (at your option) any later version.
*
*
*/
#include <linux/module.h>
#include <asm/system.h>
#include <linux/types.h>
#include <linux/kernel.h>
#include <linux/skbuff.h>
#include <linux/in.h>
#include <linux/ip.h>
#include <net/protocol.h>
#include <net/tcp.h>
#include <net/ip_masq.h>
#ifndef DEBUG_CONFIG_IP_MASQ_H323
#define DEBUG_CONFIG_IP_MASQ_H323 1
#endif
/*
* List of ports (up to MAX_MASQ_APP_PORTS) to be handled by helper
* First port is set to the default port.
*/
int ports[MAX_MASQ_APP_PORTS] = {1720}; /* I rely on the trailing items being set to
zero */
struct ip_masq_app *masq_incarnations[MAX_MASQ_APP_PORTS];
int h245registered=0;
int RTCPfound=0;
struct ip_masq *n_ms_rtcp;
/********** Start of H.245 masq app functions ******************/
static int
masq_h245_init_1 (struct ip_masq_app *mapp, struct ip_masq *ms)
{
MOD_INC_USE_COUNT;
printk("IP masq app 245 init\n");
return 0;
}
static int
masq_h245_done_1 (struct ip_masq_app *mapp, struct ip_masq *ms)
{
MOD_DEC_USE_COUNT;
RTCPfound--;
printk("IP masq app 245 done\n");
return 0;
}
int
masq_h245_in (struct ip_masq_app *mapp, struct ip_masq *ms, struct sk_buff **skb_p,
struct device *dev)
{
return 0;
}
int
masq_h245_out (struct ip_masq_app *mapp, struct ip_masq *ms, struct sk_buff **skb_p,
struct device *dev)
{
struct sk_buff *skb;
struct iphdr *iph;
struct tcphdr *th;
unsigned char *data, *data_limit;
unsigned char *skbuff_p;
__u16 port, *rtcp_port, *rtp_port;
__u32 ip,temp_ip, *rtp_ip, *rtcp_ip;
struct ip_masq * n_ms_rtp;
unsigned char p1,p2;
skb = *skb_p;
iph = skb->h.iph;
th = (struct tcphdr *)&(((char *)iph)[iph->ihl*4]);
data = skb->data;
data_limit = skb->tail;
skbuff_p = data+12;
printk("\n Raw data\n\n");
while(data<data_limit){
printk("%02x ",*data);
data++;
}
ip=ntohl(ms->saddr);
skbuff_p=skbuff_p+4;
temp_ip= (((*skbuff_p) << 24) + (*(skbuff_p+1)<< 16) + (*(skbuff_p+2) << 8) +
(*(skbuff_p+3)));
/*find if there is any ip in the packet*/
while(((skbuff_p+6)< data_limit) && (temp_ip !=ip)){
skbuff_p++;
temp_ip= (((*skbuff_p) << 24) + (*(skbuff_p+1)<< 16) + (*(skbuff_p+2) << 8) +
(*(skbuff_p+3)));
}
/*if we find one then process it*/
if(temp_ip==ip){
p1=*(skbuff_p+4);
p2=*(skbuff_p+5);
port=(p1<<8)+p2;
if(RTCPfound==0){
printk("RTCP port is at: %04x\n",port);
n_ms_rtcp = ip_masq_new(dev
, IPPROTO_UDP,
htonl(ip), htons(port),
iph->daddr, 0,
IP_MASQ_F_NO_DPORT);
if(n_ms_rtcp==NULL) {
printk("RTCP masq entry not made\n");
return 0;
}
ip_masq_set_expire(n_ms_rtcp, ip_masq_expire->udp_timeout);
/*now change the maddr and mport and change the packet*/
rtcp_ip=skbuff_p;
rtcp_port=skbuff_p+4;
*rtcp_ip=n_ms_rtcp->maddr;
*rtcp_port=n_ms_rtcp->mport;
printk("maddr=%08x, mport=%04x", n_ms_rtcp->maddr,n_ms_rtcp->mport);
RTCPfound++;
}
/*now go for the rtp*/
else{
/*make the masq entry for the rtp*/
n_ms_rtp = ip_masq_new(dev, IPPROTO_UDP,
htonl(ip), htons(port),
iph->daddr, 0,
IP_MASQ_F_NO_DPORT);
if(n_ms_rtp==NULL) {
printk("RTP masq entry not made\n");
return 0;
}
ip_masq_set_expire(n_ms_rtp, ip_masq_expire->udp_timeout);
/*now change the maddr and mport and change the packet*/
rtp_ip=skbuff_p;
rtp_port=skbuff_p+4;
*rtp_ip=n_ms_rtp->maddr;
*rtp_port=n_ms_rtp->mport;
printk("maddr=%08x, mport=%04x", n_ms_rtp->maddr,n_ms_rtp->mport);
/*search for the rtcp addr*/
skbuff_p=skbuff_p+6;
temp_ip= (((*skbuff_p) << 24) + (*(skbuff_p+1)<< 16) + (*(skbuff_p+2) << 8)
+ (*(skbuff_p+3)));
/*find the next ip in the packet*/
while(((skbuff_p+6)< data_limit) && (temp_ip !=ip)){
skbuff_p++;
temp_ip= (((*skbuff_p) << 24) + (*(skbuff_p+1)<< 16) + (*(skbuff_p+2) <<
8) + (*(skbuff_p+3)));
}
rtcp_ip=skbuff_p;
rtcp_port=skbuff_p+4;
/* n_ms_rtcp=ip_masq_out_get_2(IPPROTO_UDP, */
/* htonl(*rtcp_ip), */
/* htons(*rtcp_port), */
/* iph->daddr, 0); */
printk("old maddr=%08x,old mport=%04x", n_ms_rtcp->maddr,n_ms_rtcp->mport);
/* if(n_ms_rtcp==NULL) { */
/* printk("RTCP masq entry not made\n"); */
/* return 0; */
/* } */
*rtcp_ip=n_ms_rtcp->maddr;
*rtcp_port=n_ms_rtcp->mport;
}
}
return 0;
}
/***********End of H.245 app functions *******************/
struct ip_masq_app ip_masq_h245_template = {
NULL, /* next */
"h245", /* name */
0, /* type */
0, /* n_attach */
masq_h245_init_1, /* ip_masq_init_1 */
masq_h245_done_1, /* ip_masq_done_1 */
masq_h245_out, /* pkt_out */
masq_h245_in, /* pkt_in */
};
struct ip_masq_app * ip_masq_h245;
static int
masq_h323_init_1 (struct ip_masq_app *mapp, struct ip_masq *ms)
{
printk("323 init\n");
MOD_INC_USE_COUNT;
if (h245registered) {
printk("\nfound an old ip_masq_app entry, deleting....\n");
if(unregister_ip_masq_app(ip_masq_h245))
kfree(ip_masq_h245);
h245registered=0;
}
return 0;
}
static int
masq_h323_done_1 (struct ip_masq_app *mapp, struct ip_masq *ms)
{
printk("323 done\n");
MOD_DEC_USE_COUNT;
return 0;
}
int
masq_h323_out (struct ip_masq_app *mapp, struct ip_masq *ms, struct sk_buff **skb_p,
struct device *dev)
{
return 0;
}
int
masq_h323_in (struct ip_masq_app *mapp, struct ip_masq *ms, struct sk_buff **skb_p,
struct device *dev)
{
struct sk_buff *skb;
struct iphdr *iph;
struct tcphdr *th;
unsigned char *data, *data_limit;
__u32 ip;
__u16 port;
__u32 temp_ip;
unsigned char * skbuff_p;
unsigned char p1,p2;
int j;
skb = *skb_p;
iph = skb->h.iph;
th = (struct tcphdr *)&(((char *)iph)[iph->ihl*4]);
data = skb->data;
data_limit = skb->tail;
skbuff_p = data+12;
ip= (((*skbuff_p) << 24) + (*(skbuff_p+1)<< 16) + (*(skbuff_p+2) << 8) +
(*(skbuff_p+3)));
skbuff_p=skbuff_p+4;
temp_ip= (((*skbuff_p) << 24) + (*(skbuff_p+1)<< 16) + (*(skbuff_p+2) << 8) +
(*(skbuff_p+3)));
while(((skbuff_p+6)< data_limit) && (temp_ip !=ip)){
skbuff_p++;
temp_ip= (((*skbuff_p) << 24) + (*(skbuff_p+1)<< 16) + (*(skbuff_p+2) << 8)
+ (*(skbuff_p+3)));
}
if(temp_ip==ip){
p1=*(skbuff_p+4);
p2=*(skbuff_p+5);
port=(p1<<8)+p2;
printk("H.245 Port is at: %04x\n",port);
if ((j = register_ip_masq_app(ip_masq_h245,
IPPROTO_TCP,
port))) {
h245registered = 1;
}
}
return 0;
}
struct ip_masq_app ip_masq_h323 = {
NULL, /* next */
"h323", /* name */
0, /* type */
0, /* n_attach */
masq_h323_init_1, /* ip_masq_init_1 */
masq_h323_done_1, /* ip_masq_done_1 */
masq_h323_out, /* pkt_out */
masq_h323_in, /* pkt_in */
};
/*
* ip_masq_h323 initialization
*/
int ip_masq_h323_init(void)
{
int i, j;
ip_masq_h245 = NULL;
for (i=0; (i<MAX_MASQ_APP_PORTS); i++) {
if (ports[i]) {
if ((masq_incarnations[i] = kmalloc(sizeof(struct ip_masq_app),
GFP_KERNEL)) == NULL)
return -ENOMEM;
memcpy(masq_incarnations[i], &ip_masq_h323, sizeof(struct
ip_masq_app));
if ((ip_masq_h245 = kmalloc(sizeof(struct ip_masq_app),
GFP_KERNEL)) == NULL)
return -ENOMEM;
memcpy(ip_masq_h245, &ip_masq_h245_template, sizeof(struct ip_masq_app));
if ((j = register_ip_masq_app(masq_incarnations[i],
IPPROTO_TCP,
ports[i]))) {
return j;
}
#if DEBUG_CONFIG_IP_MASQ_H323
printk("H323: loaded support on port[%d] = %d\n",
i, ports[i]);
#endif
} else {
/* To be safe, force the incarnation table entry to NULL */
masq_incarnations[i] = NULL;
}
}
return 0;
}
/*
* ip_masq_h323 fin.
*/
int ip_masq_h323_done(void)
{
int i, j, k;
k=0;
for (i=0; (i<MAX_MASQ_APP_PORTS); i++) {
if (masq_incarnations[i]) {
if ((j = unregister_ip_masq_app(masq_incarnations[i]))) {
k = j;
} else {
kfree(masq_incarnations[i]);
masq_incarnations[i] = NULL;
#if DEBUG_CONFIG_IP_MASQ_H323
printk("H323: unloaded support on port[%d] = %d\n",
i, ports[i]);
#endif
}
}
}
if (h245registered) {
printk("\nremoving the masq app entry\n");
if(unregister_ip_masq_app(ip_masq_h245))
kfree(ip_masq_h245);
h245registered=0;
}
return k;
}
#ifdef MODULE
int init_module(void)
{
printk("Init module\n");
if (ip_masq_h323_init() != 0)
return -EIO;
register_symtab(0);
return 0;
}
void cleanup_module(void)
{
if (ip_masq_h323_done() != 0)
printk("ip_masq_h323: can't remove module\n");
}
#endif /* MODULE */
.----------------------------------------------------------------------------.
| David A. Ranch - Linux/Networking/PC hardware [EMAIL PROTECTED] |
!---- ----!
`----- For more detailed info, see http://www.ecst.csuchico.edu/~dranch -----'
_______________________________________________
Masq maillist - [EMAIL PROTECTED]
Admin requests can be handled at http://www.indyramp.com/masq-list/ -- THIS INCLUDES
UNSUBSCRIBING!
or email to [EMAIL PROTECTED]
PLEASE read the HOWTO and search the archives before posting.
You can start your search at http://www.indyramp.com/masq/
Please keep general linux/unix/pc/internet questions off the list.