-
Notifications
You must be signed in to change notification settings - Fork 2.9k
/
snmpm_network_interface_filter.erl
128 lines (105 loc) · 4.87 KB
/
snmpm_network_interface_filter.erl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
%%
%% %CopyrightBegin%
%%
%% Copyright Ericsson AB 2009-2024. All Rights Reserved.
%%
%% Licensed under the Apache License, Version 2.0 (the "License");
%% you may not use this file except in compliance with the License.
%% You may obtain a copy of the License at
%%
%% http://www.apache.org/licenses/LICENSE-2.0
%%
%% Unless required by applicable law or agreed to in writing, software
%% distributed under the License is distributed on an "AS IS" BASIS,
%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
%% See the License for the specific language governing permissions and
%% limitations under the License.
%%
%% %CopyrightEnd%
%%
-module(snmpm_network_interface_filter).
-moduledoc """
Behaviour module for the SNMP manager network-interface filter.
This module defines the behaviour of the manager network interface filter. A
`snmpm_network_interface_filter` compliant module must export the following
functions:
- [`accept_recv/2`](`c:accept_recv/2`)
- [`accept_send/2`](`c:accept_send/2`)
- [`accept_recv_pdu/3`](`c:accept_recv_pdu/3`)
- [`accept_send_pdu/3`](`c:accept_send_pdu/3`)
The semantics of them and their exact signatures are explained below.
The purpose of the network interface filter is to allow for filtering of
messages (accept or reject) receive and send. This is done on two levels:
- The first level is at the UDP entry / exit point, i.e. immediately after the
receipt of the message, before any message processing is done (accept_recv)
and immediately before sending the message, after all message processing is
done (accept_send).
- The second level is at the MPD entry / exit point, i.e. immediately after the
basic message processing (accept_recv_pdu) / immediately before the basic
message processing (accept_send_pdu).
Note that the network interface filter is something which is used by the network
interface implementation provided by the application (`snmpm_net_if` and
`snmpm_net_if_mt`). The default filter accepts all messages.
A network interface filter can e.g. be used during testing or for load
regulation.
Legacy network interface filter modules used arguments on the form
`(IpAddr, PortNumber,...)` instead of `(Domain, Addr, ...)`, and if the SNMP
manager is run without changing the configuration to use transport domains the
network interface filter will still get the old arguments and work as before.
""".
-export([verify/1]).
-type transportDomain() :: snmpa_conf:transportDomain().
-type transportAddressWithPort() :: snmpa_conf:transportAddressWithPort().
-type pdu_type() :: snmpm:pdu_type().
%% **************************************************************************
%% accept_recv(address(), port()) -> boolean()
%% Called at the reception of a message
%% (before *any* processing has been done).
-doc """
Called at the reception of a message (before _any_ processing has been done).
For the message to be rejected, the function _must_ return _false_.
""".
-callback accept_recv(Domain, Addr) -> boolean() when
Domain :: transportDomain(),
Addr :: transportAddressWithPort().
%% **************************************************************************
%% accept_send(address(), port()) -> boolean()
%% Called before the sending of a message
%% (after *all* processing has been done).
-doc """
Called before the sending of a message (after _all_ processing has been done).
For the message to be rejected, the function _must_ return _false_.
""".
-callback accept_send(Domain, Addr) -> boolean() when
Domain :: transportDomain(),
Addr :: transportAddressWithPort().
%% **************************************************************************
%% accept_recv_pdu(Addr, Port, pdu_type()) -> boolean()
%% Called after the basic message processing (MPD) has been done,
%% but before the pdu is handed over to the master-agent for
%% primary processing.
-doc """
Called after the basic message processing (MPD) has been done, but before the
pdu is handed over to the server for primary processing.
For the pdu to be rejected, the function _must_ return _false_.
""".
-callback accept_recv_pdu(Domain, Addr, PduType) -> boolean() when
Domain :: transportDomain(),
Addr :: transportAddressWithPort(),
PduType :: pdu_type().
%% **************************************************************************
%% accept_send_pdu(Addr, Port, pdu_type()) -> boolean()
%% Called before the basic message processing (MPD) is done,
%% when a pdu has been received from the master-agent.
-doc """
Called before the basic message processing (MPD) is done, when a pdu has been
received from the master-agent.
For the message to be rejected, the function _must_ return _false_.
""".
-callback accept_send_pdu(Domain, Addr, PduType) -> boolean() when
Domain :: transportDomain(),
Addr :: transportAddressWithPort(),
PduType :: pdu_type().
-doc false.
verify(Module) ->
snmp_misc:verify_behaviour(?MODULE, Module).