• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# How to contribute
2
3Contributors are essential to Scapy (as they are to most open source
4projects). Here is some advice to help you help the project!
5
6## Project objectives
7
8We try to keep Scapy as powerful as possible, to support as many
9protocols and platforms as possible, to keep and make the code (and
10the commit history) as clean as possible.
11
12Since Scapy can be slow and memory consuming, we try to limit CPU and
13memory usage, particularly in parts of the code often called.
14
15## What to contribute?
16
17You want to spend to time working on Scapy but have no (or little)
18idea what to do? You can look for open issues
19[labeled "contributions wanted"](https://github.com/secdev/scapy/labels/contributions%20wanted), or look at the [contributions roadmap](https://github.com/secdev/scapy/issues/399)
20
21If you have any ideas of useful contributions that you cannot (or do
22not want to) do yourself, open an issue and use the label
23"contributions wanted".
24
25Once you have chosen a contribution, open an issue to let other people
26know you're working on it (or assign the existing issue to yourself)
27and track your progress. You might want to ask whether you're working
28in an appropriate direction, to avoid the frustration of seeing your
29contribution rejected after a lot of work.
30
31## Reporting issues
32
33### Questions
34
35It is OK so submit issues to ask questions (more than OK,
36encouraged). There is a label "question" that you can use for that.
37
38### Bugs
39
40If you have installed Scapy through a package manager (from your Linux
41or BSD system, from PyPI, etc.), please get and install the current
42development code, and check that the bug still exists before
43submitting an issue.
44
45Please label your issues "bug".
46
47If you're not sure whether a behavior is a bug or not, submit an issue
48and ask, don't be shy!
49
50### Enhancements / feature requests
51
52If you want a feature in Scapy, but cannot implement it yourself or
53want some hints on how to do that, open an issue with label
54"enhancement".
55
56Explain if possible the API you would like to have (e.g., give examples
57of function calls, packet creations, etc.).
58
59## Submitting pull requests
60
61### Coding style & conventions
62
63First, Scapy "legacy" code contains a lot of code that do not comply
64with the following recommendations, but we try to comply with the some
65guidelines for new code.
66
67  - The code should be PEP-8 compliant; you can check your code with
68    [pep8](https://pypi.python.org/pypi/pep8).
69  - [Pylint](http://www.pylint.org/) can help you write good Python
70    code (even if respecting Pylint rules is sometimes either too hard
71    or even undesirable; human brain needed!).
72  - [Google Python Style Guide](https://google.github.io/styleguide/pyguide.html)
73    is a nice read!
74  - Avoid creating unnecessary `list` objects, particularly if they
75    can be huge (e.g., when possible, use `scapy.modules.six.range()` instead of
76    `range()`, `for line in fdesc` instead of `for line in
77    fdesc.readlines()`; more generally prefer generators over lists).
78
79### Tests
80
81Please consider adding tests for your new features or that trigger the
82bug you are fixing. This will prevent a regression from being
83unnoticed.
84
85### New protocols
86
87New protocols can go either in `scapy/layers` or to
88`scapy/contrib`. Protocols in `scapy/layers` should be usually found
89on common networks, while protocols in `scapy/contrib` should be
90uncommon or specific.
91
92### Features
93
94Protocol-related features should be implemented within the same module
95as the protocol layers(s) (e.g., `traceroute()` is implemented in
96`scapy/layers/inet.py`).
97
98Other features may be implemented in a module (`scapy/modules`) or a
99contribution (`scapy/contrib`).
100
101### Core
102
103If you contribute to Scapy's core (e.g., `scapy/base_classes.py`,
104`scapy/packet.py`, etc.), please be very careful with performances and
105memory footprint, as it is easy to write Python code that wastes
106memory or CPU cycles.
107
108As an example, Packet().__init__() is called each time a **layer** is
109parsed from a string (during a network capture or a PCAP file
110read). Adding inefficient code here will have a disastrous effect on
111Scapy's performances.
112
113### Python 2 and 3 compatibility
114
115The project aims to provide code that works both on Python 2 and Python 3. Therefore, some rules need to be apply to achieve compatibility:
116- byte-string must be defined as `b"\x00\x01\x02"`
117- exceptions must comply with the new Python 3 format: `except SomeError as e:`
118- lambdas must be written using a single argument when using tuples: use `lambda x_y: x_y[0] + f(x_y[1])` instead of `lambda (x, y): x + f(y)`.
119- use int instead of long
120- use list comprehension instead of map() and filter()
121- use scapy.modules.six.range instead of xrange and range
122- use scapy.modules.six.itervalues(dict) instead of dict.values() or dict.itervalues()
123- use scapy.modules.six.string_types instead of basestring
124- `__bool__ = __nonzero__` must be used when declaring `__nonzero__` methods
125- `io.BytesIO` must be used instead of `StringIO` when using bytes
126- `__cmp__` must not be used.
127- UserDict should be imported via `six.UserDict`
128
129### Code review
130
131Maintainers tend to be picky, and you might feel frustrated that your
132code (which is perfectly working in your use case) is not merged
133faster.
134
135Please don't be offended, and keep in mind that maintainers are
136concerned about code maintainability and readability, commit history
137(we use the history a lot, for example to find regressions or
138understand why certain decisions have been made), performances,
139integration in Scapy, API consistency (so that someone who knows how
140to use Scapy will know how to use your code), etc.
141
142**Thanks for reading, happy hacking!**
143