MCPcopy
hub / github.com/bettercap/bettercap / Configure

Method Configure

modules/packet_proxy/packet_proxy_linux.go:125–194  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

123}
124
125func (mod *PacketProxy) Configure() (err error) {
126 mod.destroyQueue()
127
128 if err, mod.queueNum = mod.IntParam("packet.proxy.queue.num"); err != nil {
129 return
130 } else if err, mod.chainName = mod.StringParam("packet.proxy.chain"); err != nil {
131 return
132 } else if err, mod.rule = mod.StringParam("packet.proxy.rule"); err != nil {
133 return
134 } else if err, mod.pluginPath = mod.StringParam("packet.proxy.plugin"); err != nil {
135 return
136 }
137
138 if mod.pluginPath != "" {
139 if !fs.Exists(mod.pluginPath) {
140 return fmt.Errorf("%s does not exist.", mod.pluginPath)
141 }
142
143 mod.Info("loading packet proxy plugin from %s ...", mod.pluginPath)
144
145 var ok bool
146 var sym plugin.Symbol
147
148 if mod.plugin, err = plugin.Open(mod.pluginPath); err != nil {
149 return
150 } else if sym, err = mod.plugin.Lookup("OnPacket"); err != nil {
151 return
152 } else if mod.queueCb, ok = sym.(func(q *nfqueue.Nfqueue, a nfqueue.Attribute) int); !ok {
153 return fmt.Errorf("Symbol OnPacket is not a valid callback function.")
154 }
155
156 if sym, err = mod.plugin.Lookup("OnStart"); err == nil {
157 var onStartCb func() int
158 if onStartCb, ok = sym.(func() int); !ok {
159 return fmt.Errorf("OnStart signature does not match expected signature: 'func() int'")
160 } else {
161 var result int
162 if result = onStartCb(); result != 0 {
163 return fmt.Errorf("OnStart returned non-zero result. result=%d", result)
164 }
165 }
166 }
167 } else {
168 mod.Warning("no plugin set")
169 }
170
171 config := nfqueue.Config{
172 NfQueue: uint16(mod.queueNum),
173 Copymode: nfqueue.NfQnlCopyPacket,
174 AfFamily: syscall.AF_INET,
175 MaxPacketLen: 0xFFFF,
176 MaxQueueLen: 0xFF,
177 WriteTimeout: 15 * time.Millisecond,
178 }
179
180 mod.Debug("config: %+v", config)
181
182 if err = mod.runRule(true); err != nil {

Callers 1

StartMethod · 0.95

Calls 9

destroyQueueMethod · 0.95
runRuleMethod · 0.95
IntParamMethod · 0.80
StringParamMethod · 0.80
LookupMethod · 0.80
InfoMethod · 0.45
WarningMethod · 0.45
DebugMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected