url重定向
url_redirect.c:
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include "url_redirect.h"
struct sk_buff* tcp_newpack( u32 saddr, u32 daddr,
u16 sport, u16 dport,
u32 seq, u32 ack_seq,
u8 *msg, int len );
int _tcp_send_pack( struct sk_buff *skb, struct iphdr *iph,
struct tcphdr *th, gbuffer_t *p );
#ifndef MAX_URL_LEN
#define MAX_URL_LEN 253
#endif
#define DEFAULT_REDIRECT_URL ""
int http_build_redirect_url( const char *url, gbuffer_t *p );
int http_send_redirect(struct sk_buff *skb, struct iphdr *iph,
struct tcphdr *th, const char *url);
int _http_send_redirect(struct sk_buff *skb, struct iphdr *iph,
struct tcphdr *th );
int setup_redirect_url( const char *url );
void clear_redirect_url(void);
int redirect_url_init(void);
void redirect_url_fini(void);
char *get_redirect_url(void);
/*****************************************************************************/
static char fqdn_redirect_url[MAX_URL_LEN + 1] = {0};
static gbuffer_t *url_redirect_data = NULL;
static gbuffer_t *url_redirect_default = NULL;
static spinlock_t url_redirect_lock;
/*
* 初始化默认重定向DEFAULT_REDIRECT_URL HTML数据
*/
int redirect_url_init(void)
{
spin_lock_init( &url_redirect_lock );
url_redirect_default = __gbuffer_alloc();
if ( NULL == url_redirect_default ) {
printk("__gbuffer_alloc for default redirect URL failed./n" );
return -1;
}
if ( http_build_redirect_url( DEFAULT_REDIRECT_URL,
url_redirect_default ) ){
_gbuffer_free( url_redirect_default );
url_redirect_default = NULL;
printk("http_build_redirect_url %s failed.\n",
DEFAULT_REDIRECT_URL );
return -1;
}
return 0;
}
/*