~ubuntu-branches/ubuntu/quantal/netams/quantal

« back to all changes in this revision

Viewing changes to .pc/14_fix_pthread.diff/src/ds_ipfw.c

  • Committer: Bazaar Package Importer
  • Author(s): Alexander GQ Gerasiov
  • Date: 2010-07-24 16:37:01 UTC
  • mfrom: (2.1.3 sid)
  • Revision ID: james.westby@ubuntu.com-20100724163701-rni105xlqseqe26h
Tags: 3.4.5-2
* debian/Rules.make: Add -lcrypto to fix FTBFS with binutils-gold.
* debian/netams.postinst: Fix some sed magic in netams.conf
  processing.
* debian/control: Standards version updated.
* Vietnamese translation added. Closes: #576026. Thanks to Clytie
  Siddall.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*************************************************************************
 
2
***     Authentication, authorization, accounting + firewalling package
 
3
***     Copyright 1998-2002 Anton Vinokurov <anton@netams.com>
 
4
***     Copyright 2002-2008 NeTAMS Development Team
 
5
***     This code is GPL v3
 
6
***     For latest version and more info, visit this project web page
 
7
***     located at http://www.netams.com
 
8
***
 
9
*************************************************************************/
 
10
/* $Id: ds_ipfw.c,v 1.44 2009-12-19 17:25:50 anton Exp $ */
 
11
 
 
12
#ifdef FREEBSD
 
13
#include "netams.h"
 
14
#include "ds_any.h"
 
15
 
 
16
/////////////////////////////////////////////////////////////////////////////////////
 
17
void ds_ipfw_cancel(void *ptr);
 
18
/////////////////////////////////////////////////////////////////////////////////////
 
19
void ds_ipfw(Service_DS *ds) {
 
20
        socklen_t size_ds = sizeof(struct sockaddr_in);
 
21
        int socketid;
 
22
        FlowEngine *FE=ds->FE;
 
23
        unsigned len;
 
24
        struct timeval start;
 
25
        unsigned char *packet=ds->packet;
 
26
        
 
27
        struct sockaddr_in sin;
 
28
        sin.sin_family = AF_INET;
 
29
        sin.sin_addr.s_addr = INADDR_ANY;
 
30
        sin.sin_port = htons(ds->port);
 
31
 
 
32
 
 
33
        if ((socketid = socket(PF_INET, SOCK_RAW, IPPROTO_DIVERT)) < 0) 
 
34
                aLog(D_ERR, "divert socket\n");
 
35
        else {
 
36
                
 
37
        
 
38
        if (bind(socketid, (struct sockaddr *)&(sin), sizeof(sin))) 
 
39
                aLog(D_ERR, "bind divert socket: %u\n", socketid);
 
40
        else {
 
41
        
 
42
        SET_POLL(socketid);
 
43
 
 
44
        pthread_cleanup_push(ds_ipfw_cancel, (void*) &socketid);
 
45
        pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, NULL);
 
46
 
 
47
        aLog(D_INFO,"IPFW packet processing for data-source:%u initialized\n",ds->instance);
 
48
        
 
49
        int                     status;
 
50
        int                     process_result;
 
51
        struct ipv4_key         key;
 
52
        bzero(&key, sizeof(struct ipv4_key));
 
53
        entry                   *flow_entry;
 
54
 
 
55
        while(1) {
 
56
                CHECK_POLL(ds,status);
 
57
                
 
58
                netams_gettimeofday(&start, NULL);
 
59
                FE->Expiresearch(&start);  
 
60
                if(!status) continue;
 
61
                
 
62
                len=recvfrom(socketid, packet, MAX_PKT_SIZE, 0, (struct sockaddr *)&sin, &size_ds);
 
63
                IPv4GetKey((struct ip*) packet, &key);
 
64
                
 
65
                process_result = FE->Process((u_char *)&key, 1, ntohs(((struct ip*) packet)->ip_len), &flow_entry);
 
66
                if(process_result == -1) {
 
67
                        IPv4FillFlow(&key, flow_entry);
 
68
 
 
69
#ifdef LAYER7_FILTER
 
70
                        if (ds->layer7_detect!=LAYER7_DETECT_NONE) layer7_addinfo(key.tcp_info.dst_port, flow_entry); 
 
71
#endif
 
72
 
 
73
                        if(ds->ds_flags==DS_DIVERT) process_result = FE->FW(flow_entry);
 
74
                }
 
75
                
 
76
                if (process_result && (ds->ds_flags==DS_DIVERT)) 
 
77
                        sendto(socketid, packet, len, 0, (struct sockaddr *)&sin, size_ds);
 
78
                
 
79
#ifdef LAYER7_FILTER
 
80
                if (ds->layer7_detect!=LAYER7_DETECT_NONE) layer7_checkinfo(key.tcp_info.dst_port, flow_entry, (struct ip*) packet); 
 
81
#endif
 
82
                ds->Measure(&start, len);
 
83
        }
 
84
        
 
85
        } // socket
 
86
        } // bind
 
87
        pthread_cleanup_pop(1);
 
88
        
 
89
}
 
90
/////////////////////////////////////////////////////////////////////////////////////
 
91
void ds_ipfw_cancel(void *ptr) {
 
92
        int socketid=*(int*)ptr;
 
93
        shutdown(socketid, SHUT_RDWR);
 
94
        close(socketid);
 
95
}
 
96
/////////////////////////////////////////////////////////////////////////////////////
 
97
#endif
 
98
/////////////////////////////////////////////////////////////////////////////////////