URN Logo
UNIX Resources » Linux » China Linux Forum » Linux内核技术 » 第293页 » 在可卸载内核里不能应用系统调用吗?
announcement 声明: 本页内容为中国Linux论坛的内容镜像,文章的版权以及其他所有的相关权利属于中国Linux论坛和相应文章的作者,如果转载,请注明文章来源及相关版权信息。
Resources
China Linux Forum(finished)
Linux Forum(finished)
FreeBSD China(finished)
linuxforum.com
  LinuxForum General Chat
  Linux Advocacy
  LinuxForum Polls
  Introductions
  Linux Kernel Support
  Patch Management
  Development Release
  Linux Programming
  Linux Security
  Linux Software
  Linux Hardware Problems
    Linux Video Problems
    Linux Sound Problems
  Linux Networking Support
  Linux Printing Support
  Linux Human Interface Devices Support
  Linux Data Storage Support
  Linux Applications Support
  Linux Installation Support
  Linux Laptops Support
  Linux Motherboard, Chipsets, CPU, Memory
  Miscellaneous
  Debian Linux Support
  Ubuntu Linux Support
  LiveCD Discussions
  Gentoo Linux Support
  Mandrake Linux Support
  Redhat / Fedora Linux Support
  Slackware Linux Support
  SuSE Linux Support
  CentOS Linux Support
  Linux Web Servers
  Linux DNS Servers
  Linux Database Servers
  Linux Email Servers
  Linux FTP Servers
  Linux Squid Proxy Server
  Linux Samba Help
  Linux cPanel Help
  Linux Ensim Help
  Linux Plesk Help
  Linux Webmin / Usermin Help
  Qmail Toaster Help
  Linux Games
  Windows Game Emulation
  Linux Discussions
  General Linux Discussions
  Red Hat Linux Discussions
  More Red Hat Linux Discussions
  Mandrake Linux Discussions
  Slackware Linux Discussions
  SuSE Linux Discussions
  Debian Discussions
  Samba Help
  Linux Security
  Linux Networking
  Gentoo Help
  Operating System Rant Forum
  Hardware Rants
   
在可卸载内核里不能应用系统调用吗?
在可卸载内核里不能应用系统调用吗? - smaplet [2001-05-29 22:50 | 7,224 byte(s)]
 
 
 
Subject: 在可卸载内核里不能应用系统调用吗?
Author: smaplet    Posted: 2001-05-29 22:50    Length: 7,224 byte(s)
[Original] [Print] [Top]
我在一段源代码里加了自己的一段程序.
然后编译.
gcc -Wall -O2 -c myfirewall.c
编译通过 .ismod时出错 .
unresolved symbol gethostname
unresolved symbol gethostbyname
(我在程序里用到了.着两个系统调用)
难道在可卸载内核里不能引用系统调用吗?还是 gcc 时 有些参数没加上
我先把源程序附上,希望那段源程序的作者原谅.
// MyFirewall.c 2000年3月7日编写
#ifndef __KERNEL__
# define __KERNEL__ //按内核模块编译
#endif
#ifndef MODULE
# define MODULE //按设备驱动程序模块编译
#endif
#include //最基本的内核模块头文件
#include
#include //最基本的内核模块头文件
#include
#include
#include
#include
#include
#include
#include
#include
#include
//#include
//#include
//#include
#define SOL_ICMP 1
#define PERMIT_PORT 23 //只允许访问TCP的80端口

static struct filterchain *mychain=NULL;
static struct filterchain *mychaintmp=NULL;
int zzl_input(struct firewall_ops *this,int pf,struct device *dev,
void *phdr,void *arg,struct sk_buff **pskb)
{//每当收到一个网络报时,此函数将被内核调用
//struct tcphdr *tcph; //TCP的头指针
//struct iphdr *iph; //IP头指针
struct sk_buff *skb=*pskb;
unsigned short symbol=1; //判断你哪个函数调用规则链
if (skb->protocol==htons(ETH_P_ARP)){
printk(" Permit a ARP Packet");
return FW_ACCEPT;//允许地址解析协议报
}
if(skb->protocol==htons(ETH_P_RARP)){
printk(" Permit a RARP Packet");
return FW_ACCEPT;//允许反向地址解析协议报
}
if(skb->protocol==htons(ETH_P_IP))
{
//return ipfwcheck(phdr,dev->name,mychaintmp,*pskb,symbol); //返回检查结果
}
return FW_REJECT;//禁止对本计算机的所有其它访问
}
int zzl_output(struct firewall_ops *this,int pf,struct device *dev,
void *phdr,void *arg,struct sk_buff **pskb)
{//程序编写方法同zzl_input函数模块

//struct tcphdr *tcph; //TCP的头指针
//struct iphdr *iph; //IP头指针
struct sk_buff *skb=*pskb;
unsigned short symbol=2; //判断你哪个函数调用规则链
if (skb->protocol==htons(ETH_P_ARP)){
printk(" Permit a ARP Packet");
return FW_ACCEPT;//允许地址解析协议报
}
if(skb->protocol==htons(ETH_P_RARP)){
printk(" Permit a RARP Packet");
return FW_ACCEPT;//允许反向地址解析协议报
}
if(skb->protocol==htons(ETH_P_IP))
{
//return ipfwcheck(phdr,dev->name,mychaintmp,*pskb,symbol); //返回检查结果
}
//return FW_REJECT;//禁止对本计算机的所有其它访问

return FW_SKIP;
}
int zzl_foreward(struct firewall_ops *this,int pf,struct device *dev,
void *phdr,void *arg,struct sk_buff **pskb)
{//程序编写方法同zzl_input函数模块
printk(" zzl_foreward is called ");
return FW_SKIP;
}
struct firewall_ops zzl_ops=
{
NULL,
zzl_foreward,
zzl_input,
zzl_output,
PF_INET,
01
};
int init_module(void)
{
if(register_firewall(PF_INET,&zzl_ops)!=0)
{
printk(" unable register firewall");
return -1;
}
//printk(" zzl_ops=%p",&zzl_ops);
mychain_init(); //init the chains
return 0;
}
void cleanup_module(void)
{
printk("unload ");
unregister_firewall(PF_INET,&zzl_ops);
}


int mychain_init(void) //对输入的数据包进行规则检测
{

static struct filterchain *new=NULL,*newtmp=NULL; //规则链
struct hostent *host; //保存网卡地址
char *myhostname;
if(gethostname(myhostname,99)==-1)
printk("gethostname ERROR ");
host=(struct hostent *)gethostbyname(myhostname);
// printk("gethostaddress error ");
//new=(struct filterchain *)malloc(sizeof(struct filterchain));
mychain=new;
new->filterip.s_addr=((*(host->h_addrlist))[0]);
new->outfilternum=0;
new->infilternum=0;
new->forwardfilternum=0;
new->ispass=0;
new->next=NULL;


printk("inin chain ok!");
return 0;
}




[Original] [Print] [Top]
Subject: Re: 在可卸载内核里不能应用系统调用吗?
Author: jkl    Posted: 2001-05-30 12:30    Length: 282 byte(s)
[Original] [Print] [Top]
gethostname()和gethostbyname()是libc库函数,内核模块只能使用/proc/ksyms中出现的符号。内核模块一般都是驱动程序,只是被动地处理来自内核其余部分的调用,没有自已的线程上下文,初始化时也只是借用insmod进程的上下文,你最好通过/proc文件系统来配置你的模块参数。


[Original] [Print] [Top]
Subject: Re: 在可卸载内核里不能应用系统调用吗?
Author: smaplet    Posted: 2001-05-30 13:18    Length: 193 byte(s)
[Original] [Print] [Top]
那能不能.给介绍一下怎么来用/proc文件系统来配置你的模块参数。
给提供一些资料可以吗? 还有关于lkm的编程的方面的.
多谢





[Original] [Print] [Top]
« Previous thread
怎样在内核中读写文件?
Linux内核技术
293
Next thread »
怎样将网卡驱动加载道内核上?
     

Copyright © 2018 UNIX Resources Network, All Rights Reserved.    About URN | Privacy & Legal | Help | Contact us