What are bpf maps used for? - bpf

Can eBPF maps be used to share information between two functions?
For example: get process name from one function; and if processname == "something" drop the packet using XDP.
An example would be appreciated.

BPF maps are used to retain information between two executions of BPF programs. So what you're describing is one possible use case.
Examples of map usage can be found in the Linux samples and in the bcc examples.

Adding two reference links to pchaigno's answer, ebpf.io and Cilium's BPF and XDP reference guide.

Related

How to keep program data in different m files in matlab

I want to write a modular matlab program and I have some data structures such as history in my program. Is that true that I have to keep all my data-structures in the main script of my program? In other words if I have some arrays and fields of data, if I put them in other m files, such as functions, they are temporal and they are going to be collected as garbage in my program execution. I am a java developer and now I want to develop some code in matlab.
As Tommaso suggested in a comment, you should use classes. Look at the documentation for classdef to get started. The full documentation to create classes starts at this page.
But to directly answer your question: it is possible to store static data in functions: see persistent.
If you're making a GUI, there are built-in ways to store data, see guidata.
Finally, there is also getappdata and setappdata, which set global variables but specific to one app.
For all that's good in this world, don't use global, it's not worth the hassle, here are plenty of better alternatives.
PS: if the links here break, note that it is always possible to type help <cmd> to get help on one of the functions mentioned here.

Reading Siemens S7 PLC symbol table

I would like, for educational purposes, to read PLC symbols table by using libnodave (or any equivalent open-source like snap7).
Actually, when I read data from merkers, I must know in advance what kind of variable will be present in the DB, also due to the fact that libnodave reads raw bytes in sequences.
I'm searching a way to know in advance what kind of data was chosen by the plc programmer when storing data so, when I use raw bytes read, I can easily monitor variables and adapt my reading and visualization routine.
Thanks in advance.
A program in a S7-3xx/4xx PLC has no symbolic addressing downloaded. So Libnodave or Snap7 can't point to a symbol.
TIA and the S7-12xx/15xx PLC are different. They have symbols downloaded. But so far as i know Libnodave or Snap7 can not use these symbols yet.
A solution maybe is the export the Symboltable is Step7/TIA to an Excel or .scv file and read there the symbol with it's format and address information.
(Libnodave does not support S7-12xx/15xx, use Snap7 instead.)

How to Use WordNet::Similarity module?

I want to compare multiple sentences and find out the similarity between them. I have installed the WordNet::Similarity module. But I am not getting any way to how to use it.
Thanks in advance.
If you choose to use a module the bare minimum you need to do is read the documentation. There is a section called Typical usage examples. Other than that the distribution itself has examples included.

How to implement interfaces in MyHDL

In VHDL, I often use records to group related signals into something that can be passed around as a single object, e.g. in a port map. What's the MyHDL way of doing this?
Interfaces are available in the 0.9-dev and
are straightforward. If you have an object
(class) with Signals in it it will be name
extended in conversion.
It is explained in the MEP
http://www.myhdl.org/doku.php/meps:mep-107
More examples available here (I realize it
is not well documented - yet):
https://bitbucket.org/cfelton/minnesota
Also, a small example available here:
http://www.edaplayground.com/s/130/941

How to access an array of structs in simulink?

I have the problem, that I have to access a funktion form a dll in matlab/Simulink in the rtw.
This should work with a s function, but I have the needed parameters in a array of structures organized.
The question is now how I can reach them when I want to call my DLL function?
Or is there a better way (e.g. level 2 Matlab files or something similar)?
The pure simulation (without RTW) worked pretty well with level 2 m files but I am not able to write a tlc file for compiling them. I did not find much on the net and the documentation only about C sources.
Thanks
Christian
For signals in Simulink, what you are asking for is an array of buses. There is similar support for using arrays of structs for parameters. For calling an external function, you might want to look at the legacy code tool. You might also be able to use the MATLAB function block to call your external dll.
In addition to what #MikeT says:
Generating code from Level 2 M-S-Functions is problematic. Read this: http://www.mathworks.co.uk/help/toolbox/simulink/sfg/f7-67622.html#brgscav-1
Also, M-S-functions are generally slow, because they run in the MATLAB interpreter: http://blogs.mathworks.com/seth/2010/10/28/tips-for-simulation-performance/
In the end I coded the problem in C and used an array where I defined to order of the elements. Then I wrote some interface functions to access this "virtual" struct.
This is not very good coding but the easiest way I have found and it is portable.
Thanks