]> git.ipfire.org Git - thirdparty/snort3.git/commitdiff
basic reject action plugin working
authorRuss Combs <rucombs@cisco.com>
Wed, 13 Aug 2014 01:19:39 +0000 (21:19 -0400)
committerRuss Combs <rucombs@cisco.com>
Wed, 13 Aug 2014 01:19:39 +0000 (21:19 -0400)
src/actions/act_reject.cc
src/detection/fpdetect.cc
src/detection/rules.h
src/managers/action_manager.cc
src/parser/cmd_line.cc
src/parser/parse_conf.cc
src/parser/parse_conf.h
src/parser/parse_rule.cc

index 0272d44cceca99c95d95599068e0264cb1dff304..7db8c104c22e5d16a96fed33e0df8f6f15078b77 100644 (file)
@@ -86,9 +86,11 @@ RejectAction::RejectAction(RejectModule*) :
     Active_SetEnabled(1);
 }
 
-void RejectAction::exec(Packet*)
+void RejectAction::exec(Packet* p)
 {
-    printf("ACT Now!");
+    if ( PacketIsRebuilt(p) )
+        return;
+
     Active_QueueReject();
 }
 
index a798423f4940c038b5ea75440992898533e2ad0a..528fc879887afc0c7e08cf43ce2ffadbec57863f 100644 (file)
@@ -150,10 +150,8 @@ static inline void fpLogOther (
     // FIXIT some or all of these can be migrated to user defined actions
     otn_trigger_actions(otn, p);
 
-    if ( !EventTrace_IsEnabled() )
-        return;
-
-    EventTrace_Log(p, otn, action);
+    if ( EventTrace_IsEnabled() )
+        EventTrace_Log(p, otn, action);
 
     // user defined actions are done here
     if ( rtn->listhead->action )
index 5641954b0c346802b7264157d6dd4497bfed28e5..1afe036f1a158fa0dc8c159752b68bdd82603bd5 100644 (file)
@@ -66,12 +66,12 @@ struct ListHead
 
 struct RuleListNode
 {
-    ListHead *RuleList;         /* The rule list associated with this node */
-    RuleType mode;              /* the rule mode */
-    int rval;                   /* 0 == no detection, 1 == detection event */
-    int evalIndex;              /* eval index for this rule set */
-    char *name;                 /* name of this rule list (for debugging)  */
-    RuleListNode *next; /* the next RuleListNode */
+    ListHead *RuleList;   /* The rule list associated with this node */
+    RuleType mode;        /* the rule mode */
+    int rval;             /* 0 == no detection, 1 == detection event */
+    int evalIndex;        /* eval index for this rule set */
+    char* name;           /* name of this rule list */
+    RuleListNode* next;   /* the next RuleListNode */
 };
 
 struct RuleState
index de267d7dbe273ad0e42d613cb96c362d12771185..e7c814b717276098c6b153a4b44be2800429b110 100644 (file)
@@ -72,9 +72,16 @@ RuleType ActionManager::get_action_type(const char* s)
 }
 
 void ActionManager::instantiate(
-    const ActionApi* api, Module*, SnortConfig* sc)
+    const ActionApi* api, Module* m, SnortConfig* sc)
 {
-    CreateRuleType(sc, api->base.name, api->type, 0, nullptr);
+    IpsAction* act = api->ctor(m);
+
+    if ( act )
+    {
+        ListHead* lh = CreateRuleType(sc, api->base.name, api->type, 0, nullptr);
+        assert(lh);
+        lh->action = act;
+    }
 }
 
 #if 0
index 7ecc9bbc7293c80c2784997890bb504cf2dc49e1..88925cdc40105e97bd4ec4a494b0d33b7444acfa 100644 (file)
@@ -544,13 +544,11 @@ static void config_log_mode(SnortConfig* sc, const char* val)
 
 static void config_inline(SnortConfig* sc, const char*)
 {
-    LogMessage("Enabling inline operation\n");
     sc->run_flags |= RUN_FLAG__INLINE;
 }
 
 static void config_inline_test(SnortConfig* sc, const char*)
 {
-    LogMessage("Enable Inline Test Mode\n");
     sc->run_flags |= RUN_FLAG__INLINE_TEST;
 }
 
index 20dc35ac7fdd458e9ba4849fceaa8cc711a3ce2e..0946ee2d83771a09ff4edc5c8dfa881a96514f6d 100644 (file)
@@ -267,29 +267,14 @@ RuleType get_rule_type(const char* s)
     return rt;
 }
 
-ListHead* get_rule_list(SnortConfig* sc, RuleType type)
+ListHead* get_rule_list(SnortConfig* sc, const char* s)
 {
-    switch ( type )
-    {
-    case RULE_TYPE__ALERT:
-        return &sc->Alert;
-
-    case RULE_TYPE__LOG:
-        return &sc->Log;
-
-    case RULE_TYPE__PASS:
-        return &sc->Pass;
+    const RuleListNode* p = sc->rule_lists;
 
-    case RULE_TYPE__DROP:
-        return &sc->Drop; 
-
-    case RULE_TYPE__SDROP:
-        return &sc->SDrop;
-
-    default:
-        break;
-    }
-    return nullptr;
+    while ( p && strcmp(p->name, s) )
+        p = p->next;
+    
+    return p ? p->RuleList : nullptr;
 }
 
 // FIXIT find this a better home
index 810d7f1fd27becd0dc05c0c7709ffb99d36a2ae1..41139d179ba58c919c68cfba91461b7fb484f837 100644 (file)
@@ -39,7 +39,7 @@ void AddRuleState(SnortConfig*, const RuleState&);
 void add_service_to_otn(SnortConfig*, OptTreeNode*, const char*);
 
 RuleType get_rule_type(const char*);
-ListHead* get_rule_list(SnortConfig*, RuleType);
+ListHead* get_rule_list(SnortConfig*, const char*);
 
 #define ERR_PAIR_COUNT \
         "%s has incorrect argument count; should be %d pairs.", ERR_KEY
index f7cc422f4e6a04efda36f333d624af53077c672f..19fe71408eb7a4960409ffa43f8d20c8221781c2 100644 (file)
@@ -1346,7 +1346,7 @@ void parse_rule_type(SnortConfig* sc, const char* s, RuleTreeNode& rtn)
         s_ignore = true;
 
     else
-        rtn.listhead = get_rule_list(sc, (RuleType)rtn.type);
+        rtn.listhead = get_rule_list(sc, s);
 }
 
 void parse_rule_proto(SnortConfig* sc, const char* s, RuleTreeNode& rtn)