Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changes in swss-common submodule to support NAT feature. #304

Merged
merged 5 commits into from
Nov 6, 2019

Conversation

kirankella
Copy link
Contributor

@kirankella kirankella commented Sep 16, 2019

  • Add new tables in CONFIG_DB, APP_DB, COUNTERS_DB
  • Netlink class for abstracting netfilter application socket

Link to NAT HLD:
https://github.com/kirankella/SONiC/blob/nat_doc_changes/doc/nat/nat_design_spec.md

Signed-off-by: kiran.kella@broadcom.com

 * Add new tables in CONFIG_DB, APP_DB, COUNTERS_DB
 * Netlink class for abstracting netfilter application socket

Signed-off-by: kiran.kella@broadcom.com
{
if (nfnl_ct_add(m_socket, ct, NLM_F_REPLACE) < 0)
{
SWSS_LOG_ERROR("Failed to update conntrack object in the kernel");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggest to SWSS_LOG_THROW or even better return a boolean whether API succeeded or not?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

int err = nl_socket_add_membership(m_socket, nfnlGroup);
if (err < 0)
{
SWSS_LOG_ERROR("Unable to register to netfilter group %d: %s", nfnlGroup,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it better to use SWSS_LOG_THROW - shortcut to log error and to throw?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

NfNetlink(int pri = 0);
~NfNetlink() override;

void registerRecvCallbacks(void);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please remove void parameter?. Seems it is legacy from C-code and in this file such style is not used expect this method

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

struct nfnl_ct *getCtObject(const IpAddress &sourceIpAddr);
struct nfnl_ct *getCtObject(uint8_t protoType, const IpAddress &sourceIpAddr, uint16_t srcPort);

static int onNetlinkRcv(struct nl_msg *msg, void *arg);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

put onNetlinkRcv declaration in #ifdef NETFILTER_UNIT_TEST

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done


private:
struct nfnl_ct *getCtObject(const IpAddress &sourceIpAddr);
struct nfnl_ct *getCtObject(uint8_t protoType, const IpAddress &sourceIpAddr, uint16_t srcPort);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are private and not used here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Were added initially during development, now these can be removed. Good catch.


namespace swss {

class NfNetlink : public Selectable {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A lot of code duplicates Netlink class, did you consider to inherit from Netlink?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inheriting from Netlink class was considered, but the Netlink class is specific to NETLINK_ROUTE and initializes m_socket member to route socket in its constructor. But NfNetlink class is specific to NETFILTER socket and Netlink class constructor invocation would result in unnecessary calls specific Route socket.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the difference is not big, one thing you can do is to define virtual private "connect" method and override it for NfNetlink to call nfnl_connect.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@stepanblyschak Are you saying, we have connect() as virtual function which is overridden by derived NfNetlink class, and call connect() in NetLink() construtor in the place of nl_connect() in the current code?
If so, since the virtual function connect() is called in the NetLink constructor, it would resolve to NetLink::connect() instead of NfNetlink::connect().
We need to get the connect() call out of the NetLink constructor and have the users of the NetLink class call the connect() explicitly.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, you're correct

nl_socket_set_nonblocking(m_socket);

/* Set socket buffer size to 10 MB */
nl_socket_set_buffer_size(m_socket, 10485760, 0);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make the buffer configurable from class user?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added an API to the class for setting the send/recv socket buffer size.

@lguohan lguohan merged commit a4a1e10 into sonic-net:master Nov 6, 2019
AkhileshSamineni added a commit to AkhileshSamineni/sonic-swss that referenced this pull request Nov 11, 2019
 - Added natsyncd and warmboot related changes.

Link to NAT HLD : https://github.com/Azure/SONiC/blob/master/doc/nat/nat_design_spec.md

Depends on:
sonic-swss :
sonic-swss-common : sonic-net/sonic-swss-common#304
sonic-linux-kernel : sonic-net/sonic-linux-kernel#100
sonic-sairedis : sonic-net/sonic-sairedis#519
AkhileshSamineni added a commit to AkhileshSamineni/sonic-swss that referenced this pull request Dec 10, 2019
 - Added natsyncd and warmboot related changes.

Link to NAT HLD : https://github.com/Azure/SONiC/blob/master/doc/nat/nat_design_spec.md

Depends on:
sonic-swss :
sonic-swss-common : sonic-net/sonic-swss-common#304
sonic-linux-kernel : sonic-net/sonic-linux-kernel#100
sonic-sairedis : sonic-net/sonic-sairedis#519
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants