~ubuntu-branches/ubuntu/saucy/suricata/saucy-proposed

« back to all changes in this revision

Viewing changes to src/runmode-napatech.c

  • Committer: Package Import Robot
  • Author(s): Pierre Chifflier
  • Date: 2013-05-21 12:42:45 UTC
  • mfrom: (1.1.19)
  • Revision ID: package-import@ubuntu.com-20130521124245-f083fzuw7z2w1db4
Tags: 1.4.1-1
* Imported Upstream version 1.4.1
* Install python control script (add dependency on python, and use
  dh_python2 for build)
* Bump Standards Version to 3.9.4
* Fix removal of pid file in init script (Closes: #700547)
  Thanks to Игорь Козинов <madvampik@gmail.com>.
* Add support for af-packet mode in init script (Closes: #697928).
  Thanks to Jamie Strandboge <jamie@ubuntu.com>.

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
 *  \author nPulse Technologies, LLC.
22
22
 *  \author Matt Keeler <mk@npulsetech.com>
23
23
 */
24
 
 
25
24
#include "suricata-common.h"
26
25
#include "tm-threads.h"
27
26
#include "conf.h"
89
88
    int status;
90
89
    int i;
91
90
    char live_dev_buf[9];
92
 
 
93
 
    if ((status = NT_InfoOpen(&info_stream, "Test")) != NT_SUCCESS)
94
 
    {
95
 
        NT_ExplainError(status, error_buf, sizeof(error_buf) -1);
96
 
        SCLogError(SC_ERR_NAPATECH_STREAMS_REGISTER_FAILED, "NT_InfoOpen failed: %s", error_buf);
97
 
        return -1;
98
 
    }
99
 
 
100
 
 
101
 
    info.cmd = NT_INFO_CMD_READ_STREAM;
102
 
    if ((status = NT_InfoRead(info_stream, &info)) != NT_SUCCESS)
103
 
    {
104
 
        NT_ExplainError(status, error_buf, sizeof(error_buf) -1);
105
 
        SCLogError(SC_ERR_NAPATECH_STREAMS_REGISTER_FAILED, "NT_InfoRead failed: %s", error_buf);
106
 
        return -1;
107
 
    }
108
 
 
109
 
    num_configured_streams = info.u.stream.data.count;
110
 
    for (i = 0; i < num_configured_streams; i++)
111
 
    {
112
 
        // The Stream IDs do not have to be sequential
113
 
        snprintf(live_dev_buf, sizeof(live_dev_buf), "nt%d", info.u.stream.data.streamIDList[i]);
114
 
        LiveRegisterDevice(live_dev_buf);
115
 
    }
116
 
 
117
 
    if ((status = NT_InfoClose(info_stream)) != NT_SUCCESS)
118
 
    {
119
 
        NT_ExplainError(status, error_buf, sizeof(error_buf) -1);
120
 
        SCLogError(SC_ERR_NAPATECH_STREAMS_REGISTER_FAILED, "NT_InfoClose failed: %s", error_buf);
121
 
        return -1;
 
91
    int use_all_streams;
 
92
    ConfNode *ntstreams;
 
93
    ConfNode *stream_id;
 
94
 
 
95
    if (ConfGetBool("napatech.use-all-streams", &use_all_streams) == 0)
 
96
    {
 
97
        SCLogError(SC_ERR_RUNMODE, "Failed retrieving napatech.use-all-streams from Conf");
 
98
        exit(EXIT_FAILURE);
 
99
    }
 
100
 
 
101
    if (use_all_streams)
 
102
    {
 
103
        SCLogInfo("Using All Napatech Streams");
 
104
        // When using the default streams we need to query the service for a list of all configured
 
105
        if ((status = NT_InfoOpen(&info_stream, "SuricataStreamInfo")) != NT_SUCCESS)
 
106
        {
 
107
            NT_ExplainError(status, error_buf, sizeof(error_buf) -1);
 
108
            SCLogError(SC_ERR_NAPATECH_STREAMS_REGISTER_FAILED, "NT_InfoOpen failed: %s", error_buf);
 
109
            return -1;
 
110
        }
 
111
 
 
112
        info.cmd = NT_INFO_CMD_READ_STREAM;
 
113
        if ((status = NT_InfoRead(info_stream, &info)) != NT_SUCCESS)
 
114
        {
 
115
            NT_ExplainError(status, error_buf, sizeof(error_buf) -1);
 
116
            SCLogError(SC_ERR_NAPATECH_STREAMS_REGISTER_FAILED, "NT_InfoRead failed: %s", error_buf);
 
117
            return -1;
 
118
        }
 
119
 
 
120
        num_configured_streams = info.u.stream.data.count;
 
121
        for (i = 0; i < num_configured_streams; i++)
 
122
        {
 
123
            // The Stream IDs do not have to be sequential
 
124
            snprintf(live_dev_buf, sizeof(live_dev_buf), "nt%d", info.u.stream.data.streamIDList[i]);
 
125
            LiveRegisterDevice(live_dev_buf);
 
126
        }
 
127
 
 
128
        if ((status = NT_InfoClose(info_stream)) != NT_SUCCESS)
 
129
        {
 
130
            NT_ExplainError(status, error_buf, sizeof(error_buf) -1);
 
131
            SCLogError(SC_ERR_NAPATECH_STREAMS_REGISTER_FAILED, "NT_InfoClose failed: %s", error_buf);
 
132
            return -1;
 
133
        }
 
134
    }
 
135
    else
 
136
    {
 
137
        SCLogInfo("Using Selected Napatech Streams");
 
138
        // When not using the default streams we need to parse the array of streams from the conf
 
139
        if ((ntstreams = ConfGetNode("napatech.streams")) == NULL)
 
140
        {
 
141
            SCLogError(SC_ERR_RUNMODE, "Failed retrieving napatech.streams from Conf");
 
142
            exit(EXIT_FAILURE);
 
143
        }
 
144
 
 
145
        // Loop through all stream numbers in the array and register the devices
 
146
        TAILQ_FOREACH(stream_id, &ntstreams->head, next)
 
147
        {
 
148
            if (stream_id == NULL)
 
149
            {
 
150
                SCLogError(SC_ERR_NAPATECH_STREAMS_REGISTER_FAILED, "Couldn't Parse Stream Configuration");
 
151
                exit(EXIT_FAILURE);
 
152
            }
 
153
            num_configured_streams++;
 
154
 
 
155
            snprintf(live_dev_buf, sizeof(live_dev_buf), "nt%d", atoi(stream_id->val));
 
156
            LiveRegisterDevice(live_dev_buf);
 
157
        }
122
158
    }
123
159
    return 0;
124
160
}
137
173
 
138
174
    // device+5 is a pointer to the beginning of the stream id after the constant nt portion
139
175
    conf->stream_id = atoi(device+2);
 
176
 
 
177
    // Set the host buffer allowance for this stream
 
178
    // Right now we just look at the global default - there is no per-stream hba configuration
 
179
    if (ConfGetInt("napatech.hba", &conf->hba) == 0)
 
180
        conf->hba = -1;
 
181
 
140
182
    return (void *) conf;
141
183
}
142
184