repo
stringlengths 5
54
| path
stringlengths 4
155
| func_name
stringlengths 1
118
| original_string
stringlengths 52
85.5k
| language
stringclasses 1
value | code
stringlengths 52
85.5k
| code_tokens
sequence | docstring
stringlengths 6
2.61k
| docstring_tokens
sequence | sha
stringlengths 40
40
| url
stringlengths 85
252
| partition
stringclasses 1
value |
---|---|---|---|---|---|---|---|---|---|---|---|
google/netstack | tcpip/stack/stack.go | SetNetworkProtocolOption | func (s *Stack) SetNetworkProtocolOption(network tcpip.NetworkProtocolNumber, option interface{}) *tcpip.Error {
netProto, ok := s.networkProtocols[network]
if !ok {
return tcpip.ErrUnknownProtocol
}
return netProto.SetOption(option)
} | go | func (s *Stack) SetNetworkProtocolOption(network tcpip.NetworkProtocolNumber, option interface{}) *tcpip.Error {
netProto, ok := s.networkProtocols[network]
if !ok {
return tcpip.ErrUnknownProtocol
}
return netProto.SetOption(option)
} | [
"func",
"(",
"s",
"*",
"Stack",
")",
"SetNetworkProtocolOption",
"(",
"network",
"tcpip",
".",
"NetworkProtocolNumber",
",",
"option",
"interface",
"{",
"}",
")",
"*",
"tcpip",
".",
"Error",
"{",
"netProto",
",",
"ok",
":=",
"s",
".",
"networkProtocols",
"[",
"network",
"]",
"\n",
"if",
"!",
"ok",
"{",
"return",
"tcpip",
".",
"ErrUnknownProtocol",
"\n",
"}",
"\n",
"return",
"netProto",
".",
"SetOption",
"(",
"option",
")",
"\n",
"}"
] | // SetNetworkProtocolOption allows configuring individual protocol level
// options. This method returns an error if the protocol is not supported or
// option is not supported by the protocol implementation or the provided value
// is incorrect. | [
"SetNetworkProtocolOption",
"allows",
"configuring",
"individual",
"protocol",
"level",
"options",
".",
"This",
"method",
"returns",
"an",
"error",
"if",
"the",
"protocol",
"is",
"not",
"supported",
"or",
"option",
"is",
"not",
"supported",
"by",
"the",
"protocol",
"implementation",
"or",
"the",
"provided",
"value",
"is",
"incorrect",
"."
] | 70ebca9c30730cf3887cdef3b85bb96ed7a97593 | https://github.com/google/netstack/blob/70ebca9c30730cf3887cdef3b85bb96ed7a97593/tcpip/stack/stack.go#L400-L406 | train |
google/netstack | tcpip/stack/stack.go | SetTransportProtocolOption | func (s *Stack) SetTransportProtocolOption(transport tcpip.TransportProtocolNumber, option interface{}) *tcpip.Error {
transProtoState, ok := s.transportProtocols[transport]
if !ok {
return tcpip.ErrUnknownProtocol
}
return transProtoState.proto.SetOption(option)
} | go | func (s *Stack) SetTransportProtocolOption(transport tcpip.TransportProtocolNumber, option interface{}) *tcpip.Error {
transProtoState, ok := s.transportProtocols[transport]
if !ok {
return tcpip.ErrUnknownProtocol
}
return transProtoState.proto.SetOption(option)
} | [
"func",
"(",
"s",
"*",
"Stack",
")",
"SetTransportProtocolOption",
"(",
"transport",
"tcpip",
".",
"TransportProtocolNumber",
",",
"option",
"interface",
"{",
"}",
")",
"*",
"tcpip",
".",
"Error",
"{",
"transProtoState",
",",
"ok",
":=",
"s",
".",
"transportProtocols",
"[",
"transport",
"]",
"\n",
"if",
"!",
"ok",
"{",
"return",
"tcpip",
".",
"ErrUnknownProtocol",
"\n",
"}",
"\n",
"return",
"transProtoState",
".",
"proto",
".",
"SetOption",
"(",
"option",
")",
"\n",
"}"
] | // SetTransportProtocolOption allows configuring individual protocol level
// options. This method returns an error if the protocol is not supported or
// option is not supported by the protocol implementation or the provided value
// is incorrect. | [
"SetTransportProtocolOption",
"allows",
"configuring",
"individual",
"protocol",
"level",
"options",
".",
"This",
"method",
"returns",
"an",
"error",
"if",
"the",
"protocol",
"is",
"not",
"supported",
"or",
"option",
"is",
"not",
"supported",
"by",
"the",
"protocol",
"implementation",
"or",
"the",
"provided",
"value",
"is",
"incorrect",
"."
] | 70ebca9c30730cf3887cdef3b85bb96ed7a97593 | https://github.com/google/netstack/blob/70ebca9c30730cf3887cdef3b85bb96ed7a97593/tcpip/stack/stack.go#L429-L435 | train |
google/netstack | tcpip/stack/stack.go | SetTransportProtocolHandler | func (s *Stack) SetTransportProtocolHandler(p tcpip.TransportProtocolNumber, h func(*Route, TransportEndpointID, buffer.View, buffer.VectorisedView) bool) {
state := s.transportProtocols[p]
if state != nil {
state.defaultHandler = h
}
} | go | func (s *Stack) SetTransportProtocolHandler(p tcpip.TransportProtocolNumber, h func(*Route, TransportEndpointID, buffer.View, buffer.VectorisedView) bool) {
state := s.transportProtocols[p]
if state != nil {
state.defaultHandler = h
}
} | [
"func",
"(",
"s",
"*",
"Stack",
")",
"SetTransportProtocolHandler",
"(",
"p",
"tcpip",
".",
"TransportProtocolNumber",
",",
"h",
"func",
"(",
"*",
"Route",
",",
"TransportEndpointID",
",",
"buffer",
".",
"View",
",",
"buffer",
".",
"VectorisedView",
")",
"bool",
")",
"{",
"state",
":=",
"s",
".",
"transportProtocols",
"[",
"p",
"]",
"\n",
"if",
"state",
"!=",
"nil",
"{",
"state",
".",
"defaultHandler",
"=",
"h",
"\n",
"}",
"\n",
"}"
] | // SetTransportProtocolHandler sets the per-stack default handler for the given
// protocol.
//
// It must be called only during initialization of the stack. Changing it as the
// stack is operating is not supported. | [
"SetTransportProtocolHandler",
"sets",
"the",
"per",
"-",
"stack",
"default",
"handler",
"for",
"the",
"given",
"protocol",
".",
"It",
"must",
"be",
"called",
"only",
"during",
"initialization",
"of",
"the",
"stack",
".",
"Changing",
"it",
"as",
"the",
"stack",
"is",
"operating",
"is",
"not",
"supported",
"."
] | 70ebca9c30730cf3887cdef3b85bb96ed7a97593 | https://github.com/google/netstack/blob/70ebca9c30730cf3887cdef3b85bb96ed7a97593/tcpip/stack/stack.go#L457-L462 | train |
google/netstack | tcpip/stack/stack.go | SetForwarding | func (s *Stack) SetForwarding(enable bool) {
// TODO(igudger, bgeffon): Expose via /proc/sys/net/ipv4/ip_forward.
s.mu.Lock()
s.forwarding = enable
s.mu.Unlock()
} | go | func (s *Stack) SetForwarding(enable bool) {
// TODO(igudger, bgeffon): Expose via /proc/sys/net/ipv4/ip_forward.
s.mu.Lock()
s.forwarding = enable
s.mu.Unlock()
} | [
"func",
"(",
"s",
"*",
"Stack",
")",
"SetForwarding",
"(",
"enable",
"bool",
")",
"{",
"// TODO(igudger, bgeffon): Expose via /proc/sys/net/ipv4/ip_forward.",
"s",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"s",
".",
"forwarding",
"=",
"enable",
"\n",
"s",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n",
"}"
] | // SetForwarding enables or disables the packet forwarding between NICs. | [
"SetForwarding",
"enables",
"or",
"disables",
"the",
"packet",
"forwarding",
"between",
"NICs",
"."
] | 70ebca9c30730cf3887cdef3b85bb96ed7a97593 | https://github.com/google/netstack/blob/70ebca9c30730cf3887cdef3b85bb96ed7a97593/tcpip/stack/stack.go#L478-L483 | train |
google/netstack | tcpip/stack/stack.go | Forwarding | func (s *Stack) Forwarding() bool {
// TODO(igudger, bgeffon): Expose via /proc/sys/net/ipv4/ip_forward.
s.mu.RLock()
defer s.mu.RUnlock()
return s.forwarding
} | go | func (s *Stack) Forwarding() bool {
// TODO(igudger, bgeffon): Expose via /proc/sys/net/ipv4/ip_forward.
s.mu.RLock()
defer s.mu.RUnlock()
return s.forwarding
} | [
"func",
"(",
"s",
"*",
"Stack",
")",
"Forwarding",
"(",
")",
"bool",
"{",
"// TODO(igudger, bgeffon): Expose via /proc/sys/net/ipv4/ip_forward.",
"s",
".",
"mu",
".",
"RLock",
"(",
")",
"\n",
"defer",
"s",
".",
"mu",
".",
"RUnlock",
"(",
")",
"\n",
"return",
"s",
".",
"forwarding",
"\n",
"}"
] | // Forwarding returns if the packet forwarding between NICs is enabled. | [
"Forwarding",
"returns",
"if",
"the",
"packet",
"forwarding",
"between",
"NICs",
"is",
"enabled",
"."
] | 70ebca9c30730cf3887cdef3b85bb96ed7a97593 | https://github.com/google/netstack/blob/70ebca9c30730cf3887cdef3b85bb96ed7a97593/tcpip/stack/stack.go#L486-L491 | train |
google/netstack | tcpip/stack/stack.go | SetRouteTable | func (s *Stack) SetRouteTable(table []tcpip.Route) {
s.mu.Lock()
defer s.mu.Unlock()
s.routeTable = table
} | go | func (s *Stack) SetRouteTable(table []tcpip.Route) {
s.mu.Lock()
defer s.mu.Unlock()
s.routeTable = table
} | [
"func",
"(",
"s",
"*",
"Stack",
")",
"SetRouteTable",
"(",
"table",
"[",
"]",
"tcpip",
".",
"Route",
")",
"{",
"s",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"s",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n\n",
"s",
".",
"routeTable",
"=",
"table",
"\n",
"}"
] | // SetRouteTable assigns the route table to be used by this stack. It
// specifies which NIC to use for given destination address ranges. | [
"SetRouteTable",
"assigns",
"the",
"route",
"table",
"to",
"be",
"used",
"by",
"this",
"stack",
".",
"It",
"specifies",
"which",
"NIC",
"to",
"use",
"for",
"given",
"destination",
"address",
"ranges",
"."
] | 70ebca9c30730cf3887cdef3b85bb96ed7a97593 | https://github.com/google/netstack/blob/70ebca9c30730cf3887cdef3b85bb96ed7a97593/tcpip/stack/stack.go#L495-L500 | train |
google/netstack | tcpip/stack/stack.go | GetRouteTable | func (s *Stack) GetRouteTable() []tcpip.Route {
s.mu.Lock()
defer s.mu.Unlock()
return append([]tcpip.Route(nil), s.routeTable...)
} | go | func (s *Stack) GetRouteTable() []tcpip.Route {
s.mu.Lock()
defer s.mu.Unlock()
return append([]tcpip.Route(nil), s.routeTable...)
} | [
"func",
"(",
"s",
"*",
"Stack",
")",
"GetRouteTable",
"(",
")",
"[",
"]",
"tcpip",
".",
"Route",
"{",
"s",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"s",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n",
"return",
"append",
"(",
"[",
"]",
"tcpip",
".",
"Route",
"(",
"nil",
")",
",",
"s",
".",
"routeTable",
"...",
")",
"\n",
"}"
] | // GetRouteTable returns the route table which is currently in use. | [
"GetRouteTable",
"returns",
"the",
"route",
"table",
"which",
"is",
"currently",
"in",
"use",
"."
] | 70ebca9c30730cf3887cdef3b85bb96ed7a97593 | https://github.com/google/netstack/blob/70ebca9c30730cf3887cdef3b85bb96ed7a97593/tcpip/stack/stack.go#L503-L507 | train |
google/netstack | tcpip/stack/stack.go | NewRawEndpoint | func (s *Stack) NewRawEndpoint(transport tcpip.TransportProtocolNumber, network tcpip.NetworkProtocolNumber, waiterQueue *waiter.Queue) (tcpip.Endpoint, *tcpip.Error) {
if !s.raw {
return nil, tcpip.ErrNotPermitted
}
t, ok := s.transportProtocols[transport]
if !ok {
return nil, tcpip.ErrUnknownProtocol
}
return t.proto.NewRawEndpoint(s, network, waiterQueue)
} | go | func (s *Stack) NewRawEndpoint(transport tcpip.TransportProtocolNumber, network tcpip.NetworkProtocolNumber, waiterQueue *waiter.Queue) (tcpip.Endpoint, *tcpip.Error) {
if !s.raw {
return nil, tcpip.ErrNotPermitted
}
t, ok := s.transportProtocols[transport]
if !ok {
return nil, tcpip.ErrUnknownProtocol
}
return t.proto.NewRawEndpoint(s, network, waiterQueue)
} | [
"func",
"(",
"s",
"*",
"Stack",
")",
"NewRawEndpoint",
"(",
"transport",
"tcpip",
".",
"TransportProtocolNumber",
",",
"network",
"tcpip",
".",
"NetworkProtocolNumber",
",",
"waiterQueue",
"*",
"waiter",
".",
"Queue",
")",
"(",
"tcpip",
".",
"Endpoint",
",",
"*",
"tcpip",
".",
"Error",
")",
"{",
"if",
"!",
"s",
".",
"raw",
"{",
"return",
"nil",
",",
"tcpip",
".",
"ErrNotPermitted",
"\n",
"}",
"\n\n",
"t",
",",
"ok",
":=",
"s",
".",
"transportProtocols",
"[",
"transport",
"]",
"\n",
"if",
"!",
"ok",
"{",
"return",
"nil",
",",
"tcpip",
".",
"ErrUnknownProtocol",
"\n",
"}",
"\n\n",
"return",
"t",
".",
"proto",
".",
"NewRawEndpoint",
"(",
"s",
",",
"network",
",",
"waiterQueue",
")",
"\n",
"}"
] | // NewRawEndpoint creates a new raw transport layer endpoint of the given
// protocol. Raw endpoints receive all traffic for a given protocol regardless
// of address. | [
"NewRawEndpoint",
"creates",
"a",
"new",
"raw",
"transport",
"layer",
"endpoint",
"of",
"the",
"given",
"protocol",
".",
"Raw",
"endpoints",
"receive",
"all",
"traffic",
"for",
"a",
"given",
"protocol",
"regardless",
"of",
"address",
"."
] | 70ebca9c30730cf3887cdef3b85bb96ed7a97593 | https://github.com/google/netstack/blob/70ebca9c30730cf3887cdef3b85bb96ed7a97593/tcpip/stack/stack.go#L522-L533 | train |
google/netstack | tcpip/stack/stack.go | createNIC | func (s *Stack) createNIC(id tcpip.NICID, name string, linkEP tcpip.LinkEndpointID, enabled, loopback bool) *tcpip.Error {
ep := FindLinkEndpoint(linkEP)
if ep == nil {
return tcpip.ErrBadLinkEndpoint
}
s.mu.Lock()
defer s.mu.Unlock()
// Make sure id is unique.
if _, ok := s.nics[id]; ok {
return tcpip.ErrDuplicateNICID
}
n := newNIC(s, id, name, ep, loopback)
s.nics[id] = n
if enabled {
n.attachLinkEndpoint()
}
return nil
} | go | func (s *Stack) createNIC(id tcpip.NICID, name string, linkEP tcpip.LinkEndpointID, enabled, loopback bool) *tcpip.Error {
ep := FindLinkEndpoint(linkEP)
if ep == nil {
return tcpip.ErrBadLinkEndpoint
}
s.mu.Lock()
defer s.mu.Unlock()
// Make sure id is unique.
if _, ok := s.nics[id]; ok {
return tcpip.ErrDuplicateNICID
}
n := newNIC(s, id, name, ep, loopback)
s.nics[id] = n
if enabled {
n.attachLinkEndpoint()
}
return nil
} | [
"func",
"(",
"s",
"*",
"Stack",
")",
"createNIC",
"(",
"id",
"tcpip",
".",
"NICID",
",",
"name",
"string",
",",
"linkEP",
"tcpip",
".",
"LinkEndpointID",
",",
"enabled",
",",
"loopback",
"bool",
")",
"*",
"tcpip",
".",
"Error",
"{",
"ep",
":=",
"FindLinkEndpoint",
"(",
"linkEP",
")",
"\n",
"if",
"ep",
"==",
"nil",
"{",
"return",
"tcpip",
".",
"ErrBadLinkEndpoint",
"\n",
"}",
"\n\n",
"s",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"s",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n\n",
"// Make sure id is unique.",
"if",
"_",
",",
"ok",
":=",
"s",
".",
"nics",
"[",
"id",
"]",
";",
"ok",
"{",
"return",
"tcpip",
".",
"ErrDuplicateNICID",
"\n",
"}",
"\n\n",
"n",
":=",
"newNIC",
"(",
"s",
",",
"id",
",",
"name",
",",
"ep",
",",
"loopback",
")",
"\n\n",
"s",
".",
"nics",
"[",
"id",
"]",
"=",
"n",
"\n",
"if",
"enabled",
"{",
"n",
".",
"attachLinkEndpoint",
"(",
")",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] | // createNIC creates a NIC with the provided id and link-layer endpoint, and
// optionally enable it. | [
"createNIC",
"creates",
"a",
"NIC",
"with",
"the",
"provided",
"id",
"and",
"link",
"-",
"layer",
"endpoint",
"and",
"optionally",
"enable",
"it",
"."
] | 70ebca9c30730cf3887cdef3b85bb96ed7a97593 | https://github.com/google/netstack/blob/70ebca9c30730cf3887cdef3b85bb96ed7a97593/tcpip/stack/stack.go#L537-L559 | train |
google/netstack | tcpip/stack/stack.go | CreateNIC | func (s *Stack) CreateNIC(id tcpip.NICID, linkEP tcpip.LinkEndpointID) *tcpip.Error {
return s.createNIC(id, "", linkEP, true, false)
} | go | func (s *Stack) CreateNIC(id tcpip.NICID, linkEP tcpip.LinkEndpointID) *tcpip.Error {
return s.createNIC(id, "", linkEP, true, false)
} | [
"func",
"(",
"s",
"*",
"Stack",
")",
"CreateNIC",
"(",
"id",
"tcpip",
".",
"NICID",
",",
"linkEP",
"tcpip",
".",
"LinkEndpointID",
")",
"*",
"tcpip",
".",
"Error",
"{",
"return",
"s",
".",
"createNIC",
"(",
"id",
",",
"\"",
"\"",
",",
"linkEP",
",",
"true",
",",
"false",
")",
"\n",
"}"
] | // CreateNIC creates a NIC with the provided id and link-layer endpoint. | [
"CreateNIC",
"creates",
"a",
"NIC",
"with",
"the",
"provided",
"id",
"and",
"link",
"-",
"layer",
"endpoint",
"."
] | 70ebca9c30730cf3887cdef3b85bb96ed7a97593 | https://github.com/google/netstack/blob/70ebca9c30730cf3887cdef3b85bb96ed7a97593/tcpip/stack/stack.go#L562-L564 | train |
google/netstack | tcpip/stack/stack.go | CreateNamedNIC | func (s *Stack) CreateNamedNIC(id tcpip.NICID, name string, linkEP tcpip.LinkEndpointID) *tcpip.Error {
return s.createNIC(id, name, linkEP, true, false)
} | go | func (s *Stack) CreateNamedNIC(id tcpip.NICID, name string, linkEP tcpip.LinkEndpointID) *tcpip.Error {
return s.createNIC(id, name, linkEP, true, false)
} | [
"func",
"(",
"s",
"*",
"Stack",
")",
"CreateNamedNIC",
"(",
"id",
"tcpip",
".",
"NICID",
",",
"name",
"string",
",",
"linkEP",
"tcpip",
".",
"LinkEndpointID",
")",
"*",
"tcpip",
".",
"Error",
"{",
"return",
"s",
".",
"createNIC",
"(",
"id",
",",
"name",
",",
"linkEP",
",",
"true",
",",
"false",
")",
"\n",
"}"
] | // CreateNamedNIC creates a NIC with the provided id and link-layer endpoint,
// and a human-readable name. | [
"CreateNamedNIC",
"creates",
"a",
"NIC",
"with",
"the",
"provided",
"id",
"and",
"link",
"-",
"layer",
"endpoint",
"and",
"a",
"human",
"-",
"readable",
"name",
"."
] | 70ebca9c30730cf3887cdef3b85bb96ed7a97593 | https://github.com/google/netstack/blob/70ebca9c30730cf3887cdef3b85bb96ed7a97593/tcpip/stack/stack.go#L568-L570 | train |
google/netstack | tcpip/stack/stack.go | CreateDisabledNIC | func (s *Stack) CreateDisabledNIC(id tcpip.NICID, linkEP tcpip.LinkEndpointID) *tcpip.Error {
return s.createNIC(id, "", linkEP, false, false)
} | go | func (s *Stack) CreateDisabledNIC(id tcpip.NICID, linkEP tcpip.LinkEndpointID) *tcpip.Error {
return s.createNIC(id, "", linkEP, false, false)
} | [
"func",
"(",
"s",
"*",
"Stack",
")",
"CreateDisabledNIC",
"(",
"id",
"tcpip",
".",
"NICID",
",",
"linkEP",
"tcpip",
".",
"LinkEndpointID",
")",
"*",
"tcpip",
".",
"Error",
"{",
"return",
"s",
".",
"createNIC",
"(",
"id",
",",
"\"",
"\"",
",",
"linkEP",
",",
"false",
",",
"false",
")",
"\n",
"}"
] | // CreateDisabledNIC creates a NIC with the provided id and link-layer endpoint,
// but leave it disable. Stack.EnableNIC must be called before the link-layer
// endpoint starts delivering packets to it. | [
"CreateDisabledNIC",
"creates",
"a",
"NIC",
"with",
"the",
"provided",
"id",
"and",
"link",
"-",
"layer",
"endpoint",
"but",
"leave",
"it",
"disable",
".",
"Stack",
".",
"EnableNIC",
"must",
"be",
"called",
"before",
"the",
"link",
"-",
"layer",
"endpoint",
"starts",
"delivering",
"packets",
"to",
"it",
"."
] | 70ebca9c30730cf3887cdef3b85bb96ed7a97593 | https://github.com/google/netstack/blob/70ebca9c30730cf3887cdef3b85bb96ed7a97593/tcpip/stack/stack.go#L581-L583 | train |
google/netstack | tcpip/stack/stack.go | EnableNIC | func (s *Stack) EnableNIC(id tcpip.NICID) *tcpip.Error {
s.mu.RLock()
defer s.mu.RUnlock()
nic := s.nics[id]
if nic == nil {
return tcpip.ErrUnknownNICID
}
nic.attachLinkEndpoint()
return nil
} | go | func (s *Stack) EnableNIC(id tcpip.NICID) *tcpip.Error {
s.mu.RLock()
defer s.mu.RUnlock()
nic := s.nics[id]
if nic == nil {
return tcpip.ErrUnknownNICID
}
nic.attachLinkEndpoint()
return nil
} | [
"func",
"(",
"s",
"*",
"Stack",
")",
"EnableNIC",
"(",
"id",
"tcpip",
".",
"NICID",
")",
"*",
"tcpip",
".",
"Error",
"{",
"s",
".",
"mu",
".",
"RLock",
"(",
")",
"\n",
"defer",
"s",
".",
"mu",
".",
"RUnlock",
"(",
")",
"\n\n",
"nic",
":=",
"s",
".",
"nics",
"[",
"id",
"]",
"\n",
"if",
"nic",
"==",
"nil",
"{",
"return",
"tcpip",
".",
"ErrUnknownNICID",
"\n",
"}",
"\n\n",
"nic",
".",
"attachLinkEndpoint",
"(",
")",
"\n\n",
"return",
"nil",
"\n",
"}"
] | // EnableNIC enables the given NIC so that the link-layer endpoint can start
// delivering packets to it. | [
"EnableNIC",
"enables",
"the",
"given",
"NIC",
"so",
"that",
"the",
"link",
"-",
"layer",
"endpoint",
"can",
"start",
"delivering",
"packets",
"to",
"it",
"."
] | 70ebca9c30730cf3887cdef3b85bb96ed7a97593 | https://github.com/google/netstack/blob/70ebca9c30730cf3887cdef3b85bb96ed7a97593/tcpip/stack/stack.go#L593-L605 | train |
google/netstack | tcpip/stack/stack.go | CheckNIC | func (s *Stack) CheckNIC(id tcpip.NICID) bool {
s.mu.RLock()
nic, ok := s.nics[id]
s.mu.RUnlock()
if ok {
return nic.linkEP.IsAttached()
}
return false
} | go | func (s *Stack) CheckNIC(id tcpip.NICID) bool {
s.mu.RLock()
nic, ok := s.nics[id]
s.mu.RUnlock()
if ok {
return nic.linkEP.IsAttached()
}
return false
} | [
"func",
"(",
"s",
"*",
"Stack",
")",
"CheckNIC",
"(",
"id",
"tcpip",
".",
"NICID",
")",
"bool",
"{",
"s",
".",
"mu",
".",
"RLock",
"(",
")",
"\n",
"nic",
",",
"ok",
":=",
"s",
".",
"nics",
"[",
"id",
"]",
"\n",
"s",
".",
"mu",
".",
"RUnlock",
"(",
")",
"\n",
"if",
"ok",
"{",
"return",
"nic",
".",
"linkEP",
".",
"IsAttached",
"(",
")",
"\n",
"}",
"\n",
"return",
"false",
"\n",
"}"
] | // CheckNIC checks if a NIC is usable. | [
"CheckNIC",
"checks",
"if",
"a",
"NIC",
"is",
"usable",
"."
] | 70ebca9c30730cf3887cdef3b85bb96ed7a97593 | https://github.com/google/netstack/blob/70ebca9c30730cf3887cdef3b85bb96ed7a97593/tcpip/stack/stack.go#L608-L616 | train |
google/netstack | tcpip/stack/stack.go | NICSubnets | func (s *Stack) NICSubnets() map[tcpip.NICID][]tcpip.Subnet {
s.mu.RLock()
defer s.mu.RUnlock()
nics := map[tcpip.NICID][]tcpip.Subnet{}
for id, nic := range s.nics {
nics[id] = append(nics[id], nic.Subnets()...)
}
return nics
} | go | func (s *Stack) NICSubnets() map[tcpip.NICID][]tcpip.Subnet {
s.mu.RLock()
defer s.mu.RUnlock()
nics := map[tcpip.NICID][]tcpip.Subnet{}
for id, nic := range s.nics {
nics[id] = append(nics[id], nic.Subnets()...)
}
return nics
} | [
"func",
"(",
"s",
"*",
"Stack",
")",
"NICSubnets",
"(",
")",
"map",
"[",
"tcpip",
".",
"NICID",
"]",
"[",
"]",
"tcpip",
".",
"Subnet",
"{",
"s",
".",
"mu",
".",
"RLock",
"(",
")",
"\n",
"defer",
"s",
".",
"mu",
".",
"RUnlock",
"(",
")",
"\n\n",
"nics",
":=",
"map",
"[",
"tcpip",
".",
"NICID",
"]",
"[",
"]",
"tcpip",
".",
"Subnet",
"{",
"}",
"\n\n",
"for",
"id",
",",
"nic",
":=",
"range",
"s",
".",
"nics",
"{",
"nics",
"[",
"id",
"]",
"=",
"append",
"(",
"nics",
"[",
"id",
"]",
",",
"nic",
".",
"Subnets",
"(",
")",
"...",
")",
"\n",
"}",
"\n",
"return",
"nics",
"\n",
"}"
] | // NICSubnets returns a map of NICIDs to their associated subnets. | [
"NICSubnets",
"returns",
"a",
"map",
"of",
"NICIDs",
"to",
"their",
"associated",
"subnets",
"."
] | 70ebca9c30730cf3887cdef3b85bb96ed7a97593 | https://github.com/google/netstack/blob/70ebca9c30730cf3887cdef3b85bb96ed7a97593/tcpip/stack/stack.go#L619-L629 | train |
google/netstack | tcpip/stack/stack.go | NICInfo | func (s *Stack) NICInfo() map[tcpip.NICID]NICInfo {
s.mu.RLock()
defer s.mu.RUnlock()
nics := make(map[tcpip.NICID]NICInfo)
for id, nic := range s.nics {
flags := NICStateFlags{
Up: true, // Netstack interfaces are always up.
Running: nic.linkEP.IsAttached(),
Promiscuous: nic.isPromiscuousMode(),
Loopback: nic.linkEP.Capabilities()&CapabilityLoopback != 0,
}
nics[id] = NICInfo{
Name: nic.name,
LinkAddress: nic.linkEP.LinkAddress(),
ProtocolAddresses: nic.Addresses(),
Flags: flags,
MTU: nic.linkEP.MTU(),
Stats: nic.stats,
}
}
return nics
} | go | func (s *Stack) NICInfo() map[tcpip.NICID]NICInfo {
s.mu.RLock()
defer s.mu.RUnlock()
nics := make(map[tcpip.NICID]NICInfo)
for id, nic := range s.nics {
flags := NICStateFlags{
Up: true, // Netstack interfaces are always up.
Running: nic.linkEP.IsAttached(),
Promiscuous: nic.isPromiscuousMode(),
Loopback: nic.linkEP.Capabilities()&CapabilityLoopback != 0,
}
nics[id] = NICInfo{
Name: nic.name,
LinkAddress: nic.linkEP.LinkAddress(),
ProtocolAddresses: nic.Addresses(),
Flags: flags,
MTU: nic.linkEP.MTU(),
Stats: nic.stats,
}
}
return nics
} | [
"func",
"(",
"s",
"*",
"Stack",
")",
"NICInfo",
"(",
")",
"map",
"[",
"tcpip",
".",
"NICID",
"]",
"NICInfo",
"{",
"s",
".",
"mu",
".",
"RLock",
"(",
")",
"\n",
"defer",
"s",
".",
"mu",
".",
"RUnlock",
"(",
")",
"\n\n",
"nics",
":=",
"make",
"(",
"map",
"[",
"tcpip",
".",
"NICID",
"]",
"NICInfo",
")",
"\n",
"for",
"id",
",",
"nic",
":=",
"range",
"s",
".",
"nics",
"{",
"flags",
":=",
"NICStateFlags",
"{",
"Up",
":",
"true",
",",
"// Netstack interfaces are always up.",
"Running",
":",
"nic",
".",
"linkEP",
".",
"IsAttached",
"(",
")",
",",
"Promiscuous",
":",
"nic",
".",
"isPromiscuousMode",
"(",
")",
",",
"Loopback",
":",
"nic",
".",
"linkEP",
".",
"Capabilities",
"(",
")",
"&",
"CapabilityLoopback",
"!=",
"0",
",",
"}",
"\n",
"nics",
"[",
"id",
"]",
"=",
"NICInfo",
"{",
"Name",
":",
"nic",
".",
"name",
",",
"LinkAddress",
":",
"nic",
".",
"linkEP",
".",
"LinkAddress",
"(",
")",
",",
"ProtocolAddresses",
":",
"nic",
".",
"Addresses",
"(",
")",
",",
"Flags",
":",
"flags",
",",
"MTU",
":",
"nic",
".",
"linkEP",
".",
"MTU",
"(",
")",
",",
"Stats",
":",
"nic",
".",
"stats",
",",
"}",
"\n",
"}",
"\n",
"return",
"nics",
"\n",
"}"
] | // NICInfo returns a map of NICIDs to their associated information. | [
"NICInfo",
"returns",
"a",
"map",
"of",
"NICIDs",
"to",
"their",
"associated",
"information",
"."
] | 70ebca9c30730cf3887cdef3b85bb96ed7a97593 | https://github.com/google/netstack/blob/70ebca9c30730cf3887cdef3b85bb96ed7a97593/tcpip/stack/stack.go#L647-L669 | train |
google/netstack | tcpip/stack/stack.go | AddAddress | func (s *Stack) AddAddress(id tcpip.NICID, protocol tcpip.NetworkProtocolNumber, addr tcpip.Address) *tcpip.Error {
return s.AddAddressWithOptions(id, protocol, addr, CanBePrimaryEndpoint)
} | go | func (s *Stack) AddAddress(id tcpip.NICID, protocol tcpip.NetworkProtocolNumber, addr tcpip.Address) *tcpip.Error {
return s.AddAddressWithOptions(id, protocol, addr, CanBePrimaryEndpoint)
} | [
"func",
"(",
"s",
"*",
"Stack",
")",
"AddAddress",
"(",
"id",
"tcpip",
".",
"NICID",
",",
"protocol",
"tcpip",
".",
"NetworkProtocolNumber",
",",
"addr",
"tcpip",
".",
"Address",
")",
"*",
"tcpip",
".",
"Error",
"{",
"return",
"s",
".",
"AddAddressWithOptions",
"(",
"id",
",",
"protocol",
",",
"addr",
",",
"CanBePrimaryEndpoint",
")",
"\n",
"}"
] | // AddAddress adds a new network-layer address to the specified NIC. | [
"AddAddress",
"adds",
"a",
"new",
"network",
"-",
"layer",
"address",
"to",
"the",
"specified",
"NIC",
"."
] | 70ebca9c30730cf3887cdef3b85bb96ed7a97593 | https://github.com/google/netstack/blob/70ebca9c30730cf3887cdef3b85bb96ed7a97593/tcpip/stack/stack.go#L687-L689 | train |
google/netstack | tcpip/stack/stack.go | AddSubnet | func (s *Stack) AddSubnet(id tcpip.NICID, protocol tcpip.NetworkProtocolNumber, subnet tcpip.Subnet) *tcpip.Error {
s.mu.RLock()
defer s.mu.RUnlock()
if nic, ok := s.nics[id]; ok {
nic.AddSubnet(protocol, subnet)
return nil
}
return tcpip.ErrUnknownNICID
} | go | func (s *Stack) AddSubnet(id tcpip.NICID, protocol tcpip.NetworkProtocolNumber, subnet tcpip.Subnet) *tcpip.Error {
s.mu.RLock()
defer s.mu.RUnlock()
if nic, ok := s.nics[id]; ok {
nic.AddSubnet(protocol, subnet)
return nil
}
return tcpip.ErrUnknownNICID
} | [
"func",
"(",
"s",
"*",
"Stack",
")",
"AddSubnet",
"(",
"id",
"tcpip",
".",
"NICID",
",",
"protocol",
"tcpip",
".",
"NetworkProtocolNumber",
",",
"subnet",
"tcpip",
".",
"Subnet",
")",
"*",
"tcpip",
".",
"Error",
"{",
"s",
".",
"mu",
".",
"RLock",
"(",
")",
"\n",
"defer",
"s",
".",
"mu",
".",
"RUnlock",
"(",
")",
"\n\n",
"if",
"nic",
",",
"ok",
":=",
"s",
".",
"nics",
"[",
"id",
"]",
";",
"ok",
"{",
"nic",
".",
"AddSubnet",
"(",
"protocol",
",",
"subnet",
")",
"\n",
"return",
"nil",
"\n",
"}",
"\n\n",
"return",
"tcpip",
".",
"ErrUnknownNICID",
"\n",
"}"
] | // AddSubnet adds a subnet range to the specified NIC. | [
"AddSubnet",
"adds",
"a",
"subnet",
"range",
"to",
"the",
"specified",
"NIC",
"."
] | 70ebca9c30730cf3887cdef3b85bb96ed7a97593 | https://github.com/google/netstack/blob/70ebca9c30730cf3887cdef3b85bb96ed7a97593/tcpip/stack/stack.go#L706-L716 | train |
google/netstack | tcpip/stack/stack.go | RemoveAddress | func (s *Stack) RemoveAddress(id tcpip.NICID, addr tcpip.Address) *tcpip.Error {
s.mu.RLock()
defer s.mu.RUnlock()
if nic, ok := s.nics[id]; ok {
return nic.RemoveAddress(addr)
}
return tcpip.ErrUnknownNICID
} | go | func (s *Stack) RemoveAddress(id tcpip.NICID, addr tcpip.Address) *tcpip.Error {
s.mu.RLock()
defer s.mu.RUnlock()
if nic, ok := s.nics[id]; ok {
return nic.RemoveAddress(addr)
}
return tcpip.ErrUnknownNICID
} | [
"func",
"(",
"s",
"*",
"Stack",
")",
"RemoveAddress",
"(",
"id",
"tcpip",
".",
"NICID",
",",
"addr",
"tcpip",
".",
"Address",
")",
"*",
"tcpip",
".",
"Error",
"{",
"s",
".",
"mu",
".",
"RLock",
"(",
")",
"\n",
"defer",
"s",
".",
"mu",
".",
"RUnlock",
"(",
")",
"\n\n",
"if",
"nic",
",",
"ok",
":=",
"s",
".",
"nics",
"[",
"id",
"]",
";",
"ok",
"{",
"return",
"nic",
".",
"RemoveAddress",
"(",
"addr",
")",
"\n",
"}",
"\n\n",
"return",
"tcpip",
".",
"ErrUnknownNICID",
"\n",
"}"
] | // RemoveAddress removes an existing network-layer address from the specified
// NIC. | [
"RemoveAddress",
"removes",
"an",
"existing",
"network",
"-",
"layer",
"address",
"from",
"the",
"specified",
"NIC",
"."
] | 70ebca9c30730cf3887cdef3b85bb96ed7a97593 | https://github.com/google/netstack/blob/70ebca9c30730cf3887cdef3b85bb96ed7a97593/tcpip/stack/stack.go#L746-L755 | train |
google/netstack | tcpip/stack/stack.go | CheckNetworkProtocol | func (s *Stack) CheckNetworkProtocol(protocol tcpip.NetworkProtocolNumber) bool {
_, ok := s.networkProtocols[protocol]
return ok
} | go | func (s *Stack) CheckNetworkProtocol(protocol tcpip.NetworkProtocolNumber) bool {
_, ok := s.networkProtocols[protocol]
return ok
} | [
"func",
"(",
"s",
"*",
"Stack",
")",
"CheckNetworkProtocol",
"(",
"protocol",
"tcpip",
".",
"NetworkProtocolNumber",
")",
"bool",
"{",
"_",
",",
"ok",
":=",
"s",
".",
"networkProtocols",
"[",
"protocol",
"]",
"\n",
"return",
"ok",
"\n",
"}"
] | // CheckNetworkProtocol checks if a given network protocol is enabled in the
// stack. | [
"CheckNetworkProtocol",
"checks",
"if",
"a",
"given",
"network",
"protocol",
"is",
"enabled",
"in",
"the",
"stack",
"."
] | 70ebca9c30730cf3887cdef3b85bb96ed7a97593 | https://github.com/google/netstack/blob/70ebca9c30730cf3887cdef3b85bb96ed7a97593/tcpip/stack/stack.go#L826-L829 | train |
google/netstack | tcpip/stack/stack.go | CheckLocalAddress | func (s *Stack) CheckLocalAddress(nicid tcpip.NICID, protocol tcpip.NetworkProtocolNumber, addr tcpip.Address) tcpip.NICID {
s.mu.RLock()
defer s.mu.RUnlock()
// If a NIC is specified, we try to find the address there only.
if nicid != 0 {
nic := s.nics[nicid]
if nic == nil {
return 0
}
ref := nic.findEndpoint(protocol, addr, CanBePrimaryEndpoint)
if ref == nil {
return 0
}
ref.decRef()
return nic.id
}
// Go through all the NICs.
for _, nic := range s.nics {
ref := nic.findEndpoint(protocol, addr, CanBePrimaryEndpoint)
if ref != nil {
ref.decRef()
return nic.id
}
}
return 0
} | go | func (s *Stack) CheckLocalAddress(nicid tcpip.NICID, protocol tcpip.NetworkProtocolNumber, addr tcpip.Address) tcpip.NICID {
s.mu.RLock()
defer s.mu.RUnlock()
// If a NIC is specified, we try to find the address there only.
if nicid != 0 {
nic := s.nics[nicid]
if nic == nil {
return 0
}
ref := nic.findEndpoint(protocol, addr, CanBePrimaryEndpoint)
if ref == nil {
return 0
}
ref.decRef()
return nic.id
}
// Go through all the NICs.
for _, nic := range s.nics {
ref := nic.findEndpoint(protocol, addr, CanBePrimaryEndpoint)
if ref != nil {
ref.decRef()
return nic.id
}
}
return 0
} | [
"func",
"(",
"s",
"*",
"Stack",
")",
"CheckLocalAddress",
"(",
"nicid",
"tcpip",
".",
"NICID",
",",
"protocol",
"tcpip",
".",
"NetworkProtocolNumber",
",",
"addr",
"tcpip",
".",
"Address",
")",
"tcpip",
".",
"NICID",
"{",
"s",
".",
"mu",
".",
"RLock",
"(",
")",
"\n",
"defer",
"s",
".",
"mu",
".",
"RUnlock",
"(",
")",
"\n\n",
"// If a NIC is specified, we try to find the address there only.",
"if",
"nicid",
"!=",
"0",
"{",
"nic",
":=",
"s",
".",
"nics",
"[",
"nicid",
"]",
"\n",
"if",
"nic",
"==",
"nil",
"{",
"return",
"0",
"\n",
"}",
"\n\n",
"ref",
":=",
"nic",
".",
"findEndpoint",
"(",
"protocol",
",",
"addr",
",",
"CanBePrimaryEndpoint",
")",
"\n",
"if",
"ref",
"==",
"nil",
"{",
"return",
"0",
"\n",
"}",
"\n\n",
"ref",
".",
"decRef",
"(",
")",
"\n\n",
"return",
"nic",
".",
"id",
"\n",
"}",
"\n\n",
"// Go through all the NICs.",
"for",
"_",
",",
"nic",
":=",
"range",
"s",
".",
"nics",
"{",
"ref",
":=",
"nic",
".",
"findEndpoint",
"(",
"protocol",
",",
"addr",
",",
"CanBePrimaryEndpoint",
")",
"\n",
"if",
"ref",
"!=",
"nil",
"{",
"ref",
".",
"decRef",
"(",
")",
"\n",
"return",
"nic",
".",
"id",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"0",
"\n",
"}"
] | // CheckLocalAddress determines if the given local address exists, and if it
// does, returns the id of the NIC it's bound to. Returns 0 if the address
// does not exist. | [
"CheckLocalAddress",
"determines",
"if",
"the",
"given",
"local",
"address",
"exists",
"and",
"if",
"it",
"does",
"returns",
"the",
"id",
"of",
"the",
"NIC",
"it",
"s",
"bound",
"to",
".",
"Returns",
"0",
"if",
"the",
"address",
"does",
"not",
"exist",
"."
] | 70ebca9c30730cf3887cdef3b85bb96ed7a97593 | https://github.com/google/netstack/blob/70ebca9c30730cf3887cdef3b85bb96ed7a97593/tcpip/stack/stack.go#L834-L865 | train |
google/netstack | tcpip/stack/stack.go | SetPromiscuousMode | func (s *Stack) SetPromiscuousMode(nicID tcpip.NICID, enable bool) *tcpip.Error {
s.mu.RLock()
defer s.mu.RUnlock()
nic := s.nics[nicID]
if nic == nil {
return tcpip.ErrUnknownNICID
}
nic.setPromiscuousMode(enable)
return nil
} | go | func (s *Stack) SetPromiscuousMode(nicID tcpip.NICID, enable bool) *tcpip.Error {
s.mu.RLock()
defer s.mu.RUnlock()
nic := s.nics[nicID]
if nic == nil {
return tcpip.ErrUnknownNICID
}
nic.setPromiscuousMode(enable)
return nil
} | [
"func",
"(",
"s",
"*",
"Stack",
")",
"SetPromiscuousMode",
"(",
"nicID",
"tcpip",
".",
"NICID",
",",
"enable",
"bool",
")",
"*",
"tcpip",
".",
"Error",
"{",
"s",
".",
"mu",
".",
"RLock",
"(",
")",
"\n",
"defer",
"s",
".",
"mu",
".",
"RUnlock",
"(",
")",
"\n\n",
"nic",
":=",
"s",
".",
"nics",
"[",
"nicID",
"]",
"\n",
"if",
"nic",
"==",
"nil",
"{",
"return",
"tcpip",
".",
"ErrUnknownNICID",
"\n",
"}",
"\n\n",
"nic",
".",
"setPromiscuousMode",
"(",
"enable",
")",
"\n\n",
"return",
"nil",
"\n",
"}"
] | // SetPromiscuousMode enables or disables promiscuous mode in the given NIC. | [
"SetPromiscuousMode",
"enables",
"or",
"disables",
"promiscuous",
"mode",
"in",
"the",
"given",
"NIC",
"."
] | 70ebca9c30730cf3887cdef3b85bb96ed7a97593 | https://github.com/google/netstack/blob/70ebca9c30730cf3887cdef3b85bb96ed7a97593/tcpip/stack/stack.go#L868-L880 | train |
google/netstack | tcpip/stack/stack.go | SetSpoofing | func (s *Stack) SetSpoofing(nicID tcpip.NICID, enable bool) *tcpip.Error {
s.mu.RLock()
defer s.mu.RUnlock()
nic := s.nics[nicID]
if nic == nil {
return tcpip.ErrUnknownNICID
}
nic.setSpoofing(enable)
return nil
} | go | func (s *Stack) SetSpoofing(nicID tcpip.NICID, enable bool) *tcpip.Error {
s.mu.RLock()
defer s.mu.RUnlock()
nic := s.nics[nicID]
if nic == nil {
return tcpip.ErrUnknownNICID
}
nic.setSpoofing(enable)
return nil
} | [
"func",
"(",
"s",
"*",
"Stack",
")",
"SetSpoofing",
"(",
"nicID",
"tcpip",
".",
"NICID",
",",
"enable",
"bool",
")",
"*",
"tcpip",
".",
"Error",
"{",
"s",
".",
"mu",
".",
"RLock",
"(",
")",
"\n",
"defer",
"s",
".",
"mu",
".",
"RUnlock",
"(",
")",
"\n\n",
"nic",
":=",
"s",
".",
"nics",
"[",
"nicID",
"]",
"\n",
"if",
"nic",
"==",
"nil",
"{",
"return",
"tcpip",
".",
"ErrUnknownNICID",
"\n",
"}",
"\n\n",
"nic",
".",
"setSpoofing",
"(",
"enable",
")",
"\n\n",
"return",
"nil",
"\n",
"}"
] | // SetSpoofing enables or disables address spoofing in the given NIC, allowing
// endpoints to bind to any address in the NIC. | [
"SetSpoofing",
"enables",
"or",
"disables",
"address",
"spoofing",
"in",
"the",
"given",
"NIC",
"allowing",
"endpoints",
"to",
"bind",
"to",
"any",
"address",
"in",
"the",
"NIC",
"."
] | 70ebca9c30730cf3887cdef3b85bb96ed7a97593 | https://github.com/google/netstack/blob/70ebca9c30730cf3887cdef3b85bb96ed7a97593/tcpip/stack/stack.go#L884-L896 | train |
google/netstack | tcpip/stack/stack.go | AddLinkAddress | func (s *Stack) AddLinkAddress(nicid tcpip.NICID, addr tcpip.Address, linkAddr tcpip.LinkAddress) {
fullAddr := tcpip.FullAddress{NIC: nicid, Addr: addr}
s.linkAddrCache.add(fullAddr, linkAddr)
// TODO: provide a way for a transport endpoint to receive a signal
// that AddLinkAddress for a particular address has been called.
} | go | func (s *Stack) AddLinkAddress(nicid tcpip.NICID, addr tcpip.Address, linkAddr tcpip.LinkAddress) {
fullAddr := tcpip.FullAddress{NIC: nicid, Addr: addr}
s.linkAddrCache.add(fullAddr, linkAddr)
// TODO: provide a way for a transport endpoint to receive a signal
// that AddLinkAddress for a particular address has been called.
} | [
"func",
"(",
"s",
"*",
"Stack",
")",
"AddLinkAddress",
"(",
"nicid",
"tcpip",
".",
"NICID",
",",
"addr",
"tcpip",
".",
"Address",
",",
"linkAddr",
"tcpip",
".",
"LinkAddress",
")",
"{",
"fullAddr",
":=",
"tcpip",
".",
"FullAddress",
"{",
"NIC",
":",
"nicid",
",",
"Addr",
":",
"addr",
"}",
"\n",
"s",
".",
"linkAddrCache",
".",
"add",
"(",
"fullAddr",
",",
"linkAddr",
")",
"\n",
"// TODO: provide a way for a transport endpoint to receive a signal",
"// that AddLinkAddress for a particular address has been called.",
"}"
] | // AddLinkAddress adds a link address to the stack link cache. | [
"AddLinkAddress",
"adds",
"a",
"link",
"address",
"to",
"the",
"stack",
"link",
"cache",
"."
] | 70ebca9c30730cf3887cdef3b85bb96ed7a97593 | https://github.com/google/netstack/blob/70ebca9c30730cf3887cdef3b85bb96ed7a97593/tcpip/stack/stack.go#L899-L904 | train |
google/netstack | tcpip/stack/stack.go | GetLinkAddress | func (s *Stack) GetLinkAddress(nicid tcpip.NICID, addr, localAddr tcpip.Address, protocol tcpip.NetworkProtocolNumber, waker *sleep.Waker) (tcpip.LinkAddress, <-chan struct{}, *tcpip.Error) {
s.mu.RLock()
nic := s.nics[nicid]
if nic == nil {
s.mu.RUnlock()
return "", nil, tcpip.ErrUnknownNICID
}
s.mu.RUnlock()
fullAddr := tcpip.FullAddress{NIC: nicid, Addr: addr}
linkRes := s.linkAddrResolvers[protocol]
return s.linkAddrCache.get(fullAddr, linkRes, localAddr, nic.linkEP, waker)
} | go | func (s *Stack) GetLinkAddress(nicid tcpip.NICID, addr, localAddr tcpip.Address, protocol tcpip.NetworkProtocolNumber, waker *sleep.Waker) (tcpip.LinkAddress, <-chan struct{}, *tcpip.Error) {
s.mu.RLock()
nic := s.nics[nicid]
if nic == nil {
s.mu.RUnlock()
return "", nil, tcpip.ErrUnknownNICID
}
s.mu.RUnlock()
fullAddr := tcpip.FullAddress{NIC: nicid, Addr: addr}
linkRes := s.linkAddrResolvers[protocol]
return s.linkAddrCache.get(fullAddr, linkRes, localAddr, nic.linkEP, waker)
} | [
"func",
"(",
"s",
"*",
"Stack",
")",
"GetLinkAddress",
"(",
"nicid",
"tcpip",
".",
"NICID",
",",
"addr",
",",
"localAddr",
"tcpip",
".",
"Address",
",",
"protocol",
"tcpip",
".",
"NetworkProtocolNumber",
",",
"waker",
"*",
"sleep",
".",
"Waker",
")",
"(",
"tcpip",
".",
"LinkAddress",
",",
"<-",
"chan",
"struct",
"{",
"}",
",",
"*",
"tcpip",
".",
"Error",
")",
"{",
"s",
".",
"mu",
".",
"RLock",
"(",
")",
"\n",
"nic",
":=",
"s",
".",
"nics",
"[",
"nicid",
"]",
"\n",
"if",
"nic",
"==",
"nil",
"{",
"s",
".",
"mu",
".",
"RUnlock",
"(",
")",
"\n",
"return",
"\"",
"\"",
",",
"nil",
",",
"tcpip",
".",
"ErrUnknownNICID",
"\n",
"}",
"\n",
"s",
".",
"mu",
".",
"RUnlock",
"(",
")",
"\n\n",
"fullAddr",
":=",
"tcpip",
".",
"FullAddress",
"{",
"NIC",
":",
"nicid",
",",
"Addr",
":",
"addr",
"}",
"\n",
"linkRes",
":=",
"s",
".",
"linkAddrResolvers",
"[",
"protocol",
"]",
"\n",
"return",
"s",
".",
"linkAddrCache",
".",
"get",
"(",
"fullAddr",
",",
"linkRes",
",",
"localAddr",
",",
"nic",
".",
"linkEP",
",",
"waker",
")",
"\n",
"}"
] | // GetLinkAddress implements LinkAddressCache.GetLinkAddress. | [
"GetLinkAddress",
"implements",
"LinkAddressCache",
".",
"GetLinkAddress",
"."
] | 70ebca9c30730cf3887cdef3b85bb96ed7a97593 | https://github.com/google/netstack/blob/70ebca9c30730cf3887cdef3b85bb96ed7a97593/tcpip/stack/stack.go#L907-L919 | train |
google/netstack | tcpip/stack/stack.go | RemoveWaker | func (s *Stack) RemoveWaker(nicid tcpip.NICID, addr tcpip.Address, waker *sleep.Waker) {
s.mu.RLock()
defer s.mu.RUnlock()
if nic := s.nics[nicid]; nic == nil {
fullAddr := tcpip.FullAddress{NIC: nicid, Addr: addr}
s.linkAddrCache.removeWaker(fullAddr, waker)
}
} | go | func (s *Stack) RemoveWaker(nicid tcpip.NICID, addr tcpip.Address, waker *sleep.Waker) {
s.mu.RLock()
defer s.mu.RUnlock()
if nic := s.nics[nicid]; nic == nil {
fullAddr := tcpip.FullAddress{NIC: nicid, Addr: addr}
s.linkAddrCache.removeWaker(fullAddr, waker)
}
} | [
"func",
"(",
"s",
"*",
"Stack",
")",
"RemoveWaker",
"(",
"nicid",
"tcpip",
".",
"NICID",
",",
"addr",
"tcpip",
".",
"Address",
",",
"waker",
"*",
"sleep",
".",
"Waker",
")",
"{",
"s",
".",
"mu",
".",
"RLock",
"(",
")",
"\n",
"defer",
"s",
".",
"mu",
".",
"RUnlock",
"(",
")",
"\n\n",
"if",
"nic",
":=",
"s",
".",
"nics",
"[",
"nicid",
"]",
";",
"nic",
"==",
"nil",
"{",
"fullAddr",
":=",
"tcpip",
".",
"FullAddress",
"{",
"NIC",
":",
"nicid",
",",
"Addr",
":",
"addr",
"}",
"\n",
"s",
".",
"linkAddrCache",
".",
"removeWaker",
"(",
"fullAddr",
",",
"waker",
")",
"\n",
"}",
"\n",
"}"
] | // RemoveWaker implements LinkAddressCache.RemoveWaker. | [
"RemoveWaker",
"implements",
"LinkAddressCache",
".",
"RemoveWaker",
"."
] | 70ebca9c30730cf3887cdef3b85bb96ed7a97593 | https://github.com/google/netstack/blob/70ebca9c30730cf3887cdef3b85bb96ed7a97593/tcpip/stack/stack.go#L922-L930 | train |
google/netstack | tcpip/stack/stack.go | RegisterTransportEndpoint | func (s *Stack) RegisterTransportEndpoint(nicID tcpip.NICID, netProtos []tcpip.NetworkProtocolNumber, protocol tcpip.TransportProtocolNumber, id TransportEndpointID, ep TransportEndpoint, reusePort bool) *tcpip.Error {
if nicID == 0 {
return s.demux.registerEndpoint(netProtos, protocol, id, ep, reusePort)
}
s.mu.RLock()
defer s.mu.RUnlock()
nic := s.nics[nicID]
if nic == nil {
return tcpip.ErrUnknownNICID
}
return nic.demux.registerEndpoint(netProtos, protocol, id, ep, reusePort)
} | go | func (s *Stack) RegisterTransportEndpoint(nicID tcpip.NICID, netProtos []tcpip.NetworkProtocolNumber, protocol tcpip.TransportProtocolNumber, id TransportEndpointID, ep TransportEndpoint, reusePort bool) *tcpip.Error {
if nicID == 0 {
return s.demux.registerEndpoint(netProtos, protocol, id, ep, reusePort)
}
s.mu.RLock()
defer s.mu.RUnlock()
nic := s.nics[nicID]
if nic == nil {
return tcpip.ErrUnknownNICID
}
return nic.demux.registerEndpoint(netProtos, protocol, id, ep, reusePort)
} | [
"func",
"(",
"s",
"*",
"Stack",
")",
"RegisterTransportEndpoint",
"(",
"nicID",
"tcpip",
".",
"NICID",
",",
"netProtos",
"[",
"]",
"tcpip",
".",
"NetworkProtocolNumber",
",",
"protocol",
"tcpip",
".",
"TransportProtocolNumber",
",",
"id",
"TransportEndpointID",
",",
"ep",
"TransportEndpoint",
",",
"reusePort",
"bool",
")",
"*",
"tcpip",
".",
"Error",
"{",
"if",
"nicID",
"==",
"0",
"{",
"return",
"s",
".",
"demux",
".",
"registerEndpoint",
"(",
"netProtos",
",",
"protocol",
",",
"id",
",",
"ep",
",",
"reusePort",
")",
"\n",
"}",
"\n\n",
"s",
".",
"mu",
".",
"RLock",
"(",
")",
"\n",
"defer",
"s",
".",
"mu",
".",
"RUnlock",
"(",
")",
"\n\n",
"nic",
":=",
"s",
".",
"nics",
"[",
"nicID",
"]",
"\n",
"if",
"nic",
"==",
"nil",
"{",
"return",
"tcpip",
".",
"ErrUnknownNICID",
"\n",
"}",
"\n\n",
"return",
"nic",
".",
"demux",
".",
"registerEndpoint",
"(",
"netProtos",
",",
"protocol",
",",
"id",
",",
"ep",
",",
"reusePort",
")",
"\n",
"}"
] | // RegisterTransportEndpoint registers the given endpoint with the stack
// transport dispatcher. Received packets that match the provided id will be
// delivered to the given endpoint; specifying a nic is optional, but
// nic-specific IDs have precedence over global ones. | [
"RegisterTransportEndpoint",
"registers",
"the",
"given",
"endpoint",
"with",
"the",
"stack",
"transport",
"dispatcher",
".",
"Received",
"packets",
"that",
"match",
"the",
"provided",
"id",
"will",
"be",
"delivered",
"to",
"the",
"given",
"endpoint",
";",
"specifying",
"a",
"nic",
"is",
"optional",
"but",
"nic",
"-",
"specific",
"IDs",
"have",
"precedence",
"over",
"global",
"ones",
"."
] | 70ebca9c30730cf3887cdef3b85bb96ed7a97593 | https://github.com/google/netstack/blob/70ebca9c30730cf3887cdef3b85bb96ed7a97593/tcpip/stack/stack.go#L936-L950 | train |
google/netstack | tcpip/stack/stack.go | UnregisterTransportEndpoint | func (s *Stack) UnregisterTransportEndpoint(nicID tcpip.NICID, netProtos []tcpip.NetworkProtocolNumber, protocol tcpip.TransportProtocolNumber, id TransportEndpointID, ep TransportEndpoint) {
if nicID == 0 {
s.demux.unregisterEndpoint(netProtos, protocol, id, ep)
return
}
s.mu.RLock()
defer s.mu.RUnlock()
nic := s.nics[nicID]
if nic != nil {
nic.demux.unregisterEndpoint(netProtos, protocol, id, ep)
}
} | go | func (s *Stack) UnregisterTransportEndpoint(nicID tcpip.NICID, netProtos []tcpip.NetworkProtocolNumber, protocol tcpip.TransportProtocolNumber, id TransportEndpointID, ep TransportEndpoint) {
if nicID == 0 {
s.demux.unregisterEndpoint(netProtos, protocol, id, ep)
return
}
s.mu.RLock()
defer s.mu.RUnlock()
nic := s.nics[nicID]
if nic != nil {
nic.demux.unregisterEndpoint(netProtos, protocol, id, ep)
}
} | [
"func",
"(",
"s",
"*",
"Stack",
")",
"UnregisterTransportEndpoint",
"(",
"nicID",
"tcpip",
".",
"NICID",
",",
"netProtos",
"[",
"]",
"tcpip",
".",
"NetworkProtocolNumber",
",",
"protocol",
"tcpip",
".",
"TransportProtocolNumber",
",",
"id",
"TransportEndpointID",
",",
"ep",
"TransportEndpoint",
")",
"{",
"if",
"nicID",
"==",
"0",
"{",
"s",
".",
"demux",
".",
"unregisterEndpoint",
"(",
"netProtos",
",",
"protocol",
",",
"id",
",",
"ep",
")",
"\n",
"return",
"\n",
"}",
"\n\n",
"s",
".",
"mu",
".",
"RLock",
"(",
")",
"\n",
"defer",
"s",
".",
"mu",
".",
"RUnlock",
"(",
")",
"\n\n",
"nic",
":=",
"s",
".",
"nics",
"[",
"nicID",
"]",
"\n",
"if",
"nic",
"!=",
"nil",
"{",
"nic",
".",
"demux",
".",
"unregisterEndpoint",
"(",
"netProtos",
",",
"protocol",
",",
"id",
",",
"ep",
")",
"\n",
"}",
"\n",
"}"
] | // UnregisterTransportEndpoint removes the endpoint with the given id from the
// stack transport dispatcher. | [
"UnregisterTransportEndpoint",
"removes",
"the",
"endpoint",
"with",
"the",
"given",
"id",
"from",
"the",
"stack",
"transport",
"dispatcher",
"."
] | 70ebca9c30730cf3887cdef3b85bb96ed7a97593 | https://github.com/google/netstack/blob/70ebca9c30730cf3887cdef3b85bb96ed7a97593/tcpip/stack/stack.go#L954-L967 | train |
google/netstack | tcpip/stack/stack.go | RegisterRawTransportEndpoint | func (s *Stack) RegisterRawTransportEndpoint(nicID tcpip.NICID, netProto tcpip.NetworkProtocolNumber, transProto tcpip.TransportProtocolNumber, ep RawTransportEndpoint) *tcpip.Error {
if nicID == 0 {
return s.demux.registerRawEndpoint(netProto, transProto, ep)
}
s.mu.RLock()
defer s.mu.RUnlock()
nic := s.nics[nicID]
if nic == nil {
return tcpip.ErrUnknownNICID
}
return nic.demux.registerRawEndpoint(netProto, transProto, ep)
} | go | func (s *Stack) RegisterRawTransportEndpoint(nicID tcpip.NICID, netProto tcpip.NetworkProtocolNumber, transProto tcpip.TransportProtocolNumber, ep RawTransportEndpoint) *tcpip.Error {
if nicID == 0 {
return s.demux.registerRawEndpoint(netProto, transProto, ep)
}
s.mu.RLock()
defer s.mu.RUnlock()
nic := s.nics[nicID]
if nic == nil {
return tcpip.ErrUnknownNICID
}
return nic.demux.registerRawEndpoint(netProto, transProto, ep)
} | [
"func",
"(",
"s",
"*",
"Stack",
")",
"RegisterRawTransportEndpoint",
"(",
"nicID",
"tcpip",
".",
"NICID",
",",
"netProto",
"tcpip",
".",
"NetworkProtocolNumber",
",",
"transProto",
"tcpip",
".",
"TransportProtocolNumber",
",",
"ep",
"RawTransportEndpoint",
")",
"*",
"tcpip",
".",
"Error",
"{",
"if",
"nicID",
"==",
"0",
"{",
"return",
"s",
".",
"demux",
".",
"registerRawEndpoint",
"(",
"netProto",
",",
"transProto",
",",
"ep",
")",
"\n",
"}",
"\n\n",
"s",
".",
"mu",
".",
"RLock",
"(",
")",
"\n",
"defer",
"s",
".",
"mu",
".",
"RUnlock",
"(",
")",
"\n\n",
"nic",
":=",
"s",
".",
"nics",
"[",
"nicID",
"]",
"\n",
"if",
"nic",
"==",
"nil",
"{",
"return",
"tcpip",
".",
"ErrUnknownNICID",
"\n",
"}",
"\n\n",
"return",
"nic",
".",
"demux",
".",
"registerRawEndpoint",
"(",
"netProto",
",",
"transProto",
",",
"ep",
")",
"\n",
"}"
] | // RegisterRawTransportEndpoint registers the given endpoint with the stack
// transport dispatcher. Received packets that match the provided transport
// protocol will be delivered to the given endpoint. | [
"RegisterRawTransportEndpoint",
"registers",
"the",
"given",
"endpoint",
"with",
"the",
"stack",
"transport",
"dispatcher",
".",
"Received",
"packets",
"that",
"match",
"the",
"provided",
"transport",
"protocol",
"will",
"be",
"delivered",
"to",
"the",
"given",
"endpoint",
"."
] | 70ebca9c30730cf3887cdef3b85bb96ed7a97593 | https://github.com/google/netstack/blob/70ebca9c30730cf3887cdef3b85bb96ed7a97593/tcpip/stack/stack.go#L972-L986 | train |
google/netstack | tcpip/stack/stack.go | UnregisterRawTransportEndpoint | func (s *Stack) UnregisterRawTransportEndpoint(nicID tcpip.NICID, netProto tcpip.NetworkProtocolNumber, transProto tcpip.TransportProtocolNumber, ep RawTransportEndpoint) {
if nicID == 0 {
s.demux.unregisterRawEndpoint(netProto, transProto, ep)
return
}
s.mu.RLock()
defer s.mu.RUnlock()
nic := s.nics[nicID]
if nic != nil {
nic.demux.unregisterRawEndpoint(netProto, transProto, ep)
}
} | go | func (s *Stack) UnregisterRawTransportEndpoint(nicID tcpip.NICID, netProto tcpip.NetworkProtocolNumber, transProto tcpip.TransportProtocolNumber, ep RawTransportEndpoint) {
if nicID == 0 {
s.demux.unregisterRawEndpoint(netProto, transProto, ep)
return
}
s.mu.RLock()
defer s.mu.RUnlock()
nic := s.nics[nicID]
if nic != nil {
nic.demux.unregisterRawEndpoint(netProto, transProto, ep)
}
} | [
"func",
"(",
"s",
"*",
"Stack",
")",
"UnregisterRawTransportEndpoint",
"(",
"nicID",
"tcpip",
".",
"NICID",
",",
"netProto",
"tcpip",
".",
"NetworkProtocolNumber",
",",
"transProto",
"tcpip",
".",
"TransportProtocolNumber",
",",
"ep",
"RawTransportEndpoint",
")",
"{",
"if",
"nicID",
"==",
"0",
"{",
"s",
".",
"demux",
".",
"unregisterRawEndpoint",
"(",
"netProto",
",",
"transProto",
",",
"ep",
")",
"\n",
"return",
"\n",
"}",
"\n\n",
"s",
".",
"mu",
".",
"RLock",
"(",
")",
"\n",
"defer",
"s",
".",
"mu",
".",
"RUnlock",
"(",
")",
"\n\n",
"nic",
":=",
"s",
".",
"nics",
"[",
"nicID",
"]",
"\n",
"if",
"nic",
"!=",
"nil",
"{",
"nic",
".",
"demux",
".",
"unregisterRawEndpoint",
"(",
"netProto",
",",
"transProto",
",",
"ep",
")",
"\n",
"}",
"\n",
"}"
] | // UnregisterRawTransportEndpoint removes the endpoint for the transport
// protocol from the stack transport dispatcher. | [
"UnregisterRawTransportEndpoint",
"removes",
"the",
"endpoint",
"for",
"the",
"transport",
"protocol",
"from",
"the",
"stack",
"transport",
"dispatcher",
"."
] | 70ebca9c30730cf3887cdef3b85bb96ed7a97593 | https://github.com/google/netstack/blob/70ebca9c30730cf3887cdef3b85bb96ed7a97593/tcpip/stack/stack.go#L990-L1003 | train |
google/netstack | tcpip/stack/stack.go | NetworkProtocolInstance | func (s *Stack) NetworkProtocolInstance(num tcpip.NetworkProtocolNumber) NetworkProtocol {
if p, ok := s.networkProtocols[num]; ok {
return p
}
return nil
} | go | func (s *Stack) NetworkProtocolInstance(num tcpip.NetworkProtocolNumber) NetworkProtocol {
if p, ok := s.networkProtocols[num]; ok {
return p
}
return nil
} | [
"func",
"(",
"s",
"*",
"Stack",
")",
"NetworkProtocolInstance",
"(",
"num",
"tcpip",
".",
"NetworkProtocolNumber",
")",
"NetworkProtocol",
"{",
"if",
"p",
",",
"ok",
":=",
"s",
".",
"networkProtocols",
"[",
"num",
"]",
";",
"ok",
"{",
"return",
"p",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // NetworkProtocolInstance returns the protocol instance in the stack for the
// specified network protocol. This method is public for protocol implementers
// and tests to use. | [
"NetworkProtocolInstance",
"returns",
"the",
"protocol",
"instance",
"in",
"the",
"stack",
"for",
"the",
"specified",
"network",
"protocol",
".",
"This",
"method",
"is",
"public",
"for",
"protocol",
"implementers",
"and",
"tests",
"to",
"use",
"."
] | 70ebca9c30730cf3887cdef3b85bb96ed7a97593 | https://github.com/google/netstack/blob/70ebca9c30730cf3887cdef3b85bb96ed7a97593/tcpip/stack/stack.go#L1008-L1013 | train |
google/netstack | tcpip/stack/stack.go | TransportProtocolInstance | func (s *Stack) TransportProtocolInstance(num tcpip.TransportProtocolNumber) TransportProtocol {
if pState, ok := s.transportProtocols[num]; ok {
return pState.proto
}
return nil
} | go | func (s *Stack) TransportProtocolInstance(num tcpip.TransportProtocolNumber) TransportProtocol {
if pState, ok := s.transportProtocols[num]; ok {
return pState.proto
}
return nil
} | [
"func",
"(",
"s",
"*",
"Stack",
")",
"TransportProtocolInstance",
"(",
"num",
"tcpip",
".",
"TransportProtocolNumber",
")",
"TransportProtocol",
"{",
"if",
"pState",
",",
"ok",
":=",
"s",
".",
"transportProtocols",
"[",
"num",
"]",
";",
"ok",
"{",
"return",
"pState",
".",
"proto",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // TransportProtocolInstance returns the protocol instance in the stack for the
// specified transport protocol. This method is public for protocol implementers
// and tests to use. | [
"TransportProtocolInstance",
"returns",
"the",
"protocol",
"instance",
"in",
"the",
"stack",
"for",
"the",
"specified",
"transport",
"protocol",
".",
"This",
"method",
"is",
"public",
"for",
"protocol",
"implementers",
"and",
"tests",
"to",
"use",
"."
] | 70ebca9c30730cf3887cdef3b85bb96ed7a97593 | https://github.com/google/netstack/blob/70ebca9c30730cf3887cdef3b85bb96ed7a97593/tcpip/stack/stack.go#L1018-L1023 | train |
google/netstack | tcpip/stack/stack.go | GetTCPProbe | func (s *Stack) GetTCPProbe() TCPProbeFunc {
s.mu.Lock()
p := s.tcpProbeFunc
s.mu.Unlock()
return p
} | go | func (s *Stack) GetTCPProbe() TCPProbeFunc {
s.mu.Lock()
p := s.tcpProbeFunc
s.mu.Unlock()
return p
} | [
"func",
"(",
"s",
"*",
"Stack",
")",
"GetTCPProbe",
"(",
")",
"TCPProbeFunc",
"{",
"s",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"p",
":=",
"s",
".",
"tcpProbeFunc",
"\n",
"s",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n",
"return",
"p",
"\n",
"}"
] | // GetTCPProbe returns the TCPProbeFunc if installed with AddTCPProbe, nil
// otherwise. | [
"GetTCPProbe",
"returns",
"the",
"TCPProbeFunc",
"if",
"installed",
"with",
"AddTCPProbe",
"nil",
"otherwise",
"."
] | 70ebca9c30730cf3887cdef3b85bb96ed7a97593 | https://github.com/google/netstack/blob/70ebca9c30730cf3887cdef3b85bb96ed7a97593/tcpip/stack/stack.go#L1044-L1049 | train |
google/netstack | tcpip/stack/stack.go | JoinGroup | func (s *Stack) JoinGroup(protocol tcpip.NetworkProtocolNumber, nicID tcpip.NICID, multicastAddr tcpip.Address) *tcpip.Error {
// TODO: notify network of subscription via igmp protocol.
return s.AddAddressWithOptions(nicID, protocol, multicastAddr, NeverPrimaryEndpoint)
} | go | func (s *Stack) JoinGroup(protocol tcpip.NetworkProtocolNumber, nicID tcpip.NICID, multicastAddr tcpip.Address) *tcpip.Error {
// TODO: notify network of subscription via igmp protocol.
return s.AddAddressWithOptions(nicID, protocol, multicastAddr, NeverPrimaryEndpoint)
} | [
"func",
"(",
"s",
"*",
"Stack",
")",
"JoinGroup",
"(",
"protocol",
"tcpip",
".",
"NetworkProtocolNumber",
",",
"nicID",
"tcpip",
".",
"NICID",
",",
"multicastAddr",
"tcpip",
".",
"Address",
")",
"*",
"tcpip",
".",
"Error",
"{",
"// TODO: notify network of subscription via igmp protocol.",
"return",
"s",
".",
"AddAddressWithOptions",
"(",
"nicID",
",",
"protocol",
",",
"multicastAddr",
",",
"NeverPrimaryEndpoint",
")",
"\n",
"}"
] | // JoinGroup joins the given multicast group on the given NIC. | [
"JoinGroup",
"joins",
"the",
"given",
"multicast",
"group",
"on",
"the",
"given",
"NIC",
"."
] | 70ebca9c30730cf3887cdef3b85bb96ed7a97593 | https://github.com/google/netstack/blob/70ebca9c30730cf3887cdef3b85bb96ed7a97593/tcpip/stack/stack.go#L1063-L1066 | train |
google/netstack | tcpip/stack/stack.go | LeaveGroup | func (s *Stack) LeaveGroup(protocol tcpip.NetworkProtocolNumber, nicID tcpip.NICID, multicastAddr tcpip.Address) *tcpip.Error {
return s.RemoveAddress(nicID, multicastAddr)
} | go | func (s *Stack) LeaveGroup(protocol tcpip.NetworkProtocolNumber, nicID tcpip.NICID, multicastAddr tcpip.Address) *tcpip.Error {
return s.RemoveAddress(nicID, multicastAddr)
} | [
"func",
"(",
"s",
"*",
"Stack",
")",
"LeaveGroup",
"(",
"protocol",
"tcpip",
".",
"NetworkProtocolNumber",
",",
"nicID",
"tcpip",
".",
"NICID",
",",
"multicastAddr",
"tcpip",
".",
"Address",
")",
"*",
"tcpip",
".",
"Error",
"{",
"return",
"s",
".",
"RemoveAddress",
"(",
"nicID",
",",
"multicastAddr",
")",
"\n",
"}"
] | // LeaveGroup leaves the given multicast group on the given NIC. | [
"LeaveGroup",
"leaves",
"the",
"given",
"multicast",
"group",
"on",
"the",
"given",
"NIC",
"."
] | 70ebca9c30730cf3887cdef3b85bb96ed7a97593 | https://github.com/google/netstack/blob/70ebca9c30730cf3887cdef3b85bb96ed7a97593/tcpip/stack/stack.go#L1069-L1071 | train |
google/netstack | tcpip/transport/udp/forwarder.go | NewForwarder | func NewForwarder(s *stack.Stack, handler func(*ForwarderRequest)) *Forwarder {
return &Forwarder{
stack: s,
handler: handler,
}
} | go | func NewForwarder(s *stack.Stack, handler func(*ForwarderRequest)) *Forwarder {
return &Forwarder{
stack: s,
handler: handler,
}
} | [
"func",
"NewForwarder",
"(",
"s",
"*",
"stack",
".",
"Stack",
",",
"handler",
"func",
"(",
"*",
"ForwarderRequest",
")",
")",
"*",
"Forwarder",
"{",
"return",
"&",
"Forwarder",
"{",
"stack",
":",
"s",
",",
"handler",
":",
"handler",
",",
"}",
"\n",
"}"
] | // NewForwarder allocates and initializes a new forwarder. | [
"NewForwarder",
"allocates",
"and",
"initializes",
"a",
"new",
"forwarder",
"."
] | 70ebca9c30730cf3887cdef3b85bb96ed7a97593 | https://github.com/google/netstack/blob/70ebca9c30730cf3887cdef3b85bb96ed7a97593/tcpip/transport/udp/forwarder.go#L36-L41 | train |
google/netstack | tcpip/transport/udp/forwarder.go | HandlePacket | func (f *Forwarder) HandlePacket(r *stack.Route, id stack.TransportEndpointID, netHeader buffer.View, vv buffer.VectorisedView) bool {
f.handler(&ForwarderRequest{
stack: f.stack,
route: r,
id: id,
vv: vv,
})
return true
} | go | func (f *Forwarder) HandlePacket(r *stack.Route, id stack.TransportEndpointID, netHeader buffer.View, vv buffer.VectorisedView) bool {
f.handler(&ForwarderRequest{
stack: f.stack,
route: r,
id: id,
vv: vv,
})
return true
} | [
"func",
"(",
"f",
"*",
"Forwarder",
")",
"HandlePacket",
"(",
"r",
"*",
"stack",
".",
"Route",
",",
"id",
"stack",
".",
"TransportEndpointID",
",",
"netHeader",
"buffer",
".",
"View",
",",
"vv",
"buffer",
".",
"VectorisedView",
")",
"bool",
"{",
"f",
".",
"handler",
"(",
"&",
"ForwarderRequest",
"{",
"stack",
":",
"f",
".",
"stack",
",",
"route",
":",
"r",
",",
"id",
":",
"id",
",",
"vv",
":",
"vv",
",",
"}",
")",
"\n\n",
"return",
"true",
"\n",
"}"
] | // HandlePacket handles all packets.
//
// This function is expected to be passed as an argument to the
// stack.SetTransportProtocolHandler function. | [
"HandlePacket",
"handles",
"all",
"packets",
".",
"This",
"function",
"is",
"expected",
"to",
"be",
"passed",
"as",
"an",
"argument",
"to",
"the",
"stack",
".",
"SetTransportProtocolHandler",
"function",
"."
] | 70ebca9c30730cf3887cdef3b85bb96ed7a97593 | https://github.com/google/netstack/blob/70ebca9c30730cf3887cdef3b85bb96ed7a97593/tcpip/transport/udp/forwarder.go#L47-L56 | train |
google/netstack | tcpip/transport/udp/forwarder.go | CreateEndpoint | func (r *ForwarderRequest) CreateEndpoint(queue *waiter.Queue) (tcpip.Endpoint, *tcpip.Error) {
ep := newEndpoint(r.stack, r.route.NetProto, queue)
if err := r.stack.RegisterTransportEndpoint(r.route.NICID(), []tcpip.NetworkProtocolNumber{r.route.NetProto}, ProtocolNumber, r.id, ep, ep.reusePort); err != nil {
ep.Close()
return nil, err
}
ep.id = r.id
ep.route = r.route.Clone()
ep.dstPort = r.id.RemotePort
ep.regNICID = r.route.NICID()
ep.state = stateConnected
ep.rcvMu.Lock()
ep.rcvReady = true
ep.rcvMu.Unlock()
ep.HandlePacket(r.route, r.id, r.vv)
return ep, nil
} | go | func (r *ForwarderRequest) CreateEndpoint(queue *waiter.Queue) (tcpip.Endpoint, *tcpip.Error) {
ep := newEndpoint(r.stack, r.route.NetProto, queue)
if err := r.stack.RegisterTransportEndpoint(r.route.NICID(), []tcpip.NetworkProtocolNumber{r.route.NetProto}, ProtocolNumber, r.id, ep, ep.reusePort); err != nil {
ep.Close()
return nil, err
}
ep.id = r.id
ep.route = r.route.Clone()
ep.dstPort = r.id.RemotePort
ep.regNICID = r.route.NICID()
ep.state = stateConnected
ep.rcvMu.Lock()
ep.rcvReady = true
ep.rcvMu.Unlock()
ep.HandlePacket(r.route, r.id, r.vv)
return ep, nil
} | [
"func",
"(",
"r",
"*",
"ForwarderRequest",
")",
"CreateEndpoint",
"(",
"queue",
"*",
"waiter",
".",
"Queue",
")",
"(",
"tcpip",
".",
"Endpoint",
",",
"*",
"tcpip",
".",
"Error",
")",
"{",
"ep",
":=",
"newEndpoint",
"(",
"r",
".",
"stack",
",",
"r",
".",
"route",
".",
"NetProto",
",",
"queue",
")",
"\n",
"if",
"err",
":=",
"r",
".",
"stack",
".",
"RegisterTransportEndpoint",
"(",
"r",
".",
"route",
".",
"NICID",
"(",
")",
",",
"[",
"]",
"tcpip",
".",
"NetworkProtocolNumber",
"{",
"r",
".",
"route",
".",
"NetProto",
"}",
",",
"ProtocolNumber",
",",
"r",
".",
"id",
",",
"ep",
",",
"ep",
".",
"reusePort",
")",
";",
"err",
"!=",
"nil",
"{",
"ep",
".",
"Close",
"(",
")",
"\n",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"ep",
".",
"id",
"=",
"r",
".",
"id",
"\n",
"ep",
".",
"route",
"=",
"r",
".",
"route",
".",
"Clone",
"(",
")",
"\n",
"ep",
".",
"dstPort",
"=",
"r",
".",
"id",
".",
"RemotePort",
"\n",
"ep",
".",
"regNICID",
"=",
"r",
".",
"route",
".",
"NICID",
"(",
")",
"\n\n",
"ep",
".",
"state",
"=",
"stateConnected",
"\n\n",
"ep",
".",
"rcvMu",
".",
"Lock",
"(",
")",
"\n",
"ep",
".",
"rcvReady",
"=",
"true",
"\n",
"ep",
".",
"rcvMu",
".",
"Unlock",
"(",
")",
"\n\n",
"ep",
".",
"HandlePacket",
"(",
"r",
".",
"route",
",",
"r",
".",
"id",
",",
"r",
".",
"vv",
")",
"\n\n",
"return",
"ep",
",",
"nil",
"\n",
"}"
] | // CreateEndpoint creates a connected UDP endpoint for the session request. | [
"CreateEndpoint",
"creates",
"a",
"connected",
"UDP",
"endpoint",
"for",
"the",
"session",
"request",
"."
] | 70ebca9c30730cf3887cdef3b85bb96ed7a97593 | https://github.com/google/netstack/blob/70ebca9c30730cf3887cdef3b85bb96ed7a97593/tcpip/transport/udp/forwarder.go#L75-L96 | train |
google/netstack | tcpip/network/fragmentation/reassembler_list.go | PushBack | func (l *reassemblerList) PushBack(e *reassembler) {
reassemblerElementMapper{}.linkerFor(e).SetNext(nil)
reassemblerElementMapper{}.linkerFor(e).SetPrev(l.tail)
if l.tail != nil {
reassemblerElementMapper{}.linkerFor(l.tail).SetNext(e)
} else {
l.head = e
}
l.tail = e
} | go | func (l *reassemblerList) PushBack(e *reassembler) {
reassemblerElementMapper{}.linkerFor(e).SetNext(nil)
reassemblerElementMapper{}.linkerFor(e).SetPrev(l.tail)
if l.tail != nil {
reassemblerElementMapper{}.linkerFor(l.tail).SetNext(e)
} else {
l.head = e
}
l.tail = e
} | [
"func",
"(",
"l",
"*",
"reassemblerList",
")",
"PushBack",
"(",
"e",
"*",
"reassembler",
")",
"{",
"reassemblerElementMapper",
"{",
"}",
".",
"linkerFor",
"(",
"e",
")",
".",
"SetNext",
"(",
"nil",
")",
"\n",
"reassemblerElementMapper",
"{",
"}",
".",
"linkerFor",
"(",
"e",
")",
".",
"SetPrev",
"(",
"l",
".",
"tail",
")",
"\n\n",
"if",
"l",
".",
"tail",
"!=",
"nil",
"{",
"reassemblerElementMapper",
"{",
"}",
".",
"linkerFor",
"(",
"l",
".",
"tail",
")",
".",
"SetNext",
"(",
"e",
")",
"\n",
"}",
"else",
"{",
"l",
".",
"head",
"=",
"e",
"\n",
"}",
"\n\n",
"l",
".",
"tail",
"=",
"e",
"\n",
"}"
] | // PushBack inserts the element e at the back of list l. | [
"PushBack",
"inserts",
"the",
"element",
"e",
"at",
"the",
"back",
"of",
"list",
"l",
"."
] | 70ebca9c30730cf3887cdef3b85bb96ed7a97593 | https://github.com/google/netstack/blob/70ebca9c30730cf3887cdef3b85bb96ed7a97593/tcpip/network/fragmentation/reassembler_list.go#L70-L81 | train |
google/netstack | tcpip/stack/linkaddrcache.go | add | func (c *linkAddrCache) add(k tcpip.FullAddress, v tcpip.LinkAddress) {
c.mu.Lock()
defer c.mu.Unlock()
entry, ok := c.cache[k]
if ok {
s := entry.state()
if s != expired && entry.linkAddr == v {
// Disregard repeated calls.
return
}
// Check if entry is waiting for address resolution.
if s == incomplete {
entry.linkAddr = v
} else {
// Otherwise create a new entry to replace it.
entry = c.makeAndAddEntry(k, v)
}
} else {
entry = c.makeAndAddEntry(k, v)
}
entry.changeState(ready)
} | go | func (c *linkAddrCache) add(k tcpip.FullAddress, v tcpip.LinkAddress) {
c.mu.Lock()
defer c.mu.Unlock()
entry, ok := c.cache[k]
if ok {
s := entry.state()
if s != expired && entry.linkAddr == v {
// Disregard repeated calls.
return
}
// Check if entry is waiting for address resolution.
if s == incomplete {
entry.linkAddr = v
} else {
// Otherwise create a new entry to replace it.
entry = c.makeAndAddEntry(k, v)
}
} else {
entry = c.makeAndAddEntry(k, v)
}
entry.changeState(ready)
} | [
"func",
"(",
"c",
"*",
"linkAddrCache",
")",
"add",
"(",
"k",
"tcpip",
".",
"FullAddress",
",",
"v",
"tcpip",
".",
"LinkAddress",
")",
"{",
"c",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"c",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n\n",
"entry",
",",
"ok",
":=",
"c",
".",
"cache",
"[",
"k",
"]",
"\n",
"if",
"ok",
"{",
"s",
":=",
"entry",
".",
"state",
"(",
")",
"\n",
"if",
"s",
"!=",
"expired",
"&&",
"entry",
".",
"linkAddr",
"==",
"v",
"{",
"// Disregard repeated calls.",
"return",
"\n",
"}",
"\n",
"// Check if entry is waiting for address resolution.",
"if",
"s",
"==",
"incomplete",
"{",
"entry",
".",
"linkAddr",
"=",
"v",
"\n",
"}",
"else",
"{",
"// Otherwise create a new entry to replace it.",
"entry",
"=",
"c",
".",
"makeAndAddEntry",
"(",
"k",
",",
"v",
")",
"\n",
"}",
"\n",
"}",
"else",
"{",
"entry",
"=",
"c",
".",
"makeAndAddEntry",
"(",
"k",
",",
"v",
")",
"\n",
"}",
"\n\n",
"entry",
".",
"changeState",
"(",
"ready",
")",
"\n",
"}"
] | // add adds a k -> v mapping to the cache. | [
"add",
"adds",
"a",
"k",
"-",
">",
"v",
"mapping",
"to",
"the",
"cache",
"."
] | 70ebca9c30730cf3887cdef3b85bb96ed7a97593 | https://github.com/google/netstack/blob/70ebca9c30730cf3887cdef3b85bb96ed7a97593/tcpip/stack/linkaddrcache.go#L150-L173 | train |
google/netstack | tcpip/stack/linkaddrcache.go | makeAndAddEntry | func (c *linkAddrCache) makeAndAddEntry(k tcpip.FullAddress, v tcpip.LinkAddress) *linkAddrEntry {
// Take over the next entry.
entry := &c.entries[c.next]
if c.cache[entry.addr] == entry {
delete(c.cache, entry.addr)
}
// Mark the soon-to-be-replaced entry as expired, just in case there is
// someone waiting for address resolution on it.
entry.changeState(expired)
*entry = linkAddrEntry{
addr: k,
linkAddr: v,
expiration: time.Now().Add(c.ageLimit),
wakers: make(map[*sleep.Waker]struct{}),
done: make(chan struct{}),
}
c.cache[k] = entry
c.next = (c.next + 1) % len(c.entries)
return entry
} | go | func (c *linkAddrCache) makeAndAddEntry(k tcpip.FullAddress, v tcpip.LinkAddress) *linkAddrEntry {
// Take over the next entry.
entry := &c.entries[c.next]
if c.cache[entry.addr] == entry {
delete(c.cache, entry.addr)
}
// Mark the soon-to-be-replaced entry as expired, just in case there is
// someone waiting for address resolution on it.
entry.changeState(expired)
*entry = linkAddrEntry{
addr: k,
linkAddr: v,
expiration: time.Now().Add(c.ageLimit),
wakers: make(map[*sleep.Waker]struct{}),
done: make(chan struct{}),
}
c.cache[k] = entry
c.next = (c.next + 1) % len(c.entries)
return entry
} | [
"func",
"(",
"c",
"*",
"linkAddrCache",
")",
"makeAndAddEntry",
"(",
"k",
"tcpip",
".",
"FullAddress",
",",
"v",
"tcpip",
".",
"LinkAddress",
")",
"*",
"linkAddrEntry",
"{",
"// Take over the next entry.",
"entry",
":=",
"&",
"c",
".",
"entries",
"[",
"c",
".",
"next",
"]",
"\n",
"if",
"c",
".",
"cache",
"[",
"entry",
".",
"addr",
"]",
"==",
"entry",
"{",
"delete",
"(",
"c",
".",
"cache",
",",
"entry",
".",
"addr",
")",
"\n",
"}",
"\n\n",
"// Mark the soon-to-be-replaced entry as expired, just in case there is",
"// someone waiting for address resolution on it.",
"entry",
".",
"changeState",
"(",
"expired",
")",
"\n\n",
"*",
"entry",
"=",
"linkAddrEntry",
"{",
"addr",
":",
"k",
",",
"linkAddr",
":",
"v",
",",
"expiration",
":",
"time",
".",
"Now",
"(",
")",
".",
"Add",
"(",
"c",
".",
"ageLimit",
")",
",",
"wakers",
":",
"make",
"(",
"map",
"[",
"*",
"sleep",
".",
"Waker",
"]",
"struct",
"{",
"}",
")",
",",
"done",
":",
"make",
"(",
"chan",
"struct",
"{",
"}",
")",
",",
"}",
"\n\n",
"c",
".",
"cache",
"[",
"k",
"]",
"=",
"entry",
"\n",
"c",
".",
"next",
"=",
"(",
"c",
".",
"next",
"+",
"1",
")",
"%",
"len",
"(",
"c",
".",
"entries",
")",
"\n",
"return",
"entry",
"\n",
"}"
] | // makeAndAddEntry is a helper function to create and add a new
// entry to the cache map and evict older entry as needed. | [
"makeAndAddEntry",
"is",
"a",
"helper",
"function",
"to",
"create",
"and",
"add",
"a",
"new",
"entry",
"to",
"the",
"cache",
"map",
"and",
"evict",
"older",
"entry",
"as",
"needed",
"."
] | 70ebca9c30730cf3887cdef3b85bb96ed7a97593 | https://github.com/google/netstack/blob/70ebca9c30730cf3887cdef3b85bb96ed7a97593/tcpip/stack/linkaddrcache.go#L177-L199 | train |
google/netstack | tcpip/stack/linkaddrcache.go | get | func (c *linkAddrCache) get(k tcpip.FullAddress, linkRes LinkAddressResolver, localAddr tcpip.Address, linkEP LinkEndpoint, waker *sleep.Waker) (tcpip.LinkAddress, <-chan struct{}, *tcpip.Error) {
if linkRes != nil {
if addr, ok := linkRes.ResolveStaticAddress(k.Addr); ok {
return addr, nil, nil
}
}
c.mu.Lock()
defer c.mu.Unlock()
if entry, ok := c.cache[k]; ok {
switch s := entry.state(); s {
case expired:
case ready:
return entry.linkAddr, nil, nil
case failed:
return "", nil, tcpip.ErrNoLinkAddress
case incomplete:
// Address resolution is still in progress.
entry.addWaker(waker)
return "", entry.done, tcpip.ErrWouldBlock
default:
panic(fmt.Sprintf("invalid cache entry state: %s", s))
}
}
if linkRes == nil {
return "", nil, tcpip.ErrNoLinkAddress
}
// Add 'incomplete' entry in the cache to mark that resolution is in progress.
e := c.makeAndAddEntry(k, "")
e.addWaker(waker)
go c.startAddressResolution(k, linkRes, localAddr, linkEP, e.done)
return "", e.done, tcpip.ErrWouldBlock
} | go | func (c *linkAddrCache) get(k tcpip.FullAddress, linkRes LinkAddressResolver, localAddr tcpip.Address, linkEP LinkEndpoint, waker *sleep.Waker) (tcpip.LinkAddress, <-chan struct{}, *tcpip.Error) {
if linkRes != nil {
if addr, ok := linkRes.ResolveStaticAddress(k.Addr); ok {
return addr, nil, nil
}
}
c.mu.Lock()
defer c.mu.Unlock()
if entry, ok := c.cache[k]; ok {
switch s := entry.state(); s {
case expired:
case ready:
return entry.linkAddr, nil, nil
case failed:
return "", nil, tcpip.ErrNoLinkAddress
case incomplete:
// Address resolution is still in progress.
entry.addWaker(waker)
return "", entry.done, tcpip.ErrWouldBlock
default:
panic(fmt.Sprintf("invalid cache entry state: %s", s))
}
}
if linkRes == nil {
return "", nil, tcpip.ErrNoLinkAddress
}
// Add 'incomplete' entry in the cache to mark that resolution is in progress.
e := c.makeAndAddEntry(k, "")
e.addWaker(waker)
go c.startAddressResolution(k, linkRes, localAddr, linkEP, e.done)
return "", e.done, tcpip.ErrWouldBlock
} | [
"func",
"(",
"c",
"*",
"linkAddrCache",
")",
"get",
"(",
"k",
"tcpip",
".",
"FullAddress",
",",
"linkRes",
"LinkAddressResolver",
",",
"localAddr",
"tcpip",
".",
"Address",
",",
"linkEP",
"LinkEndpoint",
",",
"waker",
"*",
"sleep",
".",
"Waker",
")",
"(",
"tcpip",
".",
"LinkAddress",
",",
"<-",
"chan",
"struct",
"{",
"}",
",",
"*",
"tcpip",
".",
"Error",
")",
"{",
"if",
"linkRes",
"!=",
"nil",
"{",
"if",
"addr",
",",
"ok",
":=",
"linkRes",
".",
"ResolveStaticAddress",
"(",
"k",
".",
"Addr",
")",
";",
"ok",
"{",
"return",
"addr",
",",
"nil",
",",
"nil",
"\n",
"}",
"\n",
"}",
"\n\n",
"c",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"c",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n",
"if",
"entry",
",",
"ok",
":=",
"c",
".",
"cache",
"[",
"k",
"]",
";",
"ok",
"{",
"switch",
"s",
":=",
"entry",
".",
"state",
"(",
")",
";",
"s",
"{",
"case",
"expired",
":",
"case",
"ready",
":",
"return",
"entry",
".",
"linkAddr",
",",
"nil",
",",
"nil",
"\n",
"case",
"failed",
":",
"return",
"\"",
"\"",
",",
"nil",
",",
"tcpip",
".",
"ErrNoLinkAddress",
"\n",
"case",
"incomplete",
":",
"// Address resolution is still in progress.",
"entry",
".",
"addWaker",
"(",
"waker",
")",
"\n",
"return",
"\"",
"\"",
",",
"entry",
".",
"done",
",",
"tcpip",
".",
"ErrWouldBlock",
"\n",
"default",
":",
"panic",
"(",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"s",
")",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"if",
"linkRes",
"==",
"nil",
"{",
"return",
"\"",
"\"",
",",
"nil",
",",
"tcpip",
".",
"ErrNoLinkAddress",
"\n",
"}",
"\n\n",
"// Add 'incomplete' entry in the cache to mark that resolution is in progress.",
"e",
":=",
"c",
".",
"makeAndAddEntry",
"(",
"k",
",",
"\"",
"\"",
")",
"\n",
"e",
".",
"addWaker",
"(",
"waker",
")",
"\n\n",
"go",
"c",
".",
"startAddressResolution",
"(",
"k",
",",
"linkRes",
",",
"localAddr",
",",
"linkEP",
",",
"e",
".",
"done",
")",
"\n\n",
"return",
"\"",
"\"",
",",
"e",
".",
"done",
",",
"tcpip",
".",
"ErrWouldBlock",
"\n",
"}"
] | // get reports any known link address for k. | [
"get",
"reports",
"any",
"known",
"link",
"address",
"for",
"k",
"."
] | 70ebca9c30730cf3887cdef3b85bb96ed7a97593 | https://github.com/google/netstack/blob/70ebca9c30730cf3887cdef3b85bb96ed7a97593/tcpip/stack/linkaddrcache.go#L202-L238 | train |
google/netstack | tcpip/link/channel/channel.go | New | func New(size int, mtu uint32, linkAddr tcpip.LinkAddress) (tcpip.LinkEndpointID, *Endpoint) {
e := &Endpoint{
C: make(chan PacketInfo, size),
mtu: mtu,
linkAddr: linkAddr,
}
return stack.RegisterLinkEndpoint(e), e
} | go | func New(size int, mtu uint32, linkAddr tcpip.LinkAddress) (tcpip.LinkEndpointID, *Endpoint) {
e := &Endpoint{
C: make(chan PacketInfo, size),
mtu: mtu,
linkAddr: linkAddr,
}
return stack.RegisterLinkEndpoint(e), e
} | [
"func",
"New",
"(",
"size",
"int",
",",
"mtu",
"uint32",
",",
"linkAddr",
"tcpip",
".",
"LinkAddress",
")",
"(",
"tcpip",
".",
"LinkEndpointID",
",",
"*",
"Endpoint",
")",
"{",
"e",
":=",
"&",
"Endpoint",
"{",
"C",
":",
"make",
"(",
"chan",
"PacketInfo",
",",
"size",
")",
",",
"mtu",
":",
"mtu",
",",
"linkAddr",
":",
"linkAddr",
",",
"}",
"\n\n",
"return",
"stack",
".",
"RegisterLinkEndpoint",
"(",
"e",
")",
",",
"e",
"\n",
"}"
] | // New creates a new channel endpoint. | [
"New",
"creates",
"a",
"new",
"channel",
"endpoint",
"."
] | 70ebca9c30730cf3887cdef3b85bb96ed7a97593 | https://github.com/google/netstack/blob/70ebca9c30730cf3887cdef3b85bb96ed7a97593/tcpip/link/channel/channel.go#L47-L55 | train |
google/netstack | tcpip/link/channel/channel.go | InjectLinkAddr | func (e *Endpoint) InjectLinkAddr(protocol tcpip.NetworkProtocolNumber, remote tcpip.LinkAddress, vv buffer.VectorisedView) {
e.dispatcher.DeliverNetworkPacket(e, remote, "" /* local */, protocol, vv.Clone(nil))
} | go | func (e *Endpoint) InjectLinkAddr(protocol tcpip.NetworkProtocolNumber, remote tcpip.LinkAddress, vv buffer.VectorisedView) {
e.dispatcher.DeliverNetworkPacket(e, remote, "" /* local */, protocol, vv.Clone(nil))
} | [
"func",
"(",
"e",
"*",
"Endpoint",
")",
"InjectLinkAddr",
"(",
"protocol",
"tcpip",
".",
"NetworkProtocolNumber",
",",
"remote",
"tcpip",
".",
"LinkAddress",
",",
"vv",
"buffer",
".",
"VectorisedView",
")",
"{",
"e",
".",
"dispatcher",
".",
"DeliverNetworkPacket",
"(",
"e",
",",
"remote",
",",
"\"",
"\"",
"/* local */",
",",
"protocol",
",",
"vv",
".",
"Clone",
"(",
"nil",
")",
")",
"\n",
"}"
] | // InjectLinkAddr injects an inbound packet with a remote link address. | [
"InjectLinkAddr",
"injects",
"an",
"inbound",
"packet",
"with",
"a",
"remote",
"link",
"address",
"."
] | 70ebca9c30730cf3887cdef3b85bb96ed7a97593 | https://github.com/google/netstack/blob/70ebca9c30730cf3887cdef3b85bb96ed7a97593/tcpip/link/channel/channel.go#L76-L78 | train |
google/netstack | tcpip/link/channel/channel.go | Capabilities | func (e *Endpoint) Capabilities() stack.LinkEndpointCapabilities {
caps := stack.LinkEndpointCapabilities(0)
if e.GSO {
caps |= stack.CapabilityGSO
}
return caps
} | go | func (e *Endpoint) Capabilities() stack.LinkEndpointCapabilities {
caps := stack.LinkEndpointCapabilities(0)
if e.GSO {
caps |= stack.CapabilityGSO
}
return caps
} | [
"func",
"(",
"e",
"*",
"Endpoint",
")",
"Capabilities",
"(",
")",
"stack",
".",
"LinkEndpointCapabilities",
"{",
"caps",
":=",
"stack",
".",
"LinkEndpointCapabilities",
"(",
"0",
")",
"\n",
"if",
"e",
".",
"GSO",
"{",
"caps",
"|=",
"stack",
".",
"CapabilityGSO",
"\n",
"}",
"\n",
"return",
"caps",
"\n",
"}"
] | // Capabilities implements stack.LinkEndpoint.Capabilities. | [
"Capabilities",
"implements",
"stack",
".",
"LinkEndpoint",
".",
"Capabilities",
"."
] | 70ebca9c30730cf3887cdef3b85bb96ed7a97593 | https://github.com/google/netstack/blob/70ebca9c30730cf3887cdef3b85bb96ed7a97593/tcpip/link/channel/channel.go#L98-L104 | train |
google/netstack | tcpip/link/channel/channel.go | WritePacket | func (e *Endpoint) WritePacket(_ *stack.Route, gso *stack.GSO, hdr buffer.Prependable, payload buffer.VectorisedView, protocol tcpip.NetworkProtocolNumber) *tcpip.Error {
p := PacketInfo{
Header: hdr.View(),
Proto: protocol,
Payload: payload.ToView(),
GSO: gso,
}
select {
case e.C <- p:
default:
}
return nil
} | go | func (e *Endpoint) WritePacket(_ *stack.Route, gso *stack.GSO, hdr buffer.Prependable, payload buffer.VectorisedView, protocol tcpip.NetworkProtocolNumber) *tcpip.Error {
p := PacketInfo{
Header: hdr.View(),
Proto: protocol,
Payload: payload.ToView(),
GSO: gso,
}
select {
case e.C <- p:
default:
}
return nil
} | [
"func",
"(",
"e",
"*",
"Endpoint",
")",
"WritePacket",
"(",
"_",
"*",
"stack",
".",
"Route",
",",
"gso",
"*",
"stack",
".",
"GSO",
",",
"hdr",
"buffer",
".",
"Prependable",
",",
"payload",
"buffer",
".",
"VectorisedView",
",",
"protocol",
"tcpip",
".",
"NetworkProtocolNumber",
")",
"*",
"tcpip",
".",
"Error",
"{",
"p",
":=",
"PacketInfo",
"{",
"Header",
":",
"hdr",
".",
"View",
"(",
")",
",",
"Proto",
":",
"protocol",
",",
"Payload",
":",
"payload",
".",
"ToView",
"(",
")",
",",
"GSO",
":",
"gso",
",",
"}",
"\n\n",
"select",
"{",
"case",
"e",
".",
"C",
"<-",
"p",
":",
"default",
":",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] | // WritePacket stores outbound packets into the channel. | [
"WritePacket",
"stores",
"outbound",
"packets",
"into",
"the",
"channel",
"."
] | 70ebca9c30730cf3887cdef3b85bb96ed7a97593 | https://github.com/google/netstack/blob/70ebca9c30730cf3887cdef3b85bb96ed7a97593/tcpip/link/channel/channel.go#L123-L137 | train |
google/netstack | tcpip/adapters/gonet/gonet.go | Shutdown | func (l *Listener) Shutdown() {
l.ep.Shutdown(tcpip.ShutdownWrite | tcpip.ShutdownRead)
close(l.cancel) // broadcast cancellation
} | go | func (l *Listener) Shutdown() {
l.ep.Shutdown(tcpip.ShutdownWrite | tcpip.ShutdownRead)
close(l.cancel) // broadcast cancellation
} | [
"func",
"(",
"l",
"*",
"Listener",
")",
"Shutdown",
"(",
")",
"{",
"l",
".",
"ep",
".",
"Shutdown",
"(",
"tcpip",
".",
"ShutdownWrite",
"|",
"tcpip",
".",
"ShutdownRead",
")",
"\n",
"close",
"(",
"l",
".",
"cancel",
")",
"// broadcast cancellation",
"\n",
"}"
] | // Shutdown stops the HTTP server. | [
"Shutdown",
"stops",
"the",
"HTTP",
"server",
"."
] | 70ebca9c30730cf3887cdef3b85bb96ed7a97593 | https://github.com/google/netstack/blob/70ebca9c30730cf3887cdef3b85bb96ed7a97593/tcpip/adapters/gonet/gonet.go#L98-L101 | train |
google/netstack | tcpip/adapters/gonet/gonet.go | Addr | func (l *Listener) Addr() net.Addr {
a, err := l.ep.GetLocalAddress()
if err != nil {
return nil
}
return fullToTCPAddr(a)
} | go | func (l *Listener) Addr() net.Addr {
a, err := l.ep.GetLocalAddress()
if err != nil {
return nil
}
return fullToTCPAddr(a)
} | [
"func",
"(",
"l",
"*",
"Listener",
")",
"Addr",
"(",
")",
"net",
".",
"Addr",
"{",
"a",
",",
"err",
":=",
"l",
".",
"ep",
".",
"GetLocalAddress",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"return",
"fullToTCPAddr",
"(",
"a",
")",
"\n",
"}"
] | // Addr implements net.Listener.Addr. | [
"Addr",
"implements",
"net",
".",
"Listener",
".",
"Addr",
"."
] | 70ebca9c30730cf3887cdef3b85bb96ed7a97593 | https://github.com/google/netstack/blob/70ebca9c30730cf3887cdef3b85bb96ed7a97593/tcpip/adapters/gonet/gonet.go#L104-L110 | train |
google/netstack | tcpip/adapters/gonet/gonet.go | setDeadline | func (d *deadlineTimer) setDeadline(cancelCh *chan struct{}, timer **time.Timer, t time.Time) {
if *timer != nil && !(*timer).Stop() {
*cancelCh = make(chan struct{})
}
// Create a new channel if we already closed it due to setting an already
// expired time. We won't race with the timer because we already handled
// that above.
select {
case <-*cancelCh:
*cancelCh = make(chan struct{})
default:
}
// "A zero value for t means I/O operations will not time out."
// - net.Conn.SetDeadline
if t.IsZero() {
return
}
timeout := t.Sub(time.Now())
if timeout <= 0 {
close(*cancelCh)
return
}
// Timer.Stop returns whether or not the AfterFunc has started, but
// does not indicate whether or not it has completed. Make a copy of
// the cancel channel to prevent this code from racing with the next
// call of setDeadline replacing *cancelCh.
ch := *cancelCh
*timer = time.AfterFunc(timeout, func() {
close(ch)
})
} | go | func (d *deadlineTimer) setDeadline(cancelCh *chan struct{}, timer **time.Timer, t time.Time) {
if *timer != nil && !(*timer).Stop() {
*cancelCh = make(chan struct{})
}
// Create a new channel if we already closed it due to setting an already
// expired time. We won't race with the timer because we already handled
// that above.
select {
case <-*cancelCh:
*cancelCh = make(chan struct{})
default:
}
// "A zero value for t means I/O operations will not time out."
// - net.Conn.SetDeadline
if t.IsZero() {
return
}
timeout := t.Sub(time.Now())
if timeout <= 0 {
close(*cancelCh)
return
}
// Timer.Stop returns whether or not the AfterFunc has started, but
// does not indicate whether or not it has completed. Make a copy of
// the cancel channel to prevent this code from racing with the next
// call of setDeadline replacing *cancelCh.
ch := *cancelCh
*timer = time.AfterFunc(timeout, func() {
close(ch)
})
} | [
"func",
"(",
"d",
"*",
"deadlineTimer",
")",
"setDeadline",
"(",
"cancelCh",
"*",
"chan",
"struct",
"{",
"}",
",",
"timer",
"*",
"*",
"time",
".",
"Timer",
",",
"t",
"time",
".",
"Time",
")",
"{",
"if",
"*",
"timer",
"!=",
"nil",
"&&",
"!",
"(",
"*",
"timer",
")",
".",
"Stop",
"(",
")",
"{",
"*",
"cancelCh",
"=",
"make",
"(",
"chan",
"struct",
"{",
"}",
")",
"\n",
"}",
"\n\n",
"// Create a new channel if we already closed it due to setting an already",
"// expired time. We won't race with the timer because we already handled",
"// that above.",
"select",
"{",
"case",
"<-",
"*",
"cancelCh",
":",
"*",
"cancelCh",
"=",
"make",
"(",
"chan",
"struct",
"{",
"}",
")",
"\n",
"default",
":",
"}",
"\n\n",
"// \"A zero value for t means I/O operations will not time out.\"",
"// - net.Conn.SetDeadline",
"if",
"t",
".",
"IsZero",
"(",
")",
"{",
"return",
"\n",
"}",
"\n\n",
"timeout",
":=",
"t",
".",
"Sub",
"(",
"time",
".",
"Now",
"(",
")",
")",
"\n",
"if",
"timeout",
"<=",
"0",
"{",
"close",
"(",
"*",
"cancelCh",
")",
"\n",
"return",
"\n",
"}",
"\n\n",
"// Timer.Stop returns whether or not the AfterFunc has started, but",
"// does not indicate whether or not it has completed. Make a copy of",
"// the cancel channel to prevent this code from racing with the next",
"// call of setDeadline replacing *cancelCh.",
"ch",
":=",
"*",
"cancelCh",
"\n",
"*",
"timer",
"=",
"time",
".",
"AfterFunc",
"(",
"timeout",
",",
"func",
"(",
")",
"{",
"close",
"(",
"ch",
")",
"\n",
"}",
")",
"\n",
"}"
] | // setDeadline contains the shared logic for setting a deadline.
//
// cancelCh and timer must be pointers to deadlineTimer.readCancelCh and
// deadlineTimer.readTimer or deadlineTimer.writeCancelCh and
// deadlineTimer.writeTimer.
//
// setDeadline must only be called while holding d.mu. | [
"setDeadline",
"contains",
"the",
"shared",
"logic",
"for",
"setting",
"a",
"deadline",
".",
"cancelCh",
"and",
"timer",
"must",
"be",
"pointers",
"to",
"deadlineTimer",
".",
"readCancelCh",
"and",
"deadlineTimer",
".",
"readTimer",
"or",
"deadlineTimer",
".",
"writeCancelCh",
"and",
"deadlineTimer",
".",
"writeTimer",
".",
"setDeadline",
"must",
"only",
"be",
"called",
"while",
"holding",
"d",
".",
"mu",
"."
] | 70ebca9c30730cf3887cdef3b85bb96ed7a97593 | https://github.com/google/netstack/blob/70ebca9c30730cf3887cdef3b85bb96ed7a97593/tcpip/adapters/gonet/gonet.go#L147-L181 | train |
google/netstack | tcpip/adapters/gonet/gonet.go | SetReadDeadline | func (d *deadlineTimer) SetReadDeadline(t time.Time) error {
d.mu.Lock()
d.setDeadline(&d.readCancelCh, &d.readTimer, t)
d.mu.Unlock()
return nil
} | go | func (d *deadlineTimer) SetReadDeadline(t time.Time) error {
d.mu.Lock()
d.setDeadline(&d.readCancelCh, &d.readTimer, t)
d.mu.Unlock()
return nil
} | [
"func",
"(",
"d",
"*",
"deadlineTimer",
")",
"SetReadDeadline",
"(",
"t",
"time",
".",
"Time",
")",
"error",
"{",
"d",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"d",
".",
"setDeadline",
"(",
"&",
"d",
".",
"readCancelCh",
",",
"&",
"d",
".",
"readTimer",
",",
"t",
")",
"\n",
"d",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n",
"return",
"nil",
"\n",
"}"
] | // SetReadDeadline implements net.Conn.SetReadDeadline and
// net.PacketConn.SetReadDeadline. | [
"SetReadDeadline",
"implements",
"net",
".",
"Conn",
".",
"SetReadDeadline",
"and",
"net",
".",
"PacketConn",
".",
"SetReadDeadline",
"."
] | 70ebca9c30730cf3887cdef3b85bb96ed7a97593 | https://github.com/google/netstack/blob/70ebca9c30730cf3887cdef3b85bb96ed7a97593/tcpip/adapters/gonet/gonet.go#L185-L190 | train |
google/netstack | tcpip/adapters/gonet/gonet.go | SetWriteDeadline | func (d *deadlineTimer) SetWriteDeadline(t time.Time) error {
d.mu.Lock()
d.setDeadline(&d.writeCancelCh, &d.writeTimer, t)
d.mu.Unlock()
return nil
} | go | func (d *deadlineTimer) SetWriteDeadline(t time.Time) error {
d.mu.Lock()
d.setDeadline(&d.writeCancelCh, &d.writeTimer, t)
d.mu.Unlock()
return nil
} | [
"func",
"(",
"d",
"*",
"deadlineTimer",
")",
"SetWriteDeadline",
"(",
"t",
"time",
".",
"Time",
")",
"error",
"{",
"d",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"d",
".",
"setDeadline",
"(",
"&",
"d",
".",
"writeCancelCh",
",",
"&",
"d",
".",
"writeTimer",
",",
"t",
")",
"\n",
"d",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n",
"return",
"nil",
"\n",
"}"
] | // SetWriteDeadline implements net.Conn.SetWriteDeadline and
// net.PacketConn.SetWriteDeadline. | [
"SetWriteDeadline",
"implements",
"net",
".",
"Conn",
".",
"SetWriteDeadline",
"and",
"net",
".",
"PacketConn",
".",
"SetWriteDeadline",
"."
] | 70ebca9c30730cf3887cdef3b85bb96ed7a97593 | https://github.com/google/netstack/blob/70ebca9c30730cf3887cdef3b85bb96ed7a97593/tcpip/adapters/gonet/gonet.go#L194-L199 | train |
google/netstack | tcpip/adapters/gonet/gonet.go | SetDeadline | func (d *deadlineTimer) SetDeadline(t time.Time) error {
d.mu.Lock()
d.setDeadline(&d.readCancelCh, &d.readTimer, t)
d.setDeadline(&d.writeCancelCh, &d.writeTimer, t)
d.mu.Unlock()
return nil
} | go | func (d *deadlineTimer) SetDeadline(t time.Time) error {
d.mu.Lock()
d.setDeadline(&d.readCancelCh, &d.readTimer, t)
d.setDeadline(&d.writeCancelCh, &d.writeTimer, t)
d.mu.Unlock()
return nil
} | [
"func",
"(",
"d",
"*",
"deadlineTimer",
")",
"SetDeadline",
"(",
"t",
"time",
".",
"Time",
")",
"error",
"{",
"d",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"d",
".",
"setDeadline",
"(",
"&",
"d",
".",
"readCancelCh",
",",
"&",
"d",
".",
"readTimer",
",",
"t",
")",
"\n",
"d",
".",
"setDeadline",
"(",
"&",
"d",
".",
"writeCancelCh",
",",
"&",
"d",
".",
"writeTimer",
",",
"t",
")",
"\n",
"d",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n",
"return",
"nil",
"\n",
"}"
] | // SetDeadline implements net.Conn.SetDeadline and net.PacketConn.SetDeadline. | [
"SetDeadline",
"implements",
"net",
".",
"Conn",
".",
"SetDeadline",
"and",
"net",
".",
"PacketConn",
".",
"SetDeadline",
"."
] | 70ebca9c30730cf3887cdef3b85bb96ed7a97593 | https://github.com/google/netstack/blob/70ebca9c30730cf3887cdef3b85bb96ed7a97593/tcpip/adapters/gonet/gonet.go#L202-L208 | train |
google/netstack | tcpip/adapters/gonet/gonet.go | NewConn | func NewConn(wq *waiter.Queue, ep tcpip.Endpoint) *Conn {
c := &Conn{
wq: wq,
ep: ep,
}
c.deadlineTimer.init()
return c
} | go | func NewConn(wq *waiter.Queue, ep tcpip.Endpoint) *Conn {
c := &Conn{
wq: wq,
ep: ep,
}
c.deadlineTimer.init()
return c
} | [
"func",
"NewConn",
"(",
"wq",
"*",
"waiter",
".",
"Queue",
",",
"ep",
"tcpip",
".",
"Endpoint",
")",
"*",
"Conn",
"{",
"c",
":=",
"&",
"Conn",
"{",
"wq",
":",
"wq",
",",
"ep",
":",
"ep",
",",
"}",
"\n",
"c",
".",
"deadlineTimer",
".",
"init",
"(",
")",
"\n",
"return",
"c",
"\n",
"}"
] | // NewConn creates a new Conn. | [
"NewConn",
"creates",
"a",
"new",
"Conn",
"."
] | 70ebca9c30730cf3887cdef3b85bb96ed7a97593 | https://github.com/google/netstack/blob/70ebca9c30730cf3887cdef3b85bb96ed7a97593/tcpip/adapters/gonet/gonet.go#L231-L238 | train |
google/netstack | tcpip/adapters/gonet/gonet.go | Accept | func (l *Listener) Accept() (net.Conn, error) {
n, wq, err := l.ep.Accept()
if err == tcpip.ErrWouldBlock {
// Create wait queue entry that notifies a channel.
waitEntry, notifyCh := waiter.NewChannelEntry(nil)
l.wq.EventRegister(&waitEntry, waiter.EventIn)
defer l.wq.EventUnregister(&waitEntry)
for {
n, wq, err = l.ep.Accept()
if err != tcpip.ErrWouldBlock {
break
}
select {
case <-l.cancel:
return nil, errCanceled
case <-notifyCh:
}
}
}
if err != nil {
return nil, &net.OpError{
Op: "accept",
Net: "tcp",
Addr: l.Addr(),
Err: errors.New(err.String()),
}
}
return NewConn(wq, n), nil
} | go | func (l *Listener) Accept() (net.Conn, error) {
n, wq, err := l.ep.Accept()
if err == tcpip.ErrWouldBlock {
// Create wait queue entry that notifies a channel.
waitEntry, notifyCh := waiter.NewChannelEntry(nil)
l.wq.EventRegister(&waitEntry, waiter.EventIn)
defer l.wq.EventUnregister(&waitEntry)
for {
n, wq, err = l.ep.Accept()
if err != tcpip.ErrWouldBlock {
break
}
select {
case <-l.cancel:
return nil, errCanceled
case <-notifyCh:
}
}
}
if err != nil {
return nil, &net.OpError{
Op: "accept",
Net: "tcp",
Addr: l.Addr(),
Err: errors.New(err.String()),
}
}
return NewConn(wq, n), nil
} | [
"func",
"(",
"l",
"*",
"Listener",
")",
"Accept",
"(",
")",
"(",
"net",
".",
"Conn",
",",
"error",
")",
"{",
"n",
",",
"wq",
",",
"err",
":=",
"l",
".",
"ep",
".",
"Accept",
"(",
")",
"\n\n",
"if",
"err",
"==",
"tcpip",
".",
"ErrWouldBlock",
"{",
"// Create wait queue entry that notifies a channel.",
"waitEntry",
",",
"notifyCh",
":=",
"waiter",
".",
"NewChannelEntry",
"(",
"nil",
")",
"\n",
"l",
".",
"wq",
".",
"EventRegister",
"(",
"&",
"waitEntry",
",",
"waiter",
".",
"EventIn",
")",
"\n",
"defer",
"l",
".",
"wq",
".",
"EventUnregister",
"(",
"&",
"waitEntry",
")",
"\n\n",
"for",
"{",
"n",
",",
"wq",
",",
"err",
"=",
"l",
".",
"ep",
".",
"Accept",
"(",
")",
"\n\n",
"if",
"err",
"!=",
"tcpip",
".",
"ErrWouldBlock",
"{",
"break",
"\n",
"}",
"\n\n",
"select",
"{",
"case",
"<-",
"l",
".",
"cancel",
":",
"return",
"nil",
",",
"errCanceled",
"\n",
"case",
"<-",
"notifyCh",
":",
"}",
"\n",
"}",
"\n",
"}",
"\n\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"&",
"net",
".",
"OpError",
"{",
"Op",
":",
"\"",
"\"",
",",
"Net",
":",
"\"",
"\"",
",",
"Addr",
":",
"l",
".",
"Addr",
"(",
")",
",",
"Err",
":",
"errors",
".",
"New",
"(",
"err",
".",
"String",
"(",
")",
")",
",",
"}",
"\n",
"}",
"\n\n",
"return",
"NewConn",
"(",
"wq",
",",
"n",
")",
",",
"nil",
"\n",
"}"
] | // Accept implements net.Conn.Accept. | [
"Accept",
"implements",
"net",
".",
"Conn",
".",
"Accept",
"."
] | 70ebca9c30730cf3887cdef3b85bb96ed7a97593 | https://github.com/google/netstack/blob/70ebca9c30730cf3887cdef3b85bb96ed7a97593/tcpip/adapters/gonet/gonet.go#L241-L275 | train |
google/netstack | tcpip/adapters/gonet/gonet.go | commonRead | func commonRead(ep tcpip.Endpoint, wq *waiter.Queue, deadline <-chan struct{}, addr *tcpip.FullAddress, errorer opErrorer, dontWait bool) ([]byte, error) {
select {
case <-deadline:
return nil, errorer.newOpError("read", &timeoutError{})
default:
}
read, _, err := ep.Read(addr)
if err == tcpip.ErrWouldBlock {
if dontWait {
return nil, errWouldBlock
}
// Create wait queue entry that notifies a channel.
waitEntry, notifyCh := waiter.NewChannelEntry(nil)
wq.EventRegister(&waitEntry, waiter.EventIn)
defer wq.EventUnregister(&waitEntry)
for {
read, _, err = ep.Read(addr)
if err != tcpip.ErrWouldBlock {
break
}
select {
case <-deadline:
return nil, errorer.newOpError("read", &timeoutError{})
case <-notifyCh:
}
}
}
if err == tcpip.ErrClosedForReceive {
return nil, io.EOF
}
if err != nil {
return nil, errorer.newOpError("read", errors.New(err.String()))
}
return read, nil
} | go | func commonRead(ep tcpip.Endpoint, wq *waiter.Queue, deadline <-chan struct{}, addr *tcpip.FullAddress, errorer opErrorer, dontWait bool) ([]byte, error) {
select {
case <-deadline:
return nil, errorer.newOpError("read", &timeoutError{})
default:
}
read, _, err := ep.Read(addr)
if err == tcpip.ErrWouldBlock {
if dontWait {
return nil, errWouldBlock
}
// Create wait queue entry that notifies a channel.
waitEntry, notifyCh := waiter.NewChannelEntry(nil)
wq.EventRegister(&waitEntry, waiter.EventIn)
defer wq.EventUnregister(&waitEntry)
for {
read, _, err = ep.Read(addr)
if err != tcpip.ErrWouldBlock {
break
}
select {
case <-deadline:
return nil, errorer.newOpError("read", &timeoutError{})
case <-notifyCh:
}
}
}
if err == tcpip.ErrClosedForReceive {
return nil, io.EOF
}
if err != nil {
return nil, errorer.newOpError("read", errors.New(err.String()))
}
return read, nil
} | [
"func",
"commonRead",
"(",
"ep",
"tcpip",
".",
"Endpoint",
",",
"wq",
"*",
"waiter",
".",
"Queue",
",",
"deadline",
"<-",
"chan",
"struct",
"{",
"}",
",",
"addr",
"*",
"tcpip",
".",
"FullAddress",
",",
"errorer",
"opErrorer",
",",
"dontWait",
"bool",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"select",
"{",
"case",
"<-",
"deadline",
":",
"return",
"nil",
",",
"errorer",
".",
"newOpError",
"(",
"\"",
"\"",
",",
"&",
"timeoutError",
"{",
"}",
")",
"\n",
"default",
":",
"}",
"\n\n",
"read",
",",
"_",
",",
"err",
":=",
"ep",
".",
"Read",
"(",
"addr",
")",
"\n\n",
"if",
"err",
"==",
"tcpip",
".",
"ErrWouldBlock",
"{",
"if",
"dontWait",
"{",
"return",
"nil",
",",
"errWouldBlock",
"\n",
"}",
"\n",
"// Create wait queue entry that notifies a channel.",
"waitEntry",
",",
"notifyCh",
":=",
"waiter",
".",
"NewChannelEntry",
"(",
"nil",
")",
"\n",
"wq",
".",
"EventRegister",
"(",
"&",
"waitEntry",
",",
"waiter",
".",
"EventIn",
")",
"\n",
"defer",
"wq",
".",
"EventUnregister",
"(",
"&",
"waitEntry",
")",
"\n",
"for",
"{",
"read",
",",
"_",
",",
"err",
"=",
"ep",
".",
"Read",
"(",
"addr",
")",
"\n",
"if",
"err",
"!=",
"tcpip",
".",
"ErrWouldBlock",
"{",
"break",
"\n",
"}",
"\n",
"select",
"{",
"case",
"<-",
"deadline",
":",
"return",
"nil",
",",
"errorer",
".",
"newOpError",
"(",
"\"",
"\"",
",",
"&",
"timeoutError",
"{",
"}",
")",
"\n",
"case",
"<-",
"notifyCh",
":",
"}",
"\n",
"}",
"\n",
"}",
"\n\n",
"if",
"err",
"==",
"tcpip",
".",
"ErrClosedForReceive",
"{",
"return",
"nil",
",",
"io",
".",
"EOF",
"\n",
"}",
"\n\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errorer",
".",
"newOpError",
"(",
"\"",
"\"",
",",
"errors",
".",
"New",
"(",
"err",
".",
"String",
"(",
")",
")",
")",
"\n",
"}",
"\n\n",
"return",
"read",
",",
"nil",
"\n",
"}"
] | // commonRead implements the common logic between net.Conn.Read and
// net.PacketConn.ReadFrom. | [
"commonRead",
"implements",
"the",
"common",
"logic",
"between",
"net",
".",
"Conn",
".",
"Read",
"and",
"net",
".",
"PacketConn",
".",
"ReadFrom",
"."
] | 70ebca9c30730cf3887cdef3b85bb96ed7a97593 | https://github.com/google/netstack/blob/70ebca9c30730cf3887cdef3b85bb96ed7a97593/tcpip/adapters/gonet/gonet.go#L283-L322 | train |
google/netstack | tcpip/adapters/gonet/gonet.go | Read | func (c *Conn) Read(b []byte) (int, error) {
c.readMu.Lock()
defer c.readMu.Unlock()
deadline := c.readCancel()
numRead := 0
for numRead != len(b) {
if len(c.read) == 0 {
var err error
c.read, err = commonRead(c.ep, c.wq, deadline, nil, c, numRead != 0)
if err != nil {
if numRead != 0 {
return numRead, nil
}
return numRead, err
}
}
n := copy(b[numRead:], c.read)
c.read.TrimFront(n)
numRead += n
if len(c.read) == 0 {
c.read = nil
}
}
return numRead, nil
} | go | func (c *Conn) Read(b []byte) (int, error) {
c.readMu.Lock()
defer c.readMu.Unlock()
deadline := c.readCancel()
numRead := 0
for numRead != len(b) {
if len(c.read) == 0 {
var err error
c.read, err = commonRead(c.ep, c.wq, deadline, nil, c, numRead != 0)
if err != nil {
if numRead != 0 {
return numRead, nil
}
return numRead, err
}
}
n := copy(b[numRead:], c.read)
c.read.TrimFront(n)
numRead += n
if len(c.read) == 0 {
c.read = nil
}
}
return numRead, nil
} | [
"func",
"(",
"c",
"*",
"Conn",
")",
"Read",
"(",
"b",
"[",
"]",
"byte",
")",
"(",
"int",
",",
"error",
")",
"{",
"c",
".",
"readMu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"c",
".",
"readMu",
".",
"Unlock",
"(",
")",
"\n\n",
"deadline",
":=",
"c",
".",
"readCancel",
"(",
")",
"\n\n",
"numRead",
":=",
"0",
"\n",
"for",
"numRead",
"!=",
"len",
"(",
"b",
")",
"{",
"if",
"len",
"(",
"c",
".",
"read",
")",
"==",
"0",
"{",
"var",
"err",
"error",
"\n",
"c",
".",
"read",
",",
"err",
"=",
"commonRead",
"(",
"c",
".",
"ep",
",",
"c",
".",
"wq",
",",
"deadline",
",",
"nil",
",",
"c",
",",
"numRead",
"!=",
"0",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"if",
"numRead",
"!=",
"0",
"{",
"return",
"numRead",
",",
"nil",
"\n",
"}",
"\n",
"return",
"numRead",
",",
"err",
"\n",
"}",
"\n",
"}",
"\n",
"n",
":=",
"copy",
"(",
"b",
"[",
"numRead",
":",
"]",
",",
"c",
".",
"read",
")",
"\n",
"c",
".",
"read",
".",
"TrimFront",
"(",
"n",
")",
"\n",
"numRead",
"+=",
"n",
"\n",
"if",
"len",
"(",
"c",
".",
"read",
")",
"==",
"0",
"{",
"c",
".",
"read",
"=",
"nil",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"numRead",
",",
"nil",
"\n",
"}"
] | // Read implements net.Conn.Read. | [
"Read",
"implements",
"net",
".",
"Conn",
".",
"Read",
"."
] | 70ebca9c30730cf3887cdef3b85bb96ed7a97593 | https://github.com/google/netstack/blob/70ebca9c30730cf3887cdef3b85bb96ed7a97593/tcpip/adapters/gonet/gonet.go#L325-L351 | train |
google/netstack | tcpip/adapters/gonet/gonet.go | Write | func (c *Conn) Write(b []byte) (int, error) {
deadline := c.writeCancel()
// Check if deadlineTimer has already expired.
select {
case <-deadline:
return 0, c.newOpError("write", &timeoutError{})
default:
}
v := buffer.NewViewFromBytes(b)
// We must handle two soft failure conditions simultaneously:
// 1. Write may write nothing and return tcpip.ErrWouldBlock.
// If this happens, we need to register for notifications if we have
// not already and wait to try again.
// 2. Write may write fewer than the full number of bytes and return
// without error. In this case we need to try writing the remaining
// bytes again. I do not need to register for notifications.
//
// What is more, these two soft failure conditions can be interspersed.
// There is no guarantee that all of the condition #1s will occur before
// all of the condition #2s or visa-versa.
var (
err *tcpip.Error
nbytes int
reg bool
notifyCh chan struct{}
)
for nbytes < len(b) && (err == tcpip.ErrWouldBlock || err == nil) {
if err == tcpip.ErrWouldBlock {
if !reg {
// Only register once.
reg = true
// Create wait queue entry that notifies a channel.
var waitEntry waiter.Entry
waitEntry, notifyCh = waiter.NewChannelEntry(nil)
c.wq.EventRegister(&waitEntry, waiter.EventOut)
defer c.wq.EventUnregister(&waitEntry)
} else {
// Don't wait immediately after registration in case more data
// became available between when we last checked and when we setup
// the notification.
select {
case <-deadline:
return nbytes, c.newOpError("write", &timeoutError{})
case <-notifyCh:
}
}
}
var n uintptr
var resCh <-chan struct{}
n, resCh, err = c.ep.Write(tcpip.SlicePayload(v), tcpip.WriteOptions{})
nbytes += int(n)
v.TrimFront(int(n))
if resCh != nil {
select {
case <-deadline:
return nbytes, c.newOpError("write", &timeoutError{})
case <-resCh:
}
n, _, err = c.ep.Write(tcpip.SlicePayload(v), tcpip.WriteOptions{})
nbytes += int(n)
v.TrimFront(int(n))
}
}
if err == nil {
return nbytes, nil
}
return nbytes, c.newOpError("write", errors.New(err.String()))
} | go | func (c *Conn) Write(b []byte) (int, error) {
deadline := c.writeCancel()
// Check if deadlineTimer has already expired.
select {
case <-deadline:
return 0, c.newOpError("write", &timeoutError{})
default:
}
v := buffer.NewViewFromBytes(b)
// We must handle two soft failure conditions simultaneously:
// 1. Write may write nothing and return tcpip.ErrWouldBlock.
// If this happens, we need to register for notifications if we have
// not already and wait to try again.
// 2. Write may write fewer than the full number of bytes and return
// without error. In this case we need to try writing the remaining
// bytes again. I do not need to register for notifications.
//
// What is more, these two soft failure conditions can be interspersed.
// There is no guarantee that all of the condition #1s will occur before
// all of the condition #2s or visa-versa.
var (
err *tcpip.Error
nbytes int
reg bool
notifyCh chan struct{}
)
for nbytes < len(b) && (err == tcpip.ErrWouldBlock || err == nil) {
if err == tcpip.ErrWouldBlock {
if !reg {
// Only register once.
reg = true
// Create wait queue entry that notifies a channel.
var waitEntry waiter.Entry
waitEntry, notifyCh = waiter.NewChannelEntry(nil)
c.wq.EventRegister(&waitEntry, waiter.EventOut)
defer c.wq.EventUnregister(&waitEntry)
} else {
// Don't wait immediately after registration in case more data
// became available between when we last checked and when we setup
// the notification.
select {
case <-deadline:
return nbytes, c.newOpError("write", &timeoutError{})
case <-notifyCh:
}
}
}
var n uintptr
var resCh <-chan struct{}
n, resCh, err = c.ep.Write(tcpip.SlicePayload(v), tcpip.WriteOptions{})
nbytes += int(n)
v.TrimFront(int(n))
if resCh != nil {
select {
case <-deadline:
return nbytes, c.newOpError("write", &timeoutError{})
case <-resCh:
}
n, _, err = c.ep.Write(tcpip.SlicePayload(v), tcpip.WriteOptions{})
nbytes += int(n)
v.TrimFront(int(n))
}
}
if err == nil {
return nbytes, nil
}
return nbytes, c.newOpError("write", errors.New(err.String()))
} | [
"func",
"(",
"c",
"*",
"Conn",
")",
"Write",
"(",
"b",
"[",
"]",
"byte",
")",
"(",
"int",
",",
"error",
")",
"{",
"deadline",
":=",
"c",
".",
"writeCancel",
"(",
")",
"\n\n",
"// Check if deadlineTimer has already expired.",
"select",
"{",
"case",
"<-",
"deadline",
":",
"return",
"0",
",",
"c",
".",
"newOpError",
"(",
"\"",
"\"",
",",
"&",
"timeoutError",
"{",
"}",
")",
"\n",
"default",
":",
"}",
"\n\n",
"v",
":=",
"buffer",
".",
"NewViewFromBytes",
"(",
"b",
")",
"\n\n",
"// We must handle two soft failure conditions simultaneously:",
"// 1. Write may write nothing and return tcpip.ErrWouldBlock.",
"// If this happens, we need to register for notifications if we have",
"// not already and wait to try again.",
"// 2. Write may write fewer than the full number of bytes and return",
"// without error. In this case we need to try writing the remaining",
"// bytes again. I do not need to register for notifications.",
"//",
"// What is more, these two soft failure conditions can be interspersed.",
"// There is no guarantee that all of the condition #1s will occur before",
"// all of the condition #2s or visa-versa.",
"var",
"(",
"err",
"*",
"tcpip",
".",
"Error",
"\n",
"nbytes",
"int",
"\n",
"reg",
"bool",
"\n",
"notifyCh",
"chan",
"struct",
"{",
"}",
"\n",
")",
"\n",
"for",
"nbytes",
"<",
"len",
"(",
"b",
")",
"&&",
"(",
"err",
"==",
"tcpip",
".",
"ErrWouldBlock",
"||",
"err",
"==",
"nil",
")",
"{",
"if",
"err",
"==",
"tcpip",
".",
"ErrWouldBlock",
"{",
"if",
"!",
"reg",
"{",
"// Only register once.",
"reg",
"=",
"true",
"\n\n",
"// Create wait queue entry that notifies a channel.",
"var",
"waitEntry",
"waiter",
".",
"Entry",
"\n",
"waitEntry",
",",
"notifyCh",
"=",
"waiter",
".",
"NewChannelEntry",
"(",
"nil",
")",
"\n",
"c",
".",
"wq",
".",
"EventRegister",
"(",
"&",
"waitEntry",
",",
"waiter",
".",
"EventOut",
")",
"\n",
"defer",
"c",
".",
"wq",
".",
"EventUnregister",
"(",
"&",
"waitEntry",
")",
"\n",
"}",
"else",
"{",
"// Don't wait immediately after registration in case more data",
"// became available between when we last checked and when we setup",
"// the notification.",
"select",
"{",
"case",
"<-",
"deadline",
":",
"return",
"nbytes",
",",
"c",
".",
"newOpError",
"(",
"\"",
"\"",
",",
"&",
"timeoutError",
"{",
"}",
")",
"\n",
"case",
"<-",
"notifyCh",
":",
"}",
"\n",
"}",
"\n",
"}",
"\n\n",
"var",
"n",
"uintptr",
"\n",
"var",
"resCh",
"<-",
"chan",
"struct",
"{",
"}",
"\n",
"n",
",",
"resCh",
",",
"err",
"=",
"c",
".",
"ep",
".",
"Write",
"(",
"tcpip",
".",
"SlicePayload",
"(",
"v",
")",
",",
"tcpip",
".",
"WriteOptions",
"{",
"}",
")",
"\n",
"nbytes",
"+=",
"int",
"(",
"n",
")",
"\n",
"v",
".",
"TrimFront",
"(",
"int",
"(",
"n",
")",
")",
"\n\n",
"if",
"resCh",
"!=",
"nil",
"{",
"select",
"{",
"case",
"<-",
"deadline",
":",
"return",
"nbytes",
",",
"c",
".",
"newOpError",
"(",
"\"",
"\"",
",",
"&",
"timeoutError",
"{",
"}",
")",
"\n",
"case",
"<-",
"resCh",
":",
"}",
"\n\n",
"n",
",",
"_",
",",
"err",
"=",
"c",
".",
"ep",
".",
"Write",
"(",
"tcpip",
".",
"SlicePayload",
"(",
"v",
")",
",",
"tcpip",
".",
"WriteOptions",
"{",
"}",
")",
"\n",
"nbytes",
"+=",
"int",
"(",
"n",
")",
"\n",
"v",
".",
"TrimFront",
"(",
"int",
"(",
"n",
")",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"if",
"err",
"==",
"nil",
"{",
"return",
"nbytes",
",",
"nil",
"\n",
"}",
"\n\n",
"return",
"nbytes",
",",
"c",
".",
"newOpError",
"(",
"\"",
"\"",
",",
"errors",
".",
"New",
"(",
"err",
".",
"String",
"(",
")",
")",
")",
"\n",
"}"
] | // Write implements net.Conn.Write. | [
"Write",
"implements",
"net",
".",
"Conn",
".",
"Write",
"."
] | 70ebca9c30730cf3887cdef3b85bb96ed7a97593 | https://github.com/google/netstack/blob/70ebca9c30730cf3887cdef3b85bb96ed7a97593/tcpip/adapters/gonet/gonet.go#L354-L430 | train |
google/netstack | tcpip/adapters/gonet/gonet.go | LocalAddr | func (c *Conn) LocalAddr() net.Addr {
a, err := c.ep.GetLocalAddress()
if err != nil {
return nil
}
return fullToTCPAddr(a)
} | go | func (c *Conn) LocalAddr() net.Addr {
a, err := c.ep.GetLocalAddress()
if err != nil {
return nil
}
return fullToTCPAddr(a)
} | [
"func",
"(",
"c",
"*",
"Conn",
")",
"LocalAddr",
"(",
")",
"net",
".",
"Addr",
"{",
"a",
",",
"err",
":=",
"c",
".",
"ep",
".",
"GetLocalAddress",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"return",
"fullToTCPAddr",
"(",
"a",
")",
"\n",
"}"
] | // LocalAddr implements net.Conn.LocalAddr. | [
"LocalAddr",
"implements",
"net",
".",
"Conn",
".",
"LocalAddr",
"."
] | 70ebca9c30730cf3887cdef3b85bb96ed7a97593 | https://github.com/google/netstack/blob/70ebca9c30730cf3887cdef3b85bb96ed7a97593/tcpip/adapters/gonet/gonet.go#L461-L467 | train |
google/netstack | tcpip/adapters/gonet/gonet.go | DialTCP | func DialTCP(s *stack.Stack, addr tcpip.FullAddress, network tcpip.NetworkProtocolNumber) (*Conn, error) {
// Create TCP endpoint, then connect.
var wq waiter.Queue
ep, err := s.NewEndpoint(tcp.ProtocolNumber, network, &wq)
if err != nil {
return nil, errors.New(err.String())
}
// Create wait queue entry that notifies a channel.
//
// We do this unconditionally as Connect will always return an error.
waitEntry, notifyCh := waiter.NewChannelEntry(nil)
wq.EventRegister(&waitEntry, waiter.EventOut)
defer wq.EventUnregister(&waitEntry)
err = ep.Connect(addr)
if err == tcpip.ErrConnectStarted {
<-notifyCh
err = ep.GetSockOpt(tcpip.ErrorOption{})
}
if err != nil {
ep.Close()
return nil, &net.OpError{
Op: "connect",
Net: "tcp",
Addr: fullToTCPAddr(addr),
Err: errors.New(err.String()),
}
}
return NewConn(&wq, ep), nil
} | go | func DialTCP(s *stack.Stack, addr tcpip.FullAddress, network tcpip.NetworkProtocolNumber) (*Conn, error) {
// Create TCP endpoint, then connect.
var wq waiter.Queue
ep, err := s.NewEndpoint(tcp.ProtocolNumber, network, &wq)
if err != nil {
return nil, errors.New(err.String())
}
// Create wait queue entry that notifies a channel.
//
// We do this unconditionally as Connect will always return an error.
waitEntry, notifyCh := waiter.NewChannelEntry(nil)
wq.EventRegister(&waitEntry, waiter.EventOut)
defer wq.EventUnregister(&waitEntry)
err = ep.Connect(addr)
if err == tcpip.ErrConnectStarted {
<-notifyCh
err = ep.GetSockOpt(tcpip.ErrorOption{})
}
if err != nil {
ep.Close()
return nil, &net.OpError{
Op: "connect",
Net: "tcp",
Addr: fullToTCPAddr(addr),
Err: errors.New(err.String()),
}
}
return NewConn(&wq, ep), nil
} | [
"func",
"DialTCP",
"(",
"s",
"*",
"stack",
".",
"Stack",
",",
"addr",
"tcpip",
".",
"FullAddress",
",",
"network",
"tcpip",
".",
"NetworkProtocolNumber",
")",
"(",
"*",
"Conn",
",",
"error",
")",
"{",
"// Create TCP endpoint, then connect.",
"var",
"wq",
"waiter",
".",
"Queue",
"\n",
"ep",
",",
"err",
":=",
"s",
".",
"NewEndpoint",
"(",
"tcp",
".",
"ProtocolNumber",
",",
"network",
",",
"&",
"wq",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"New",
"(",
"err",
".",
"String",
"(",
")",
")",
"\n",
"}",
"\n\n",
"// Create wait queue entry that notifies a channel.",
"//",
"// We do this unconditionally as Connect will always return an error.",
"waitEntry",
",",
"notifyCh",
":=",
"waiter",
".",
"NewChannelEntry",
"(",
"nil",
")",
"\n",
"wq",
".",
"EventRegister",
"(",
"&",
"waitEntry",
",",
"waiter",
".",
"EventOut",
")",
"\n",
"defer",
"wq",
".",
"EventUnregister",
"(",
"&",
"waitEntry",
")",
"\n\n",
"err",
"=",
"ep",
".",
"Connect",
"(",
"addr",
")",
"\n",
"if",
"err",
"==",
"tcpip",
".",
"ErrConnectStarted",
"{",
"<-",
"notifyCh",
"\n",
"err",
"=",
"ep",
".",
"GetSockOpt",
"(",
"tcpip",
".",
"ErrorOption",
"{",
"}",
")",
"\n",
"}",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"ep",
".",
"Close",
"(",
")",
"\n",
"return",
"nil",
",",
"&",
"net",
".",
"OpError",
"{",
"Op",
":",
"\"",
"\"",
",",
"Net",
":",
"\"",
"\"",
",",
"Addr",
":",
"fullToTCPAddr",
"(",
"addr",
")",
",",
"Err",
":",
"errors",
".",
"New",
"(",
"err",
".",
"String",
"(",
")",
")",
",",
"}",
"\n",
"}",
"\n\n",
"return",
"NewConn",
"(",
"&",
"wq",
",",
"ep",
")",
",",
"nil",
"\n",
"}"
] | // DialTCP creates a new TCP Conn connected to the specified address. | [
"DialTCP",
"creates",
"a",
"new",
"TCP",
"Conn",
"connected",
"to",
"the",
"specified",
"address",
"."
] | 70ebca9c30730cf3887cdef3b85bb96ed7a97593 | https://github.com/google/netstack/blob/70ebca9c30730cf3887cdef3b85bb96ed7a97593/tcpip/adapters/gonet/gonet.go#L497-L528 | train |
google/netstack | tcpip/adapters/gonet/gonet.go | NewPacketConn | func NewPacketConn(s *stack.Stack, addr tcpip.FullAddress, network tcpip.NetworkProtocolNumber) (*PacketConn, error) {
// Create UDP endpoint and bind it.
var wq waiter.Queue
ep, err := s.NewEndpoint(udp.ProtocolNumber, network, &wq)
if err != nil {
return nil, errors.New(err.String())
}
if err := ep.Bind(addr); err != nil {
ep.Close()
return nil, &net.OpError{
Op: "bind",
Net: "udp",
Addr: fullToUDPAddr(addr),
Err: errors.New(err.String()),
}
}
c := &PacketConn{
stack: s,
ep: ep,
wq: &wq,
}
c.deadlineTimer.init()
return c, nil
} | go | func NewPacketConn(s *stack.Stack, addr tcpip.FullAddress, network tcpip.NetworkProtocolNumber) (*PacketConn, error) {
// Create UDP endpoint and bind it.
var wq waiter.Queue
ep, err := s.NewEndpoint(udp.ProtocolNumber, network, &wq)
if err != nil {
return nil, errors.New(err.String())
}
if err := ep.Bind(addr); err != nil {
ep.Close()
return nil, &net.OpError{
Op: "bind",
Net: "udp",
Addr: fullToUDPAddr(addr),
Err: errors.New(err.String()),
}
}
c := &PacketConn{
stack: s,
ep: ep,
wq: &wq,
}
c.deadlineTimer.init()
return c, nil
} | [
"func",
"NewPacketConn",
"(",
"s",
"*",
"stack",
".",
"Stack",
",",
"addr",
"tcpip",
".",
"FullAddress",
",",
"network",
"tcpip",
".",
"NetworkProtocolNumber",
")",
"(",
"*",
"PacketConn",
",",
"error",
")",
"{",
"// Create UDP endpoint and bind it.",
"var",
"wq",
"waiter",
".",
"Queue",
"\n",
"ep",
",",
"err",
":=",
"s",
".",
"NewEndpoint",
"(",
"udp",
".",
"ProtocolNumber",
",",
"network",
",",
"&",
"wq",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"New",
"(",
"err",
".",
"String",
"(",
")",
")",
"\n",
"}",
"\n\n",
"if",
"err",
":=",
"ep",
".",
"Bind",
"(",
"addr",
")",
";",
"err",
"!=",
"nil",
"{",
"ep",
".",
"Close",
"(",
")",
"\n",
"return",
"nil",
",",
"&",
"net",
".",
"OpError",
"{",
"Op",
":",
"\"",
"\"",
",",
"Net",
":",
"\"",
"\"",
",",
"Addr",
":",
"fullToUDPAddr",
"(",
"addr",
")",
",",
"Err",
":",
"errors",
".",
"New",
"(",
"err",
".",
"String",
"(",
")",
")",
",",
"}",
"\n",
"}",
"\n\n",
"c",
":=",
"&",
"PacketConn",
"{",
"stack",
":",
"s",
",",
"ep",
":",
"ep",
",",
"wq",
":",
"&",
"wq",
",",
"}",
"\n",
"c",
".",
"deadlineTimer",
".",
"init",
"(",
")",
"\n",
"return",
"c",
",",
"nil",
"\n",
"}"
] | // NewPacketConn creates a new PacketConn. | [
"NewPacketConn",
"creates",
"a",
"new",
"PacketConn",
"."
] | 70ebca9c30730cf3887cdef3b85bb96ed7a97593 | https://github.com/google/netstack/blob/70ebca9c30730cf3887cdef3b85bb96ed7a97593/tcpip/adapters/gonet/gonet.go#L541-L566 | train |
google/netstack | tcpip/adapters/gonet/gonet.go | RemoteAddr | func (c *PacketConn) RemoteAddr() net.Addr {
a, err := c.ep.GetRemoteAddress()
if err != nil {
return nil
}
return fullToTCPAddr(a)
} | go | func (c *PacketConn) RemoteAddr() net.Addr {
a, err := c.ep.GetRemoteAddress()
if err != nil {
return nil
}
return fullToTCPAddr(a)
} | [
"func",
"(",
"c",
"*",
"PacketConn",
")",
"RemoteAddr",
"(",
")",
"net",
".",
"Addr",
"{",
"a",
",",
"err",
":=",
"c",
".",
"ep",
".",
"GetRemoteAddress",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"return",
"fullToTCPAddr",
"(",
"a",
")",
"\n",
"}"
] | // RemoteAddr implements net.Conn.RemoteAddr. | [
"RemoteAddr",
"implements",
"net",
".",
"Conn",
".",
"RemoteAddr",
"."
] | 70ebca9c30730cf3887cdef3b85bb96ed7a97593 | https://github.com/google/netstack/blob/70ebca9c30730cf3887cdef3b85bb96ed7a97593/tcpip/adapters/gonet/gonet.go#L583-L589 | train |
google/netstack | tcpip/adapters/gonet/gonet.go | Read | func (c *PacketConn) Read(b []byte) (int, error) {
bytesRead, _, err := c.ReadFrom(b)
return bytesRead, err
} | go | func (c *PacketConn) Read(b []byte) (int, error) {
bytesRead, _, err := c.ReadFrom(b)
return bytesRead, err
} | [
"func",
"(",
"c",
"*",
"PacketConn",
")",
"Read",
"(",
"b",
"[",
"]",
"byte",
")",
"(",
"int",
",",
"error",
")",
"{",
"bytesRead",
",",
"_",
",",
"err",
":=",
"c",
".",
"ReadFrom",
"(",
"b",
")",
"\n",
"return",
"bytesRead",
",",
"err",
"\n",
"}"
] | // Read implements net.Conn.Read | [
"Read",
"implements",
"net",
".",
"Conn",
".",
"Read"
] | 70ebca9c30730cf3887cdef3b85bb96ed7a97593 | https://github.com/google/netstack/blob/70ebca9c30730cf3887cdef3b85bb96ed7a97593/tcpip/adapters/gonet/gonet.go#L592-L595 | train |
google/netstack | tcpip/adapters/gonet/gonet.go | ReadFrom | func (c *PacketConn) ReadFrom(b []byte) (int, net.Addr, error) {
deadline := c.readCancel()
var addr tcpip.FullAddress
read, err := commonRead(c.ep, c.wq, deadline, &addr, c, false)
if err != nil {
return 0, nil, err
}
return copy(b, read), fullToUDPAddr(addr), nil
} | go | func (c *PacketConn) ReadFrom(b []byte) (int, net.Addr, error) {
deadline := c.readCancel()
var addr tcpip.FullAddress
read, err := commonRead(c.ep, c.wq, deadline, &addr, c, false)
if err != nil {
return 0, nil, err
}
return copy(b, read), fullToUDPAddr(addr), nil
} | [
"func",
"(",
"c",
"*",
"PacketConn",
")",
"ReadFrom",
"(",
"b",
"[",
"]",
"byte",
")",
"(",
"int",
",",
"net",
".",
"Addr",
",",
"error",
")",
"{",
"deadline",
":=",
"c",
".",
"readCancel",
"(",
")",
"\n\n",
"var",
"addr",
"tcpip",
".",
"FullAddress",
"\n",
"read",
",",
"err",
":=",
"commonRead",
"(",
"c",
".",
"ep",
",",
"c",
".",
"wq",
",",
"deadline",
",",
"&",
"addr",
",",
"c",
",",
"false",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"0",
",",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"copy",
"(",
"b",
",",
"read",
")",
",",
"fullToUDPAddr",
"(",
"addr",
")",
",",
"nil",
"\n",
"}"
] | // ReadFrom implements net.PacketConn.ReadFrom. | [
"ReadFrom",
"implements",
"net",
".",
"PacketConn",
".",
"ReadFrom",
"."
] | 70ebca9c30730cf3887cdef3b85bb96ed7a97593 | https://github.com/google/netstack/blob/70ebca9c30730cf3887cdef3b85bb96ed7a97593/tcpip/adapters/gonet/gonet.go#L598-L608 | train |
google/netstack | tcpip/adapters/gonet/gonet.go | WriteTo | func (c *PacketConn) WriteTo(b []byte, addr net.Addr) (int, error) {
deadline := c.writeCancel()
// Check if deadline has already expired.
select {
case <-deadline:
return 0, c.newRemoteOpError("write", addr, &timeoutError{})
default:
}
// If we're being called by Write, there is no addr
wopts := tcpip.WriteOptions{}
if addr != nil {
ua := addr.(*net.UDPAddr)
wopts.To = &tcpip.FullAddress{Addr: tcpip.Address(ua.IP), Port: uint16(ua.Port)}
}
v := buffer.NewView(len(b))
copy(v, b)
n, resCh, err := c.ep.Write(tcpip.SlicePayload(v), wopts)
if resCh != nil {
select {
case <-deadline:
return int(n), c.newRemoteOpError("write", addr, &timeoutError{})
case <-resCh:
}
n, _, err = c.ep.Write(tcpip.SlicePayload(v), wopts)
}
if err == tcpip.ErrWouldBlock {
// Create wait queue entry that notifies a channel.
waitEntry, notifyCh := waiter.NewChannelEntry(nil)
c.wq.EventRegister(&waitEntry, waiter.EventOut)
defer c.wq.EventUnregister(&waitEntry)
for {
select {
case <-deadline:
return int(n), c.newRemoteOpError("write", addr, &timeoutError{})
case <-notifyCh:
}
n, _, err = c.ep.Write(tcpip.SlicePayload(v), wopts)
if err != tcpip.ErrWouldBlock {
break
}
}
}
if err == nil {
return int(n), nil
}
return int(n), c.newRemoteOpError("write", addr, errors.New(err.String()))
} | go | func (c *PacketConn) WriteTo(b []byte, addr net.Addr) (int, error) {
deadline := c.writeCancel()
// Check if deadline has already expired.
select {
case <-deadline:
return 0, c.newRemoteOpError("write", addr, &timeoutError{})
default:
}
// If we're being called by Write, there is no addr
wopts := tcpip.WriteOptions{}
if addr != nil {
ua := addr.(*net.UDPAddr)
wopts.To = &tcpip.FullAddress{Addr: tcpip.Address(ua.IP), Port: uint16(ua.Port)}
}
v := buffer.NewView(len(b))
copy(v, b)
n, resCh, err := c.ep.Write(tcpip.SlicePayload(v), wopts)
if resCh != nil {
select {
case <-deadline:
return int(n), c.newRemoteOpError("write", addr, &timeoutError{})
case <-resCh:
}
n, _, err = c.ep.Write(tcpip.SlicePayload(v), wopts)
}
if err == tcpip.ErrWouldBlock {
// Create wait queue entry that notifies a channel.
waitEntry, notifyCh := waiter.NewChannelEntry(nil)
c.wq.EventRegister(&waitEntry, waiter.EventOut)
defer c.wq.EventUnregister(&waitEntry)
for {
select {
case <-deadline:
return int(n), c.newRemoteOpError("write", addr, &timeoutError{})
case <-notifyCh:
}
n, _, err = c.ep.Write(tcpip.SlicePayload(v), wopts)
if err != tcpip.ErrWouldBlock {
break
}
}
}
if err == nil {
return int(n), nil
}
return int(n), c.newRemoteOpError("write", addr, errors.New(err.String()))
} | [
"func",
"(",
"c",
"*",
"PacketConn",
")",
"WriteTo",
"(",
"b",
"[",
"]",
"byte",
",",
"addr",
"net",
".",
"Addr",
")",
"(",
"int",
",",
"error",
")",
"{",
"deadline",
":=",
"c",
".",
"writeCancel",
"(",
")",
"\n\n",
"// Check if deadline has already expired.",
"select",
"{",
"case",
"<-",
"deadline",
":",
"return",
"0",
",",
"c",
".",
"newRemoteOpError",
"(",
"\"",
"\"",
",",
"addr",
",",
"&",
"timeoutError",
"{",
"}",
")",
"\n",
"default",
":",
"}",
"\n\n",
"// If we're being called by Write, there is no addr",
"wopts",
":=",
"tcpip",
".",
"WriteOptions",
"{",
"}",
"\n",
"if",
"addr",
"!=",
"nil",
"{",
"ua",
":=",
"addr",
".",
"(",
"*",
"net",
".",
"UDPAddr",
")",
"\n",
"wopts",
".",
"To",
"=",
"&",
"tcpip",
".",
"FullAddress",
"{",
"Addr",
":",
"tcpip",
".",
"Address",
"(",
"ua",
".",
"IP",
")",
",",
"Port",
":",
"uint16",
"(",
"ua",
".",
"Port",
")",
"}",
"\n",
"}",
"\n\n",
"v",
":=",
"buffer",
".",
"NewView",
"(",
"len",
"(",
"b",
")",
")",
"\n",
"copy",
"(",
"v",
",",
"b",
")",
"\n\n",
"n",
",",
"resCh",
",",
"err",
":=",
"c",
".",
"ep",
".",
"Write",
"(",
"tcpip",
".",
"SlicePayload",
"(",
"v",
")",
",",
"wopts",
")",
"\n",
"if",
"resCh",
"!=",
"nil",
"{",
"select",
"{",
"case",
"<-",
"deadline",
":",
"return",
"int",
"(",
"n",
")",
",",
"c",
".",
"newRemoteOpError",
"(",
"\"",
"\"",
",",
"addr",
",",
"&",
"timeoutError",
"{",
"}",
")",
"\n",
"case",
"<-",
"resCh",
":",
"}",
"\n\n",
"n",
",",
"_",
",",
"err",
"=",
"c",
".",
"ep",
".",
"Write",
"(",
"tcpip",
".",
"SlicePayload",
"(",
"v",
")",
",",
"wopts",
")",
"\n",
"}",
"\n\n",
"if",
"err",
"==",
"tcpip",
".",
"ErrWouldBlock",
"{",
"// Create wait queue entry that notifies a channel.",
"waitEntry",
",",
"notifyCh",
":=",
"waiter",
".",
"NewChannelEntry",
"(",
"nil",
")",
"\n",
"c",
".",
"wq",
".",
"EventRegister",
"(",
"&",
"waitEntry",
",",
"waiter",
".",
"EventOut",
")",
"\n",
"defer",
"c",
".",
"wq",
".",
"EventUnregister",
"(",
"&",
"waitEntry",
")",
"\n",
"for",
"{",
"select",
"{",
"case",
"<-",
"deadline",
":",
"return",
"int",
"(",
"n",
")",
",",
"c",
".",
"newRemoteOpError",
"(",
"\"",
"\"",
",",
"addr",
",",
"&",
"timeoutError",
"{",
"}",
")",
"\n",
"case",
"<-",
"notifyCh",
":",
"}",
"\n\n",
"n",
",",
"_",
",",
"err",
"=",
"c",
".",
"ep",
".",
"Write",
"(",
"tcpip",
".",
"SlicePayload",
"(",
"v",
")",
",",
"wopts",
")",
"\n",
"if",
"err",
"!=",
"tcpip",
".",
"ErrWouldBlock",
"{",
"break",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n\n",
"if",
"err",
"==",
"nil",
"{",
"return",
"int",
"(",
"n",
")",
",",
"nil",
"\n",
"}",
"\n\n",
"return",
"int",
"(",
"n",
")",
",",
"c",
".",
"newRemoteOpError",
"(",
"\"",
"\"",
",",
"addr",
",",
"errors",
".",
"New",
"(",
"err",
".",
"String",
"(",
")",
")",
")",
"\n",
"}"
] | // WriteTo implements net.PacketConn.WriteTo. | [
"WriteTo",
"implements",
"net",
".",
"PacketConn",
".",
"WriteTo",
"."
] | 70ebca9c30730cf3887cdef3b85bb96ed7a97593 | https://github.com/google/netstack/blob/70ebca9c30730cf3887cdef3b85bb96ed7a97593/tcpip/adapters/gonet/gonet.go#L615-L670 | train |
google/netstack | tcpip/adapters/gonet/gonet.go | LocalAddr | func (c *PacketConn) LocalAddr() net.Addr {
a, err := c.ep.GetLocalAddress()
if err != nil {
return nil
}
return fullToUDPAddr(a)
} | go | func (c *PacketConn) LocalAddr() net.Addr {
a, err := c.ep.GetLocalAddress()
if err != nil {
return nil
}
return fullToUDPAddr(a)
} | [
"func",
"(",
"c",
"*",
"PacketConn",
")",
"LocalAddr",
"(",
")",
"net",
".",
"Addr",
"{",
"a",
",",
"err",
":=",
"c",
".",
"ep",
".",
"GetLocalAddress",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"return",
"fullToUDPAddr",
"(",
"a",
")",
"\n",
"}"
] | // LocalAddr implements net.PacketConn.LocalAddr. | [
"LocalAddr",
"implements",
"net",
".",
"PacketConn",
".",
"LocalAddr",
"."
] | 70ebca9c30730cf3887cdef3b85bb96ed7a97593 | https://github.com/google/netstack/blob/70ebca9c30730cf3887cdef3b85bb96ed7a97593/tcpip/adapters/gonet/gonet.go#L679-L685 | train |
google/netstack | tcpip/buffer/prependable.go | NewPrependable | func NewPrependable(size int) Prependable {
return Prependable{buf: NewView(size), usedIdx: size}
} | go | func NewPrependable(size int) Prependable {
return Prependable{buf: NewView(size), usedIdx: size}
} | [
"func",
"NewPrependable",
"(",
"size",
"int",
")",
"Prependable",
"{",
"return",
"Prependable",
"{",
"buf",
":",
"NewView",
"(",
"size",
")",
",",
"usedIdx",
":",
"size",
"}",
"\n",
"}"
] | // NewPrependable allocates a new prependable buffer with the given size. | [
"NewPrependable",
"allocates",
"a",
"new",
"prependable",
"buffer",
"with",
"the",
"given",
"size",
"."
] | 70ebca9c30730cf3887cdef3b85bb96ed7a97593 | https://github.com/google/netstack/blob/70ebca9c30730cf3887cdef3b85bb96ed7a97593/tcpip/buffer/prependable.go#L31-L33 | train |
google/netstack | tcpip/buffer/prependable.go | Prepend | func (p *Prependable) Prepend(size int) []byte {
if size > p.usedIdx {
return nil
}
p.usedIdx -= size
return p.View()[:size:size]
} | go | func (p *Prependable) Prepend(size int) []byte {
if size > p.usedIdx {
return nil
}
p.usedIdx -= size
return p.View()[:size:size]
} | [
"func",
"(",
"p",
"*",
"Prependable",
")",
"Prepend",
"(",
"size",
"int",
")",
"[",
"]",
"byte",
"{",
"if",
"size",
">",
"p",
".",
"usedIdx",
"{",
"return",
"nil",
"\n",
"}",
"\n\n",
"p",
".",
"usedIdx",
"-=",
"size",
"\n",
"return",
"p",
".",
"View",
"(",
")",
"[",
":",
"size",
":",
"size",
"]",
"\n",
"}"
] | // Prepend reserves the requested space in front of the buffer, returning a
// slice that represents the reserved space. | [
"Prepend",
"reserves",
"the",
"requested",
"space",
"in",
"front",
"of",
"the",
"buffer",
"returning",
"a",
"slice",
"that",
"represents",
"the",
"reserved",
"space",
"."
] | 70ebca9c30730cf3887cdef3b85bb96ed7a97593 | https://github.com/google/netstack/blob/70ebca9c30730cf3887cdef3b85bb96ed7a97593/tcpip/buffer/prependable.go#L57-L64 | train |
google/netstack | tcpip/link/tun/tun_unsafe.go | Open | func Open(name string) (int, error) {
return open(name, syscall.IFF_TUN|syscall.IFF_NO_PI)
} | go | func Open(name string) (int, error) {
return open(name, syscall.IFF_TUN|syscall.IFF_NO_PI)
} | [
"func",
"Open",
"(",
"name",
"string",
")",
"(",
"int",
",",
"error",
")",
"{",
"return",
"open",
"(",
"name",
",",
"syscall",
".",
"IFF_TUN",
"|",
"syscall",
".",
"IFF_NO_PI",
")",
"\n",
"}"
] | // Open opens the specified TUN device, sets it to non-blocking mode, and
// returns its file descriptor. | [
"Open",
"opens",
"the",
"specified",
"TUN",
"device",
"sets",
"it",
"to",
"non",
"-",
"blocking",
"mode",
"and",
"returns",
"its",
"file",
"descriptor",
"."
] | 70ebca9c30730cf3887cdef3b85bb96ed7a97593 | https://github.com/google/netstack/blob/70ebca9c30730cf3887cdef3b85bb96ed7a97593/tcpip/link/tun/tun_unsafe.go#L27-L29 | train |
google/netstack | tcpip/link/tun/tun_unsafe.go | OpenTAP | func OpenTAP(name string) (int, error) {
return open(name, syscall.IFF_TAP|syscall.IFF_NO_PI)
} | go | func OpenTAP(name string) (int, error) {
return open(name, syscall.IFF_TAP|syscall.IFF_NO_PI)
} | [
"func",
"OpenTAP",
"(",
"name",
"string",
")",
"(",
"int",
",",
"error",
")",
"{",
"return",
"open",
"(",
"name",
",",
"syscall",
".",
"IFF_TAP",
"|",
"syscall",
".",
"IFF_NO_PI",
")",
"\n",
"}"
] | // OpenTAP opens the specified TAP device, sets it to non-blocking mode, and
// returns its file descriptor. | [
"OpenTAP",
"opens",
"the",
"specified",
"TAP",
"device",
"sets",
"it",
"to",
"non",
"-",
"blocking",
"mode",
"and",
"returns",
"its",
"file",
"descriptor",
"."
] | 70ebca9c30730cf3887cdef3b85bb96ed7a97593 | https://github.com/google/netstack/blob/70ebca9c30730cf3887cdef3b85bb96ed7a97593/tcpip/link/tun/tun_unsafe.go#L33-L35 | train |
google/netstack | sleep/sleep_unsafe.go | AddWaker | func (s *Sleeper) AddWaker(w *Waker, id int) {
// Add the waker to the list of all wakers.
w.allWakersNext = s.allWakers
s.allWakers = w
w.id = id
// Try to associate the waker with the sleeper. If it's already
// asserted, we simply enqueue it in the "ready" list.
for {
p := (*Sleeper)(atomic.LoadPointer(&w.s))
if p == &assertedSleeper {
s.enqueueAssertedWaker(w)
return
}
if atomic.CompareAndSwapPointer(&w.s, usleeper(p), usleeper(s)) {
return
}
}
} | go | func (s *Sleeper) AddWaker(w *Waker, id int) {
// Add the waker to the list of all wakers.
w.allWakersNext = s.allWakers
s.allWakers = w
w.id = id
// Try to associate the waker with the sleeper. If it's already
// asserted, we simply enqueue it in the "ready" list.
for {
p := (*Sleeper)(atomic.LoadPointer(&w.s))
if p == &assertedSleeper {
s.enqueueAssertedWaker(w)
return
}
if atomic.CompareAndSwapPointer(&w.s, usleeper(p), usleeper(s)) {
return
}
}
} | [
"func",
"(",
"s",
"*",
"Sleeper",
")",
"AddWaker",
"(",
"w",
"*",
"Waker",
",",
"id",
"int",
")",
"{",
"// Add the waker to the list of all wakers.",
"w",
".",
"allWakersNext",
"=",
"s",
".",
"allWakers",
"\n",
"s",
".",
"allWakers",
"=",
"w",
"\n",
"w",
".",
"id",
"=",
"id",
"\n\n",
"// Try to associate the waker with the sleeper. If it's already",
"// asserted, we simply enqueue it in the \"ready\" list.",
"for",
"{",
"p",
":=",
"(",
"*",
"Sleeper",
")",
"(",
"atomic",
".",
"LoadPointer",
"(",
"&",
"w",
".",
"s",
")",
")",
"\n",
"if",
"p",
"==",
"&",
"assertedSleeper",
"{",
"s",
".",
"enqueueAssertedWaker",
"(",
"w",
")",
"\n",
"return",
"\n",
"}",
"\n\n",
"if",
"atomic",
".",
"CompareAndSwapPointer",
"(",
"&",
"w",
".",
"s",
",",
"usleeper",
"(",
"p",
")",
",",
"usleeper",
"(",
"s",
")",
")",
"{",
"return",
"\n",
"}",
"\n",
"}",
"\n",
"}"
] | // AddWaker associates the given waker to the sleeper. id is the value to be
// returned when the sleeper is woken by the given waker. | [
"AddWaker",
"associates",
"the",
"given",
"waker",
"to",
"the",
"sleeper",
".",
"id",
"is",
"the",
"value",
"to",
"be",
"returned",
"when",
"the",
"sleeper",
"is",
"woken",
"by",
"the",
"given",
"waker",
"."
] | 70ebca9c30730cf3887cdef3b85bb96ed7a97593 | https://github.com/google/netstack/blob/70ebca9c30730cf3887cdef3b85bb96ed7a97593/sleep/sleep_unsafe.go#L128-L147 | train |
google/netstack | sleep/sleep_unsafe.go | nextWaker | func (s *Sleeper) nextWaker(block bool) *Waker {
// Attempt to replenish the local list if it's currently empty.
if s.localList == nil {
for atomic.LoadPointer(&s.sharedList) == nil {
// Fail request if caller requested that we
// don't block.
if !block {
return nil
}
// Indicate to wakers that we're about to sleep,
// this allows them to abort the wait by setting
// waitingG back to zero (which we'll notice
// before committing the sleep).
atomic.StoreUintptr(&s.waitingG, preparingG)
// Check if something was queued while we were
// preparing to sleep. We need this interleaving
// to avoid missing wake ups.
if atomic.LoadPointer(&s.sharedList) != nil {
atomic.StoreUintptr(&s.waitingG, 0)
break
}
// Try to commit the sleep and report it to the
// tracer as a select.
//
// gopark puts the caller to sleep and calls
// commitSleep to decide whether to immediately
// wake the caller up or to leave it sleeping.
const traceEvGoBlockSelect = 24
gopark(commitSleep, &s.waitingG, "sleeper", traceEvGoBlockSelect, 0)
}
// Pull the shared list out and reverse it in the local
// list. Given that wakers push themselves in reverse
// order, we fix things here.
v := (*Waker)(atomic.SwapPointer(&s.sharedList, nil))
for v != nil {
cur := v
v = v.next
cur.next = s.localList
s.localList = cur
}
}
// Remove the waker in the front of the list.
w := s.localList
s.localList = w.next
return w
} | go | func (s *Sleeper) nextWaker(block bool) *Waker {
// Attempt to replenish the local list if it's currently empty.
if s.localList == nil {
for atomic.LoadPointer(&s.sharedList) == nil {
// Fail request if caller requested that we
// don't block.
if !block {
return nil
}
// Indicate to wakers that we're about to sleep,
// this allows them to abort the wait by setting
// waitingG back to zero (which we'll notice
// before committing the sleep).
atomic.StoreUintptr(&s.waitingG, preparingG)
// Check if something was queued while we were
// preparing to sleep. We need this interleaving
// to avoid missing wake ups.
if atomic.LoadPointer(&s.sharedList) != nil {
atomic.StoreUintptr(&s.waitingG, 0)
break
}
// Try to commit the sleep and report it to the
// tracer as a select.
//
// gopark puts the caller to sleep and calls
// commitSleep to decide whether to immediately
// wake the caller up or to leave it sleeping.
const traceEvGoBlockSelect = 24
gopark(commitSleep, &s.waitingG, "sleeper", traceEvGoBlockSelect, 0)
}
// Pull the shared list out and reverse it in the local
// list. Given that wakers push themselves in reverse
// order, we fix things here.
v := (*Waker)(atomic.SwapPointer(&s.sharedList, nil))
for v != nil {
cur := v
v = v.next
cur.next = s.localList
s.localList = cur
}
}
// Remove the waker in the front of the list.
w := s.localList
s.localList = w.next
return w
} | [
"func",
"(",
"s",
"*",
"Sleeper",
")",
"nextWaker",
"(",
"block",
"bool",
")",
"*",
"Waker",
"{",
"// Attempt to replenish the local list if it's currently empty.",
"if",
"s",
".",
"localList",
"==",
"nil",
"{",
"for",
"atomic",
".",
"LoadPointer",
"(",
"&",
"s",
".",
"sharedList",
")",
"==",
"nil",
"{",
"// Fail request if caller requested that we",
"// don't block.",
"if",
"!",
"block",
"{",
"return",
"nil",
"\n",
"}",
"\n\n",
"// Indicate to wakers that we're about to sleep,",
"// this allows them to abort the wait by setting",
"// waitingG back to zero (which we'll notice",
"// before committing the sleep).",
"atomic",
".",
"StoreUintptr",
"(",
"&",
"s",
".",
"waitingG",
",",
"preparingG",
")",
"\n\n",
"// Check if something was queued while we were",
"// preparing to sleep. We need this interleaving",
"// to avoid missing wake ups.",
"if",
"atomic",
".",
"LoadPointer",
"(",
"&",
"s",
".",
"sharedList",
")",
"!=",
"nil",
"{",
"atomic",
".",
"StoreUintptr",
"(",
"&",
"s",
".",
"waitingG",
",",
"0",
")",
"\n",
"break",
"\n",
"}",
"\n\n",
"// Try to commit the sleep and report it to the",
"// tracer as a select.",
"//",
"// gopark puts the caller to sleep and calls",
"// commitSleep to decide whether to immediately",
"// wake the caller up or to leave it sleeping.",
"const",
"traceEvGoBlockSelect",
"=",
"24",
"\n",
"gopark",
"(",
"commitSleep",
",",
"&",
"s",
".",
"waitingG",
",",
"\"",
"\"",
",",
"traceEvGoBlockSelect",
",",
"0",
")",
"\n",
"}",
"\n\n",
"// Pull the shared list out and reverse it in the local",
"// list. Given that wakers push themselves in reverse",
"// order, we fix things here.",
"v",
":=",
"(",
"*",
"Waker",
")",
"(",
"atomic",
".",
"SwapPointer",
"(",
"&",
"s",
".",
"sharedList",
",",
"nil",
")",
")",
"\n",
"for",
"v",
"!=",
"nil",
"{",
"cur",
":=",
"v",
"\n",
"v",
"=",
"v",
".",
"next",
"\n\n",
"cur",
".",
"next",
"=",
"s",
".",
"localList",
"\n",
"s",
".",
"localList",
"=",
"cur",
"\n",
"}",
"\n",
"}",
"\n\n",
"// Remove the waker in the front of the list.",
"w",
":=",
"s",
".",
"localList",
"\n",
"s",
".",
"localList",
"=",
"w",
".",
"next",
"\n\n",
"return",
"w",
"\n",
"}"
] | // nextWaker returns the next waker in the notification list, blocking if
// needed. | [
"nextWaker",
"returns",
"the",
"next",
"waker",
"in",
"the",
"notification",
"list",
"blocking",
"if",
"needed",
"."
] | 70ebca9c30730cf3887cdef3b85bb96ed7a97593 | https://github.com/google/netstack/blob/70ebca9c30730cf3887cdef3b85bb96ed7a97593/sleep/sleep_unsafe.go#L151-L203 | train |
google/netstack | sleep/sleep_unsafe.go | enqueueAssertedWaker | func (s *Sleeper) enqueueAssertedWaker(w *Waker) {
// Add the new waker to the front of the list.
for {
v := (*Waker)(atomic.LoadPointer(&s.sharedList))
w.next = v
if atomic.CompareAndSwapPointer(&s.sharedList, uwaker(v), uwaker(w)) {
break
}
}
for {
// Nothing to do if there isn't a G waiting.
g := atomic.LoadUintptr(&s.waitingG)
if g == 0 {
return
}
// Signal to the sleeper that a waker has been asserted.
if atomic.CompareAndSwapUintptr(&s.waitingG, g, 0) {
if g != preparingG {
// We managed to get a G. Wake it up.
goready(g, 0)
}
}
}
} | go | func (s *Sleeper) enqueueAssertedWaker(w *Waker) {
// Add the new waker to the front of the list.
for {
v := (*Waker)(atomic.LoadPointer(&s.sharedList))
w.next = v
if atomic.CompareAndSwapPointer(&s.sharedList, uwaker(v), uwaker(w)) {
break
}
}
for {
// Nothing to do if there isn't a G waiting.
g := atomic.LoadUintptr(&s.waitingG)
if g == 0 {
return
}
// Signal to the sleeper that a waker has been asserted.
if atomic.CompareAndSwapUintptr(&s.waitingG, g, 0) {
if g != preparingG {
// We managed to get a G. Wake it up.
goready(g, 0)
}
}
}
} | [
"func",
"(",
"s",
"*",
"Sleeper",
")",
"enqueueAssertedWaker",
"(",
"w",
"*",
"Waker",
")",
"{",
"// Add the new waker to the front of the list.",
"for",
"{",
"v",
":=",
"(",
"*",
"Waker",
")",
"(",
"atomic",
".",
"LoadPointer",
"(",
"&",
"s",
".",
"sharedList",
")",
")",
"\n",
"w",
".",
"next",
"=",
"v",
"\n",
"if",
"atomic",
".",
"CompareAndSwapPointer",
"(",
"&",
"s",
".",
"sharedList",
",",
"uwaker",
"(",
"v",
")",
",",
"uwaker",
"(",
"w",
")",
")",
"{",
"break",
"\n",
"}",
"\n",
"}",
"\n\n",
"for",
"{",
"// Nothing to do if there isn't a G waiting.",
"g",
":=",
"atomic",
".",
"LoadUintptr",
"(",
"&",
"s",
".",
"waitingG",
")",
"\n",
"if",
"g",
"==",
"0",
"{",
"return",
"\n",
"}",
"\n\n",
"// Signal to the sleeper that a waker has been asserted.",
"if",
"atomic",
".",
"CompareAndSwapUintptr",
"(",
"&",
"s",
".",
"waitingG",
",",
"g",
",",
"0",
")",
"{",
"if",
"g",
"!=",
"preparingG",
"{",
"// We managed to get a G. Wake it up.",
"goready",
"(",
"g",
",",
"0",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"}"
] | // enqueueAssertedWaker enqueues an asserted waker to the "ready" circular list
// of wakers that want to notify the sleeper. | [
"enqueueAssertedWaker",
"enqueues",
"an",
"asserted",
"waker",
"to",
"the",
"ready",
"circular",
"list",
"of",
"wakers",
"that",
"want",
"to",
"notify",
"the",
"sleeper",
"."
] | 70ebca9c30730cf3887cdef3b85bb96ed7a97593 | https://github.com/google/netstack/blob/70ebca9c30730cf3887cdef3b85bb96ed7a97593/sleep/sleep_unsafe.go#L284-L309 | train |
google/netstack | sleep/sleep_unsafe.go | Assert | func (w *Waker) Assert() {
// Nothing to do if the waker is already asserted. This check allows us
// to complete this case (already asserted) without any interlocked
// operations on x86.
if atomic.LoadPointer(&w.s) == usleeper(&assertedSleeper) {
return
}
// Mark the waker as asserted, and wake up a sleeper if there is one.
switch s := (*Sleeper)(atomic.SwapPointer(&w.s, usleeper(&assertedSleeper))); s {
case nil:
case &assertedSleeper:
default:
s.enqueueAssertedWaker(w)
}
} | go | func (w *Waker) Assert() {
// Nothing to do if the waker is already asserted. This check allows us
// to complete this case (already asserted) without any interlocked
// operations on x86.
if atomic.LoadPointer(&w.s) == usleeper(&assertedSleeper) {
return
}
// Mark the waker as asserted, and wake up a sleeper if there is one.
switch s := (*Sleeper)(atomic.SwapPointer(&w.s, usleeper(&assertedSleeper))); s {
case nil:
case &assertedSleeper:
default:
s.enqueueAssertedWaker(w)
}
} | [
"func",
"(",
"w",
"*",
"Waker",
")",
"Assert",
"(",
")",
"{",
"// Nothing to do if the waker is already asserted. This check allows us",
"// to complete this case (already asserted) without any interlocked",
"// operations on x86.",
"if",
"atomic",
".",
"LoadPointer",
"(",
"&",
"w",
".",
"s",
")",
"==",
"usleeper",
"(",
"&",
"assertedSleeper",
")",
"{",
"return",
"\n",
"}",
"\n\n",
"// Mark the waker as asserted, and wake up a sleeper if there is one.",
"switch",
"s",
":=",
"(",
"*",
"Sleeper",
")",
"(",
"atomic",
".",
"SwapPointer",
"(",
"&",
"w",
".",
"s",
",",
"usleeper",
"(",
"&",
"assertedSleeper",
")",
")",
")",
";",
"s",
"{",
"case",
"nil",
":",
"case",
"&",
"assertedSleeper",
":",
"default",
":",
"s",
".",
"enqueueAssertedWaker",
"(",
"w",
")",
"\n",
"}",
"\n",
"}"
] | // Assert moves the waker to an asserted state, if it isn't asserted yet. When
// asserted, the waker will cause its matching sleeper to wake up. | [
"Assert",
"moves",
"the",
"waker",
"to",
"an",
"asserted",
"state",
"if",
"it",
"isn",
"t",
"asserted",
"yet",
".",
"When",
"asserted",
"the",
"waker",
"will",
"cause",
"its",
"matching",
"sleeper",
"to",
"wake",
"up",
"."
] | 70ebca9c30730cf3887cdef3b85bb96ed7a97593 | https://github.com/google/netstack/blob/70ebca9c30730cf3887cdef3b85bb96ed7a97593/sleep/sleep_unsafe.go#L347-L362 | train |
google/netstack | tcpip/stack/registration.go | RegisterLinkEndpoint | func RegisterLinkEndpoint(linkEP LinkEndpoint) tcpip.LinkEndpointID {
linkEPMu.Lock()
defer linkEPMu.Unlock()
v := nextLinkEndpointID
nextLinkEndpointID++
linkEndpoints[v] = linkEP
return v
} | go | func RegisterLinkEndpoint(linkEP LinkEndpoint) tcpip.LinkEndpointID {
linkEPMu.Lock()
defer linkEPMu.Unlock()
v := nextLinkEndpointID
nextLinkEndpointID++
linkEndpoints[v] = linkEP
return v
} | [
"func",
"RegisterLinkEndpoint",
"(",
"linkEP",
"LinkEndpoint",
")",
"tcpip",
".",
"LinkEndpointID",
"{",
"linkEPMu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"linkEPMu",
".",
"Unlock",
"(",
")",
"\n\n",
"v",
":=",
"nextLinkEndpointID",
"\n",
"nextLinkEndpointID",
"++",
"\n\n",
"linkEndpoints",
"[",
"v",
"]",
"=",
"linkEP",
"\n\n",
"return",
"v",
"\n",
"}"
] | // RegisterLinkEndpoint register a link-layer protocol endpoint and returns an
// ID that can be used to refer to it. | [
"RegisterLinkEndpoint",
"register",
"a",
"link",
"-",
"layer",
"protocol",
"endpoint",
"and",
"returns",
"an",
"ID",
"that",
"can",
"be",
"used",
"to",
"refer",
"to",
"it",
"."
] | 70ebca9c30730cf3887cdef3b85bb96ed7a97593 | https://github.com/google/netstack/blob/70ebca9c30730cf3887cdef3b85bb96ed7a97593/tcpip/stack/registration.go#L385-L395 | train |
google/netstack | tcpip/stack/registration.go | FindLinkEndpoint | func FindLinkEndpoint(id tcpip.LinkEndpointID) LinkEndpoint {
linkEPMu.RLock()
defer linkEPMu.RUnlock()
return linkEndpoints[id]
} | go | func FindLinkEndpoint(id tcpip.LinkEndpointID) LinkEndpoint {
linkEPMu.RLock()
defer linkEPMu.RUnlock()
return linkEndpoints[id]
} | [
"func",
"FindLinkEndpoint",
"(",
"id",
"tcpip",
".",
"LinkEndpointID",
")",
"LinkEndpoint",
"{",
"linkEPMu",
".",
"RLock",
"(",
")",
"\n",
"defer",
"linkEPMu",
".",
"RUnlock",
"(",
")",
"\n\n",
"return",
"linkEndpoints",
"[",
"id",
"]",
"\n",
"}"
] | // FindLinkEndpoint finds the link endpoint associated with the given ID. | [
"FindLinkEndpoint",
"finds",
"the",
"link",
"endpoint",
"associated",
"with",
"the",
"given",
"ID",
"."
] | 70ebca9c30730cf3887cdef3b85bb96ed7a97593 | https://github.com/google/netstack/blob/70ebca9c30730cf3887cdef3b85bb96ed7a97593/tcpip/stack/registration.go#L398-L403 | train |
google/netstack | tcpip/link/sharedmem/rx.go | init | func (r *rx) init(mtu uint32, c *QueueConfig) error {
// Map in all buffers.
txPipe, err := getBuffer(c.TxPipeFD)
if err != nil {
return err
}
rxPipe, err := getBuffer(c.RxPipeFD)
if err != nil {
syscall.Munmap(txPipe)
return err
}
data, err := getBuffer(c.DataFD)
if err != nil {
syscall.Munmap(txPipe)
syscall.Munmap(rxPipe)
return err
}
sharedData, err := getBuffer(c.SharedDataFD)
if err != nil {
syscall.Munmap(txPipe)
syscall.Munmap(rxPipe)
syscall.Munmap(data)
return err
}
// Duplicate the eventFD so that caller can close it but we can still
// use it.
efd, err := syscall.Dup(c.EventFD)
if err != nil {
syscall.Munmap(txPipe)
syscall.Munmap(rxPipe)
syscall.Munmap(data)
syscall.Munmap(sharedData)
return err
}
// Set the eventfd as non-blocking.
if err := syscall.SetNonblock(efd, true); err != nil {
syscall.Munmap(txPipe)
syscall.Munmap(rxPipe)
syscall.Munmap(data)
syscall.Munmap(sharedData)
syscall.Close(efd)
return err
}
// Initialize state based on buffers.
r.q.Init(txPipe, rxPipe, sharedDataPointer(sharedData))
r.data = data
r.eventFD = efd
r.sharedData = sharedData
return nil
} | go | func (r *rx) init(mtu uint32, c *QueueConfig) error {
// Map in all buffers.
txPipe, err := getBuffer(c.TxPipeFD)
if err != nil {
return err
}
rxPipe, err := getBuffer(c.RxPipeFD)
if err != nil {
syscall.Munmap(txPipe)
return err
}
data, err := getBuffer(c.DataFD)
if err != nil {
syscall.Munmap(txPipe)
syscall.Munmap(rxPipe)
return err
}
sharedData, err := getBuffer(c.SharedDataFD)
if err != nil {
syscall.Munmap(txPipe)
syscall.Munmap(rxPipe)
syscall.Munmap(data)
return err
}
// Duplicate the eventFD so that caller can close it but we can still
// use it.
efd, err := syscall.Dup(c.EventFD)
if err != nil {
syscall.Munmap(txPipe)
syscall.Munmap(rxPipe)
syscall.Munmap(data)
syscall.Munmap(sharedData)
return err
}
// Set the eventfd as non-blocking.
if err := syscall.SetNonblock(efd, true); err != nil {
syscall.Munmap(txPipe)
syscall.Munmap(rxPipe)
syscall.Munmap(data)
syscall.Munmap(sharedData)
syscall.Close(efd)
return err
}
// Initialize state based on buffers.
r.q.Init(txPipe, rxPipe, sharedDataPointer(sharedData))
r.data = data
r.eventFD = efd
r.sharedData = sharedData
return nil
} | [
"func",
"(",
"r",
"*",
"rx",
")",
"init",
"(",
"mtu",
"uint32",
",",
"c",
"*",
"QueueConfig",
")",
"error",
"{",
"// Map in all buffers.",
"txPipe",
",",
"err",
":=",
"getBuffer",
"(",
"c",
".",
"TxPipeFD",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"rxPipe",
",",
"err",
":=",
"getBuffer",
"(",
"c",
".",
"RxPipeFD",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"syscall",
".",
"Munmap",
"(",
"txPipe",
")",
"\n",
"return",
"err",
"\n",
"}",
"\n\n",
"data",
",",
"err",
":=",
"getBuffer",
"(",
"c",
".",
"DataFD",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"syscall",
".",
"Munmap",
"(",
"txPipe",
")",
"\n",
"syscall",
".",
"Munmap",
"(",
"rxPipe",
")",
"\n",
"return",
"err",
"\n",
"}",
"\n\n",
"sharedData",
",",
"err",
":=",
"getBuffer",
"(",
"c",
".",
"SharedDataFD",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"syscall",
".",
"Munmap",
"(",
"txPipe",
")",
"\n",
"syscall",
".",
"Munmap",
"(",
"rxPipe",
")",
"\n",
"syscall",
".",
"Munmap",
"(",
"data",
")",
"\n",
"return",
"err",
"\n",
"}",
"\n\n",
"// Duplicate the eventFD so that caller can close it but we can still",
"// use it.",
"efd",
",",
"err",
":=",
"syscall",
".",
"Dup",
"(",
"c",
".",
"EventFD",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"syscall",
".",
"Munmap",
"(",
"txPipe",
")",
"\n",
"syscall",
".",
"Munmap",
"(",
"rxPipe",
")",
"\n",
"syscall",
".",
"Munmap",
"(",
"data",
")",
"\n",
"syscall",
".",
"Munmap",
"(",
"sharedData",
")",
"\n",
"return",
"err",
"\n",
"}",
"\n\n",
"// Set the eventfd as non-blocking.",
"if",
"err",
":=",
"syscall",
".",
"SetNonblock",
"(",
"efd",
",",
"true",
")",
";",
"err",
"!=",
"nil",
"{",
"syscall",
".",
"Munmap",
"(",
"txPipe",
")",
"\n",
"syscall",
".",
"Munmap",
"(",
"rxPipe",
")",
"\n",
"syscall",
".",
"Munmap",
"(",
"data",
")",
"\n",
"syscall",
".",
"Munmap",
"(",
"sharedData",
")",
"\n",
"syscall",
".",
"Close",
"(",
"efd",
")",
"\n",
"return",
"err",
"\n",
"}",
"\n\n",
"// Initialize state based on buffers.",
"r",
".",
"q",
".",
"Init",
"(",
"txPipe",
",",
"rxPipe",
",",
"sharedDataPointer",
"(",
"sharedData",
")",
")",
"\n",
"r",
".",
"data",
"=",
"data",
"\n",
"r",
".",
"eventFD",
"=",
"efd",
"\n",
"r",
".",
"sharedData",
"=",
"sharedData",
"\n\n",
"return",
"nil",
"\n",
"}"
] | // init initializes all state needed by the rx queue based on the information
// provided.
//
// The caller always retains ownership of all file descriptors passed in. The
// queue implementation will duplicate any that it may need in the future. | [
"init",
"initializes",
"all",
"state",
"needed",
"by",
"the",
"rx",
"queue",
"based",
"on",
"the",
"information",
"provided",
".",
"The",
"caller",
"always",
"retains",
"ownership",
"of",
"all",
"file",
"descriptors",
"passed",
"in",
".",
"The",
"queue",
"implementation",
"will",
"duplicate",
"any",
"that",
"it",
"may",
"need",
"in",
"the",
"future",
"."
] | 70ebca9c30730cf3887cdef3b85bb96ed7a97593 | https://github.com/google/netstack/blob/70ebca9c30730cf3887cdef3b85bb96ed7a97593/tcpip/link/sharedmem/rx.go#L40-L96 | train |
google/netstack | tcpip/header/tcp.go | Less | func (r SACKBlock) Less(b btree.Item) bool {
return r.Start.LessThan(b.(SACKBlock).Start)
} | go | func (r SACKBlock) Less(b btree.Item) bool {
return r.Start.LessThan(b.(SACKBlock).Start)
} | [
"func",
"(",
"r",
"SACKBlock",
")",
"Less",
"(",
"b",
"btree",
".",
"Item",
")",
"bool",
"{",
"return",
"r",
".",
"Start",
".",
"LessThan",
"(",
"b",
".",
"(",
"SACKBlock",
")",
".",
"Start",
")",
"\n",
"}"
] | // Less returns true if r.Start < b.Start. | [
"Less",
"returns",
"true",
"if",
"r",
".",
"Start",
"<",
"b",
".",
"Start",
"."
] | 70ebca9c30730cf3887cdef3b85bb96ed7a97593 | https://github.com/google/netstack/blob/70ebca9c30730cf3887cdef3b85bb96ed7a97593/tcpip/header/tcp.go#L137-L139 | train |
google/netstack | tcpip/header/tcp.go | Contains | func (r SACKBlock) Contains(b SACKBlock) bool {
return r.Start.LessThanEq(b.Start) && b.End.LessThanEq(r.End)
} | go | func (r SACKBlock) Contains(b SACKBlock) bool {
return r.Start.LessThanEq(b.Start) && b.End.LessThanEq(r.End)
} | [
"func",
"(",
"r",
"SACKBlock",
")",
"Contains",
"(",
"b",
"SACKBlock",
")",
"bool",
"{",
"return",
"r",
".",
"Start",
".",
"LessThanEq",
"(",
"b",
".",
"Start",
")",
"&&",
"b",
".",
"End",
".",
"LessThanEq",
"(",
"r",
".",
"End",
")",
"\n",
"}"
] | // Contains returns true if b is completely contained in r. | [
"Contains",
"returns",
"true",
"if",
"b",
"is",
"completely",
"contained",
"in",
"r",
"."
] | 70ebca9c30730cf3887cdef3b85bb96ed7a97593 | https://github.com/google/netstack/blob/70ebca9c30730cf3887cdef3b85bb96ed7a97593/tcpip/header/tcp.go#L142-L144 | train |
google/netstack | tcpip/header/tcp.go | SetSourcePort | func (b TCP) SetSourcePort(port uint16) {
binary.BigEndian.PutUint16(b[TCPSrcPortOffset:], port)
} | go | func (b TCP) SetSourcePort(port uint16) {
binary.BigEndian.PutUint16(b[TCPSrcPortOffset:], port)
} | [
"func",
"(",
"b",
"TCP",
")",
"SetSourcePort",
"(",
"port",
"uint16",
")",
"{",
"binary",
".",
"BigEndian",
".",
"PutUint16",
"(",
"b",
"[",
"TCPSrcPortOffset",
":",
"]",
",",
"port",
")",
"\n",
"}"
] | // SetSourcePort sets the "source port" field of the tcp header. | [
"SetSourcePort",
"sets",
"the",
"source",
"port",
"field",
"of",
"the",
"tcp",
"header",
"."
] | 70ebca9c30730cf3887cdef3b85bb96ed7a97593 | https://github.com/google/netstack/blob/70ebca9c30730cf3887cdef3b85bb96ed7a97593/tcpip/header/tcp.go#L227-L229 | train |
google/netstack | tcpip/header/tcp.go | SetDestinationPort | func (b TCP) SetDestinationPort(port uint16) {
binary.BigEndian.PutUint16(b[TCPDstPortOffset:], port)
} | go | func (b TCP) SetDestinationPort(port uint16) {
binary.BigEndian.PutUint16(b[TCPDstPortOffset:], port)
} | [
"func",
"(",
"b",
"TCP",
")",
"SetDestinationPort",
"(",
"port",
"uint16",
")",
"{",
"binary",
".",
"BigEndian",
".",
"PutUint16",
"(",
"b",
"[",
"TCPDstPortOffset",
":",
"]",
",",
"port",
")",
"\n",
"}"
] | // SetDestinationPort sets the "destination port" field of the tcp header. | [
"SetDestinationPort",
"sets",
"the",
"destination",
"port",
"field",
"of",
"the",
"tcp",
"header",
"."
] | 70ebca9c30730cf3887cdef3b85bb96ed7a97593 | https://github.com/google/netstack/blob/70ebca9c30730cf3887cdef3b85bb96ed7a97593/tcpip/header/tcp.go#L232-L234 | train |
google/netstack | tcpip/header/tcp.go | SetChecksum | func (b TCP) SetChecksum(checksum uint16) {
binary.BigEndian.PutUint16(b[TCPChecksumOffset:], checksum)
} | go | func (b TCP) SetChecksum(checksum uint16) {
binary.BigEndian.PutUint16(b[TCPChecksumOffset:], checksum)
} | [
"func",
"(",
"b",
"TCP",
")",
"SetChecksum",
"(",
"checksum",
"uint16",
")",
"{",
"binary",
".",
"BigEndian",
".",
"PutUint16",
"(",
"b",
"[",
"TCPChecksumOffset",
":",
"]",
",",
"checksum",
")",
"\n",
"}"
] | // SetChecksum sets the checksum field of the tcp header. | [
"SetChecksum",
"sets",
"the",
"checksum",
"field",
"of",
"the",
"tcp",
"header",
"."
] | 70ebca9c30730cf3887cdef3b85bb96ed7a97593 | https://github.com/google/netstack/blob/70ebca9c30730cf3887cdef3b85bb96ed7a97593/tcpip/header/tcp.go#L237-L239 | train |
google/netstack | tcpip/header/tcp.go | CalculateChecksum | func (b TCP) CalculateChecksum(partialChecksum uint16) uint16 {
// Calculate the rest of the checksum.
return Checksum(b[:b.DataOffset()], partialChecksum)
} | go | func (b TCP) CalculateChecksum(partialChecksum uint16) uint16 {
// Calculate the rest of the checksum.
return Checksum(b[:b.DataOffset()], partialChecksum)
} | [
"func",
"(",
"b",
"TCP",
")",
"CalculateChecksum",
"(",
"partialChecksum",
"uint16",
")",
"uint16",
"{",
"// Calculate the rest of the checksum.",
"return",
"Checksum",
"(",
"b",
"[",
":",
"b",
".",
"DataOffset",
"(",
")",
"]",
",",
"partialChecksum",
")",
"\n",
"}"
] | // CalculateChecksum calculates the checksum of the tcp segment.
// partialChecksum is the checksum of the network-layer pseudo-header
// and the checksum of the segment data. | [
"CalculateChecksum",
"calculates",
"the",
"checksum",
"of",
"the",
"tcp",
"segment",
".",
"partialChecksum",
"is",
"the",
"checksum",
"of",
"the",
"network",
"-",
"layer",
"pseudo",
"-",
"header",
"and",
"the",
"checksum",
"of",
"the",
"segment",
"data",
"."
] | 70ebca9c30730cf3887cdef3b85bb96ed7a97593 | https://github.com/google/netstack/blob/70ebca9c30730cf3887cdef3b85bb96ed7a97593/tcpip/header/tcp.go#L244-L247 | train |
google/netstack | tcpip/header/tcp.go | Encode | func (b TCP) Encode(t *TCPFields) {
b.encodeSubset(t.SeqNum, t.AckNum, t.Flags, t.WindowSize)
binary.BigEndian.PutUint16(b[TCPSrcPortOffset:], t.SrcPort)
binary.BigEndian.PutUint16(b[TCPDstPortOffset:], t.DstPort)
b[TCPDataOffset] = (t.DataOffset / 4) << 4
binary.BigEndian.PutUint16(b[TCPChecksumOffset:], t.Checksum)
binary.BigEndian.PutUint16(b[TCPUrgentPtrOffset:], t.UrgentPointer)
} | go | func (b TCP) Encode(t *TCPFields) {
b.encodeSubset(t.SeqNum, t.AckNum, t.Flags, t.WindowSize)
binary.BigEndian.PutUint16(b[TCPSrcPortOffset:], t.SrcPort)
binary.BigEndian.PutUint16(b[TCPDstPortOffset:], t.DstPort)
b[TCPDataOffset] = (t.DataOffset / 4) << 4
binary.BigEndian.PutUint16(b[TCPChecksumOffset:], t.Checksum)
binary.BigEndian.PutUint16(b[TCPUrgentPtrOffset:], t.UrgentPointer)
} | [
"func",
"(",
"b",
"TCP",
")",
"Encode",
"(",
"t",
"*",
"TCPFields",
")",
"{",
"b",
".",
"encodeSubset",
"(",
"t",
".",
"SeqNum",
",",
"t",
".",
"AckNum",
",",
"t",
".",
"Flags",
",",
"t",
".",
"WindowSize",
")",
"\n",
"binary",
".",
"BigEndian",
".",
"PutUint16",
"(",
"b",
"[",
"TCPSrcPortOffset",
":",
"]",
",",
"t",
".",
"SrcPort",
")",
"\n",
"binary",
".",
"BigEndian",
".",
"PutUint16",
"(",
"b",
"[",
"TCPDstPortOffset",
":",
"]",
",",
"t",
".",
"DstPort",
")",
"\n",
"b",
"[",
"TCPDataOffset",
"]",
"=",
"(",
"t",
".",
"DataOffset",
"/",
"4",
")",
"<<",
"4",
"\n",
"binary",
".",
"BigEndian",
".",
"PutUint16",
"(",
"b",
"[",
"TCPChecksumOffset",
":",
"]",
",",
"t",
".",
"Checksum",
")",
"\n",
"binary",
".",
"BigEndian",
".",
"PutUint16",
"(",
"b",
"[",
"TCPUrgentPtrOffset",
":",
"]",
",",
"t",
".",
"UrgentPointer",
")",
"\n",
"}"
] | // Encode encodes all the fields of the tcp header. | [
"Encode",
"encodes",
"all",
"the",
"fields",
"of",
"the",
"tcp",
"header",
"."
] | 70ebca9c30730cf3887cdef3b85bb96ed7a97593 | https://github.com/google/netstack/blob/70ebca9c30730cf3887cdef3b85bb96ed7a97593/tcpip/header/tcp.go#L269-L276 | train |
google/netstack | tcpip/header/tcp.go | EncodePartial | func (b TCP) EncodePartial(partialChecksum, length uint16, seqnum, acknum uint32, flags byte, rcvwnd uint16) {
// Add the total length and "flags" field contributions to the checksum.
// We don't use the flags field directly from the header because it's a
// one-byte field with an odd offset, so it would be accounted for
// incorrectly by the Checksum routine.
tmp := make([]byte, 4)
binary.BigEndian.PutUint16(tmp, length)
binary.BigEndian.PutUint16(tmp[2:], uint16(flags))
checksum := Checksum(tmp, partialChecksum)
// Encode the passed-in fields.
b.encodeSubset(seqnum, acknum, flags, rcvwnd)
// Add the contributions of the passed-in fields to the checksum.
checksum = Checksum(b[TCPSeqNumOffset:TCPSeqNumOffset+8], checksum)
checksum = Checksum(b[TCPWinSizeOffset:TCPWinSizeOffset+2], checksum)
// Encode the checksum.
b.SetChecksum(^checksum)
} | go | func (b TCP) EncodePartial(partialChecksum, length uint16, seqnum, acknum uint32, flags byte, rcvwnd uint16) {
// Add the total length and "flags" field contributions to the checksum.
// We don't use the flags field directly from the header because it's a
// one-byte field with an odd offset, so it would be accounted for
// incorrectly by the Checksum routine.
tmp := make([]byte, 4)
binary.BigEndian.PutUint16(tmp, length)
binary.BigEndian.PutUint16(tmp[2:], uint16(flags))
checksum := Checksum(tmp, partialChecksum)
// Encode the passed-in fields.
b.encodeSubset(seqnum, acknum, flags, rcvwnd)
// Add the contributions of the passed-in fields to the checksum.
checksum = Checksum(b[TCPSeqNumOffset:TCPSeqNumOffset+8], checksum)
checksum = Checksum(b[TCPWinSizeOffset:TCPWinSizeOffset+2], checksum)
// Encode the checksum.
b.SetChecksum(^checksum)
} | [
"func",
"(",
"b",
"TCP",
")",
"EncodePartial",
"(",
"partialChecksum",
",",
"length",
"uint16",
",",
"seqnum",
",",
"acknum",
"uint32",
",",
"flags",
"byte",
",",
"rcvwnd",
"uint16",
")",
"{",
"// Add the total length and \"flags\" field contributions to the checksum.",
"// We don't use the flags field directly from the header because it's a",
"// one-byte field with an odd offset, so it would be accounted for",
"// incorrectly by the Checksum routine.",
"tmp",
":=",
"make",
"(",
"[",
"]",
"byte",
",",
"4",
")",
"\n",
"binary",
".",
"BigEndian",
".",
"PutUint16",
"(",
"tmp",
",",
"length",
")",
"\n",
"binary",
".",
"BigEndian",
".",
"PutUint16",
"(",
"tmp",
"[",
"2",
":",
"]",
",",
"uint16",
"(",
"flags",
")",
")",
"\n",
"checksum",
":=",
"Checksum",
"(",
"tmp",
",",
"partialChecksum",
")",
"\n\n",
"// Encode the passed-in fields.",
"b",
".",
"encodeSubset",
"(",
"seqnum",
",",
"acknum",
",",
"flags",
",",
"rcvwnd",
")",
"\n\n",
"// Add the contributions of the passed-in fields to the checksum.",
"checksum",
"=",
"Checksum",
"(",
"b",
"[",
"TCPSeqNumOffset",
":",
"TCPSeqNumOffset",
"+",
"8",
"]",
",",
"checksum",
")",
"\n",
"checksum",
"=",
"Checksum",
"(",
"b",
"[",
"TCPWinSizeOffset",
":",
"TCPWinSizeOffset",
"+",
"2",
"]",
",",
"checksum",
")",
"\n\n",
"// Encode the checksum.",
"b",
".",
"SetChecksum",
"(",
"^",
"checksum",
")",
"\n",
"}"
] | // EncodePartial updates a subset of the fields of the tcp header. It is useful
// in cases when similar segments are produced. | [
"EncodePartial",
"updates",
"a",
"subset",
"of",
"the",
"fields",
"of",
"the",
"tcp",
"header",
".",
"It",
"is",
"useful",
"in",
"cases",
"when",
"similar",
"segments",
"are",
"produced",
"."
] | 70ebca9c30730cf3887cdef3b85bb96ed7a97593 | https://github.com/google/netstack/blob/70ebca9c30730cf3887cdef3b85bb96ed7a97593/tcpip/header/tcp.go#L280-L299 | train |
google/netstack | tcpip/header/tcp.go | ParseSynOptions | func ParseSynOptions(opts []byte, isAck bool) TCPSynOptions {
limit := len(opts)
synOpts := TCPSynOptions{
// Per RFC 1122, page 85: "If an MSS option is not received at
// connection setup, TCP MUST assume a default send MSS of 536."
MSS: 536,
// If no window scale option is specified, WS in options is
// returned as -1; this is because the absence of the option
// indicates that the we cannot use window scaling on the
// receive end either.
WS: -1,
}
for i := 0; i < limit; {
switch opts[i] {
case TCPOptionEOL:
i = limit
case TCPOptionNOP:
i++
case TCPOptionMSS:
if i+4 > limit || opts[i+1] != 4 {
return synOpts
}
mss := uint16(opts[i+2])<<8 | uint16(opts[i+3])
if mss == 0 {
return synOpts
}
synOpts.MSS = mss
i += 4
case TCPOptionWS:
if i+3 > limit || opts[i+1] != 3 {
return synOpts
}
ws := int(opts[i+2])
if ws > MaxWndScale {
ws = MaxWndScale
}
synOpts.WS = ws
i += 3
case TCPOptionTS:
if i+10 > limit || opts[i+1] != 10 {
return synOpts
}
synOpts.TSVal = binary.BigEndian.Uint32(opts[i+2:])
if isAck {
// If the segment is a SYN-ACK then store the Timestamp Echo Reply
// in the segment.
synOpts.TSEcr = binary.BigEndian.Uint32(opts[i+6:])
}
synOpts.TS = true
i += 10
case TCPOptionSACKPermitted:
if i+2 > limit || opts[i+1] != 2 {
return synOpts
}
synOpts.SACKPermitted = true
i += 2
default:
// We don't recognize this option, just skip over it.
if i+2 > limit {
return synOpts
}
l := int(opts[i+1])
// If the length is incorrect or if l+i overflows the
// total options length then return false.
if l < 2 || i+l > limit {
return synOpts
}
i += l
}
}
return synOpts
} | go | func ParseSynOptions(opts []byte, isAck bool) TCPSynOptions {
limit := len(opts)
synOpts := TCPSynOptions{
// Per RFC 1122, page 85: "If an MSS option is not received at
// connection setup, TCP MUST assume a default send MSS of 536."
MSS: 536,
// If no window scale option is specified, WS in options is
// returned as -1; this is because the absence of the option
// indicates that the we cannot use window scaling on the
// receive end either.
WS: -1,
}
for i := 0; i < limit; {
switch opts[i] {
case TCPOptionEOL:
i = limit
case TCPOptionNOP:
i++
case TCPOptionMSS:
if i+4 > limit || opts[i+1] != 4 {
return synOpts
}
mss := uint16(opts[i+2])<<8 | uint16(opts[i+3])
if mss == 0 {
return synOpts
}
synOpts.MSS = mss
i += 4
case TCPOptionWS:
if i+3 > limit || opts[i+1] != 3 {
return synOpts
}
ws := int(opts[i+2])
if ws > MaxWndScale {
ws = MaxWndScale
}
synOpts.WS = ws
i += 3
case TCPOptionTS:
if i+10 > limit || opts[i+1] != 10 {
return synOpts
}
synOpts.TSVal = binary.BigEndian.Uint32(opts[i+2:])
if isAck {
// If the segment is a SYN-ACK then store the Timestamp Echo Reply
// in the segment.
synOpts.TSEcr = binary.BigEndian.Uint32(opts[i+6:])
}
synOpts.TS = true
i += 10
case TCPOptionSACKPermitted:
if i+2 > limit || opts[i+1] != 2 {
return synOpts
}
synOpts.SACKPermitted = true
i += 2
default:
// We don't recognize this option, just skip over it.
if i+2 > limit {
return synOpts
}
l := int(opts[i+1])
// If the length is incorrect or if l+i overflows the
// total options length then return false.
if l < 2 || i+l > limit {
return synOpts
}
i += l
}
}
return synOpts
} | [
"func",
"ParseSynOptions",
"(",
"opts",
"[",
"]",
"byte",
",",
"isAck",
"bool",
")",
"TCPSynOptions",
"{",
"limit",
":=",
"len",
"(",
"opts",
")",
"\n\n",
"synOpts",
":=",
"TCPSynOptions",
"{",
"// Per RFC 1122, page 85: \"If an MSS option is not received at",
"// connection setup, TCP MUST assume a default send MSS of 536.\"",
"MSS",
":",
"536",
",",
"// If no window scale option is specified, WS in options is",
"// returned as -1; this is because the absence of the option",
"// indicates that the we cannot use window scaling on the",
"// receive end either.",
"WS",
":",
"-",
"1",
",",
"}",
"\n\n",
"for",
"i",
":=",
"0",
";",
"i",
"<",
"limit",
";",
"{",
"switch",
"opts",
"[",
"i",
"]",
"{",
"case",
"TCPOptionEOL",
":",
"i",
"=",
"limit",
"\n",
"case",
"TCPOptionNOP",
":",
"i",
"++",
"\n",
"case",
"TCPOptionMSS",
":",
"if",
"i",
"+",
"4",
">",
"limit",
"||",
"opts",
"[",
"i",
"+",
"1",
"]",
"!=",
"4",
"{",
"return",
"synOpts",
"\n",
"}",
"\n",
"mss",
":=",
"uint16",
"(",
"opts",
"[",
"i",
"+",
"2",
"]",
")",
"<<",
"8",
"|",
"uint16",
"(",
"opts",
"[",
"i",
"+",
"3",
"]",
")",
"\n",
"if",
"mss",
"==",
"0",
"{",
"return",
"synOpts",
"\n",
"}",
"\n",
"synOpts",
".",
"MSS",
"=",
"mss",
"\n",
"i",
"+=",
"4",
"\n\n",
"case",
"TCPOptionWS",
":",
"if",
"i",
"+",
"3",
">",
"limit",
"||",
"opts",
"[",
"i",
"+",
"1",
"]",
"!=",
"3",
"{",
"return",
"synOpts",
"\n",
"}",
"\n",
"ws",
":=",
"int",
"(",
"opts",
"[",
"i",
"+",
"2",
"]",
")",
"\n",
"if",
"ws",
">",
"MaxWndScale",
"{",
"ws",
"=",
"MaxWndScale",
"\n",
"}",
"\n",
"synOpts",
".",
"WS",
"=",
"ws",
"\n",
"i",
"+=",
"3",
"\n\n",
"case",
"TCPOptionTS",
":",
"if",
"i",
"+",
"10",
">",
"limit",
"||",
"opts",
"[",
"i",
"+",
"1",
"]",
"!=",
"10",
"{",
"return",
"synOpts",
"\n",
"}",
"\n",
"synOpts",
".",
"TSVal",
"=",
"binary",
".",
"BigEndian",
".",
"Uint32",
"(",
"opts",
"[",
"i",
"+",
"2",
":",
"]",
")",
"\n",
"if",
"isAck",
"{",
"// If the segment is a SYN-ACK then store the Timestamp Echo Reply",
"// in the segment.",
"synOpts",
".",
"TSEcr",
"=",
"binary",
".",
"BigEndian",
".",
"Uint32",
"(",
"opts",
"[",
"i",
"+",
"6",
":",
"]",
")",
"\n",
"}",
"\n",
"synOpts",
".",
"TS",
"=",
"true",
"\n",
"i",
"+=",
"10",
"\n",
"case",
"TCPOptionSACKPermitted",
":",
"if",
"i",
"+",
"2",
">",
"limit",
"||",
"opts",
"[",
"i",
"+",
"1",
"]",
"!=",
"2",
"{",
"return",
"synOpts",
"\n",
"}",
"\n",
"synOpts",
".",
"SACKPermitted",
"=",
"true",
"\n",
"i",
"+=",
"2",
"\n\n",
"default",
":",
"// We don't recognize this option, just skip over it.",
"if",
"i",
"+",
"2",
">",
"limit",
"{",
"return",
"synOpts",
"\n",
"}",
"\n",
"l",
":=",
"int",
"(",
"opts",
"[",
"i",
"+",
"1",
"]",
")",
"\n",
"// If the length is incorrect or if l+i overflows the",
"// total options length then return false.",
"if",
"l",
"<",
"2",
"||",
"i",
"+",
"l",
">",
"limit",
"{",
"return",
"synOpts",
"\n",
"}",
"\n",
"i",
"+=",
"l",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"synOpts",
"\n",
"}"
] | // ParseSynOptions parses the options received in a SYN segment and returns the
// relevant ones. opts should point to the option part of the TCP Header. | [
"ParseSynOptions",
"parses",
"the",
"options",
"received",
"in",
"a",
"SYN",
"segment",
"and",
"returns",
"the",
"relevant",
"ones",
".",
"opts",
"should",
"point",
"to",
"the",
"option",
"part",
"of",
"the",
"TCP",
"Header",
"."
] | 70ebca9c30730cf3887cdef3b85bb96ed7a97593 | https://github.com/google/netstack/blob/70ebca9c30730cf3887cdef3b85bb96ed7a97593/tcpip/header/tcp.go#L303-L380 | train |
google/netstack | tcpip/header/tcp.go | ParseTCPOptions | func ParseTCPOptions(b []byte) TCPOptions {
opts := TCPOptions{}
limit := len(b)
for i := 0; i < limit; {
switch b[i] {
case TCPOptionEOL:
i = limit
case TCPOptionNOP:
i++
case TCPOptionTS:
if i+10 > limit || (b[i+1] != 10) {
return opts
}
opts.TS = true
opts.TSVal = binary.BigEndian.Uint32(b[i+2:])
opts.TSEcr = binary.BigEndian.Uint32(b[i+6:])
i += 10
case TCPOptionSACK:
if i+2 > limit {
// Malformed SACK block, just return and stop parsing.
return opts
}
sackOptionLen := int(b[i+1])
if i+sackOptionLen > limit || (sackOptionLen-2)%8 != 0 {
// Malformed SACK block, just return and stop parsing.
return opts
}
numBlocks := (sackOptionLen - 2) / 8
opts.SACKBlocks = []SACKBlock{}
for j := 0; j < numBlocks; j++ {
start := binary.BigEndian.Uint32(b[i+2+j*8:])
end := binary.BigEndian.Uint32(b[i+2+j*8+4:])
opts.SACKBlocks = append(opts.SACKBlocks, SACKBlock{
Start: seqnum.Value(start),
End: seqnum.Value(end),
})
}
i += sackOptionLen
default:
// We don't recognize this option, just skip over it.
if i+2 > limit {
return opts
}
l := int(b[i+1])
// If the length is incorrect or if l+i overflows the
// total options length then return false.
if l < 2 || i+l > limit {
return opts
}
i += l
}
}
return opts
} | go | func ParseTCPOptions(b []byte) TCPOptions {
opts := TCPOptions{}
limit := len(b)
for i := 0; i < limit; {
switch b[i] {
case TCPOptionEOL:
i = limit
case TCPOptionNOP:
i++
case TCPOptionTS:
if i+10 > limit || (b[i+1] != 10) {
return opts
}
opts.TS = true
opts.TSVal = binary.BigEndian.Uint32(b[i+2:])
opts.TSEcr = binary.BigEndian.Uint32(b[i+6:])
i += 10
case TCPOptionSACK:
if i+2 > limit {
// Malformed SACK block, just return and stop parsing.
return opts
}
sackOptionLen := int(b[i+1])
if i+sackOptionLen > limit || (sackOptionLen-2)%8 != 0 {
// Malformed SACK block, just return and stop parsing.
return opts
}
numBlocks := (sackOptionLen - 2) / 8
opts.SACKBlocks = []SACKBlock{}
for j := 0; j < numBlocks; j++ {
start := binary.BigEndian.Uint32(b[i+2+j*8:])
end := binary.BigEndian.Uint32(b[i+2+j*8+4:])
opts.SACKBlocks = append(opts.SACKBlocks, SACKBlock{
Start: seqnum.Value(start),
End: seqnum.Value(end),
})
}
i += sackOptionLen
default:
// We don't recognize this option, just skip over it.
if i+2 > limit {
return opts
}
l := int(b[i+1])
// If the length is incorrect or if l+i overflows the
// total options length then return false.
if l < 2 || i+l > limit {
return opts
}
i += l
}
}
return opts
} | [
"func",
"ParseTCPOptions",
"(",
"b",
"[",
"]",
"byte",
")",
"TCPOptions",
"{",
"opts",
":=",
"TCPOptions",
"{",
"}",
"\n",
"limit",
":=",
"len",
"(",
"b",
")",
"\n",
"for",
"i",
":=",
"0",
";",
"i",
"<",
"limit",
";",
"{",
"switch",
"b",
"[",
"i",
"]",
"{",
"case",
"TCPOptionEOL",
":",
"i",
"=",
"limit",
"\n",
"case",
"TCPOptionNOP",
":",
"i",
"++",
"\n",
"case",
"TCPOptionTS",
":",
"if",
"i",
"+",
"10",
">",
"limit",
"||",
"(",
"b",
"[",
"i",
"+",
"1",
"]",
"!=",
"10",
")",
"{",
"return",
"opts",
"\n",
"}",
"\n",
"opts",
".",
"TS",
"=",
"true",
"\n",
"opts",
".",
"TSVal",
"=",
"binary",
".",
"BigEndian",
".",
"Uint32",
"(",
"b",
"[",
"i",
"+",
"2",
":",
"]",
")",
"\n",
"opts",
".",
"TSEcr",
"=",
"binary",
".",
"BigEndian",
".",
"Uint32",
"(",
"b",
"[",
"i",
"+",
"6",
":",
"]",
")",
"\n",
"i",
"+=",
"10",
"\n",
"case",
"TCPOptionSACK",
":",
"if",
"i",
"+",
"2",
">",
"limit",
"{",
"// Malformed SACK block, just return and stop parsing.",
"return",
"opts",
"\n",
"}",
"\n",
"sackOptionLen",
":=",
"int",
"(",
"b",
"[",
"i",
"+",
"1",
"]",
")",
"\n",
"if",
"i",
"+",
"sackOptionLen",
">",
"limit",
"||",
"(",
"sackOptionLen",
"-",
"2",
")",
"%",
"8",
"!=",
"0",
"{",
"// Malformed SACK block, just return and stop parsing.",
"return",
"opts",
"\n",
"}",
"\n",
"numBlocks",
":=",
"(",
"sackOptionLen",
"-",
"2",
")",
"/",
"8",
"\n",
"opts",
".",
"SACKBlocks",
"=",
"[",
"]",
"SACKBlock",
"{",
"}",
"\n",
"for",
"j",
":=",
"0",
";",
"j",
"<",
"numBlocks",
";",
"j",
"++",
"{",
"start",
":=",
"binary",
".",
"BigEndian",
".",
"Uint32",
"(",
"b",
"[",
"i",
"+",
"2",
"+",
"j",
"*",
"8",
":",
"]",
")",
"\n",
"end",
":=",
"binary",
".",
"BigEndian",
".",
"Uint32",
"(",
"b",
"[",
"i",
"+",
"2",
"+",
"j",
"*",
"8",
"+",
"4",
":",
"]",
")",
"\n",
"opts",
".",
"SACKBlocks",
"=",
"append",
"(",
"opts",
".",
"SACKBlocks",
",",
"SACKBlock",
"{",
"Start",
":",
"seqnum",
".",
"Value",
"(",
"start",
")",
",",
"End",
":",
"seqnum",
".",
"Value",
"(",
"end",
")",
",",
"}",
")",
"\n",
"}",
"\n",
"i",
"+=",
"sackOptionLen",
"\n",
"default",
":",
"// We don't recognize this option, just skip over it.",
"if",
"i",
"+",
"2",
">",
"limit",
"{",
"return",
"opts",
"\n",
"}",
"\n",
"l",
":=",
"int",
"(",
"b",
"[",
"i",
"+",
"1",
"]",
")",
"\n",
"// If the length is incorrect or if l+i overflows the",
"// total options length then return false.",
"if",
"l",
"<",
"2",
"||",
"i",
"+",
"l",
">",
"limit",
"{",
"return",
"opts",
"\n",
"}",
"\n",
"i",
"+=",
"l",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"opts",
"\n",
"}"
] | // ParseTCPOptions extracts and stores all known options in the provided byte
// slice in a TCPOptions structure. | [
"ParseTCPOptions",
"extracts",
"and",
"stores",
"all",
"known",
"options",
"in",
"the",
"provided",
"byte",
"slice",
"in",
"a",
"TCPOptions",
"structure",
"."
] | 70ebca9c30730cf3887cdef3b85bb96ed7a97593 | https://github.com/google/netstack/blob/70ebca9c30730cf3887cdef3b85bb96ed7a97593/tcpip/header/tcp.go#L384-L437 | train |
google/netstack | tcpip/header/tcp.go | EncodeMSSOption | func EncodeMSSOption(mss uint32, b []byte) int {
// mssOptionSize is the number of bytes in a valid MSS option.
const mssOptionSize = 4
if len(b) < mssOptionSize {
return 0
}
b[0], b[1], b[2], b[3] = TCPOptionMSS, mssOptionSize, byte(mss>>8), byte(mss)
return mssOptionSize
} | go | func EncodeMSSOption(mss uint32, b []byte) int {
// mssOptionSize is the number of bytes in a valid MSS option.
const mssOptionSize = 4
if len(b) < mssOptionSize {
return 0
}
b[0], b[1], b[2], b[3] = TCPOptionMSS, mssOptionSize, byte(mss>>8), byte(mss)
return mssOptionSize
} | [
"func",
"EncodeMSSOption",
"(",
"mss",
"uint32",
",",
"b",
"[",
"]",
"byte",
")",
"int",
"{",
"// mssOptionSize is the number of bytes in a valid MSS option.",
"const",
"mssOptionSize",
"=",
"4",
"\n\n",
"if",
"len",
"(",
"b",
")",
"<",
"mssOptionSize",
"{",
"return",
"0",
"\n",
"}",
"\n",
"b",
"[",
"0",
"]",
",",
"b",
"[",
"1",
"]",
",",
"b",
"[",
"2",
"]",
",",
"b",
"[",
"3",
"]",
"=",
"TCPOptionMSS",
",",
"mssOptionSize",
",",
"byte",
"(",
"mss",
">>",
"8",
")",
",",
"byte",
"(",
"mss",
")",
"\n",
"return",
"mssOptionSize",
"\n",
"}"
] | // EncodeMSSOption encodes the MSS TCP option with the provided MSS values in
// the supplied buffer. If the provided buffer is not large enough then it just
// returns without encoding anything. It returns the number of bytes written to
// the provided buffer. | [
"EncodeMSSOption",
"encodes",
"the",
"MSS",
"TCP",
"option",
"with",
"the",
"provided",
"MSS",
"values",
"in",
"the",
"supplied",
"buffer",
".",
"If",
"the",
"provided",
"buffer",
"is",
"not",
"large",
"enough",
"then",
"it",
"just",
"returns",
"without",
"encoding",
"anything",
".",
"It",
"returns",
"the",
"number",
"of",
"bytes",
"written",
"to",
"the",
"provided",
"buffer",
"."
] | 70ebca9c30730cf3887cdef3b85bb96ed7a97593 | https://github.com/google/netstack/blob/70ebca9c30730cf3887cdef3b85bb96ed7a97593/tcpip/header/tcp.go#L443-L452 | train |
google/netstack | tcpip/header/tcp.go | EncodeWSOption | func EncodeWSOption(ws int, b []byte) int {
if len(b) < 3 {
return 0
}
b[0], b[1], b[2] = TCPOptionWS, 3, uint8(ws)
return int(b[1])
} | go | func EncodeWSOption(ws int, b []byte) int {
if len(b) < 3 {
return 0
}
b[0], b[1], b[2] = TCPOptionWS, 3, uint8(ws)
return int(b[1])
} | [
"func",
"EncodeWSOption",
"(",
"ws",
"int",
",",
"b",
"[",
"]",
"byte",
")",
"int",
"{",
"if",
"len",
"(",
"b",
")",
"<",
"3",
"{",
"return",
"0",
"\n",
"}",
"\n",
"b",
"[",
"0",
"]",
",",
"b",
"[",
"1",
"]",
",",
"b",
"[",
"2",
"]",
"=",
"TCPOptionWS",
",",
"3",
",",
"uint8",
"(",
"ws",
")",
"\n",
"return",
"int",
"(",
"b",
"[",
"1",
"]",
")",
"\n",
"}"
] | // EncodeWSOption encodes the WS TCP option with the WS value in the
// provided buffer. If the provided buffer is not large enough then it just
// returns without encoding anything. It returns the number of bytes written to
// the provided buffer. | [
"EncodeWSOption",
"encodes",
"the",
"WS",
"TCP",
"option",
"with",
"the",
"WS",
"value",
"in",
"the",
"provided",
"buffer",
".",
"If",
"the",
"provided",
"buffer",
"is",
"not",
"large",
"enough",
"then",
"it",
"just",
"returns",
"without",
"encoding",
"anything",
".",
"It",
"returns",
"the",
"number",
"of",
"bytes",
"written",
"to",
"the",
"provided",
"buffer",
"."
] | 70ebca9c30730cf3887cdef3b85bb96ed7a97593 | https://github.com/google/netstack/blob/70ebca9c30730cf3887cdef3b85bb96ed7a97593/tcpip/header/tcp.go#L458-L464 | train |
google/netstack | tcpip/header/tcp.go | EncodeTSOption | func EncodeTSOption(tsVal, tsEcr uint32, b []byte) int {
if len(b) < 10 {
return 0
}
b[0], b[1] = TCPOptionTS, 10
binary.BigEndian.PutUint32(b[2:], tsVal)
binary.BigEndian.PutUint32(b[6:], tsEcr)
return int(b[1])
} | go | func EncodeTSOption(tsVal, tsEcr uint32, b []byte) int {
if len(b) < 10 {
return 0
}
b[0], b[1] = TCPOptionTS, 10
binary.BigEndian.PutUint32(b[2:], tsVal)
binary.BigEndian.PutUint32(b[6:], tsEcr)
return int(b[1])
} | [
"func",
"EncodeTSOption",
"(",
"tsVal",
",",
"tsEcr",
"uint32",
",",
"b",
"[",
"]",
"byte",
")",
"int",
"{",
"if",
"len",
"(",
"b",
")",
"<",
"10",
"{",
"return",
"0",
"\n",
"}",
"\n",
"b",
"[",
"0",
"]",
",",
"b",
"[",
"1",
"]",
"=",
"TCPOptionTS",
",",
"10",
"\n",
"binary",
".",
"BigEndian",
".",
"PutUint32",
"(",
"b",
"[",
"2",
":",
"]",
",",
"tsVal",
")",
"\n",
"binary",
".",
"BigEndian",
".",
"PutUint32",
"(",
"b",
"[",
"6",
":",
"]",
",",
"tsEcr",
")",
"\n",
"return",
"int",
"(",
"b",
"[",
"1",
"]",
")",
"\n",
"}"
] | // EncodeTSOption encodes the provided tsVal and tsEcr values as a TCP timestamp
// option into the provided buffer. If the buffer is smaller than expected it
// just returns without encoding anything. It returns the number of bytes
// written to the provided buffer. | [
"EncodeTSOption",
"encodes",
"the",
"provided",
"tsVal",
"and",
"tsEcr",
"values",
"as",
"a",
"TCP",
"timestamp",
"option",
"into",
"the",
"provided",
"buffer",
".",
"If",
"the",
"buffer",
"is",
"smaller",
"than",
"expected",
"it",
"just",
"returns",
"without",
"encoding",
"anything",
".",
"It",
"returns",
"the",
"number",
"of",
"bytes",
"written",
"to",
"the",
"provided",
"buffer",
"."
] | 70ebca9c30730cf3887cdef3b85bb96ed7a97593 | https://github.com/google/netstack/blob/70ebca9c30730cf3887cdef3b85bb96ed7a97593/tcpip/header/tcp.go#L470-L478 | train |
google/netstack | tcpip/header/tcp.go | EncodeSACKPermittedOption | func EncodeSACKPermittedOption(b []byte) int {
if len(b) < 2 {
return 0
}
b[0], b[1] = TCPOptionSACKPermitted, 2
return int(b[1])
} | go | func EncodeSACKPermittedOption(b []byte) int {
if len(b) < 2 {
return 0
}
b[0], b[1] = TCPOptionSACKPermitted, 2
return int(b[1])
} | [
"func",
"EncodeSACKPermittedOption",
"(",
"b",
"[",
"]",
"byte",
")",
"int",
"{",
"if",
"len",
"(",
"b",
")",
"<",
"2",
"{",
"return",
"0",
"\n",
"}",
"\n\n",
"b",
"[",
"0",
"]",
",",
"b",
"[",
"1",
"]",
"=",
"TCPOptionSACKPermitted",
",",
"2",
"\n",
"return",
"int",
"(",
"b",
"[",
"1",
"]",
")",
"\n",
"}"
] | // EncodeSACKPermittedOption encodes a SACKPermitted option into the provided
// buffer. If the buffer is smaller than required it just returns without
// encoding anything. It returns the number of bytes written to the provided
// buffer. | [
"EncodeSACKPermittedOption",
"encodes",
"a",
"SACKPermitted",
"option",
"into",
"the",
"provided",
"buffer",
".",
"If",
"the",
"buffer",
"is",
"smaller",
"than",
"required",
"it",
"just",
"returns",
"without",
"encoding",
"anything",
".",
"It",
"returns",
"the",
"number",
"of",
"bytes",
"written",
"to",
"the",
"provided",
"buffer",
"."
] | 70ebca9c30730cf3887cdef3b85bb96ed7a97593 | https://github.com/google/netstack/blob/70ebca9c30730cf3887cdef3b85bb96ed7a97593/tcpip/header/tcp.go#L484-L491 | train |
google/netstack | tcpip/header/tcp.go | EncodeSACKBlocks | func EncodeSACKBlocks(sackBlocks []SACKBlock, b []byte) int {
if len(sackBlocks) == 0 {
return 0
}
l := len(sackBlocks)
if l > TCPMaxSACKBlocks {
l = TCPMaxSACKBlocks
}
if ll := (len(b) - 2) / 8; ll < l {
l = ll
}
if l == 0 {
// There is not enough space in the provided buffer to add
// any SACK blocks.
return 0
}
b[0] = TCPOptionSACK
b[1] = byte(l*8 + 2)
for i := 0; i < l; i++ {
binary.BigEndian.PutUint32(b[i*8+2:], uint32(sackBlocks[i].Start))
binary.BigEndian.PutUint32(b[i*8+6:], uint32(sackBlocks[i].End))
}
return int(b[1])
} | go | func EncodeSACKBlocks(sackBlocks []SACKBlock, b []byte) int {
if len(sackBlocks) == 0 {
return 0
}
l := len(sackBlocks)
if l > TCPMaxSACKBlocks {
l = TCPMaxSACKBlocks
}
if ll := (len(b) - 2) / 8; ll < l {
l = ll
}
if l == 0 {
// There is not enough space in the provided buffer to add
// any SACK blocks.
return 0
}
b[0] = TCPOptionSACK
b[1] = byte(l*8 + 2)
for i := 0; i < l; i++ {
binary.BigEndian.PutUint32(b[i*8+2:], uint32(sackBlocks[i].Start))
binary.BigEndian.PutUint32(b[i*8+6:], uint32(sackBlocks[i].End))
}
return int(b[1])
} | [
"func",
"EncodeSACKBlocks",
"(",
"sackBlocks",
"[",
"]",
"SACKBlock",
",",
"b",
"[",
"]",
"byte",
")",
"int",
"{",
"if",
"len",
"(",
"sackBlocks",
")",
"==",
"0",
"{",
"return",
"0",
"\n",
"}",
"\n",
"l",
":=",
"len",
"(",
"sackBlocks",
")",
"\n",
"if",
"l",
">",
"TCPMaxSACKBlocks",
"{",
"l",
"=",
"TCPMaxSACKBlocks",
"\n",
"}",
"\n",
"if",
"ll",
":=",
"(",
"len",
"(",
"b",
")",
"-",
"2",
")",
"/",
"8",
";",
"ll",
"<",
"l",
"{",
"l",
"=",
"ll",
"\n",
"}",
"\n",
"if",
"l",
"==",
"0",
"{",
"// There is not enough space in the provided buffer to add",
"// any SACK blocks.",
"return",
"0",
"\n",
"}",
"\n",
"b",
"[",
"0",
"]",
"=",
"TCPOptionSACK",
"\n",
"b",
"[",
"1",
"]",
"=",
"byte",
"(",
"l",
"*",
"8",
"+",
"2",
")",
"\n",
"for",
"i",
":=",
"0",
";",
"i",
"<",
"l",
";",
"i",
"++",
"{",
"binary",
".",
"BigEndian",
".",
"PutUint32",
"(",
"b",
"[",
"i",
"*",
"8",
"+",
"2",
":",
"]",
",",
"uint32",
"(",
"sackBlocks",
"[",
"i",
"]",
".",
"Start",
")",
")",
"\n",
"binary",
".",
"BigEndian",
".",
"PutUint32",
"(",
"b",
"[",
"i",
"*",
"8",
"+",
"6",
":",
"]",
",",
"uint32",
"(",
"sackBlocks",
"[",
"i",
"]",
".",
"End",
")",
")",
"\n",
"}",
"\n",
"return",
"int",
"(",
"b",
"[",
"1",
"]",
")",
"\n",
"}"
] | // EncodeSACKBlocks encodes the provided SACK blocks as a TCP SACK option block
// in the provided slice. It tries to fit in as many blocks as possible based on
// number of bytes available in the provided buffer. It returns the number of
// bytes written to the provided buffer. | [
"EncodeSACKBlocks",
"encodes",
"the",
"provided",
"SACK",
"blocks",
"as",
"a",
"TCP",
"SACK",
"option",
"block",
"in",
"the",
"provided",
"slice",
".",
"It",
"tries",
"to",
"fit",
"in",
"as",
"many",
"blocks",
"as",
"possible",
"based",
"on",
"number",
"of",
"bytes",
"available",
"in",
"the",
"provided",
"buffer",
".",
"It",
"returns",
"the",
"number",
"of",
"bytes",
"written",
"to",
"the",
"provided",
"buffer",
"."
] | 70ebca9c30730cf3887cdef3b85bb96ed7a97593 | https://github.com/google/netstack/blob/70ebca9c30730cf3887cdef3b85bb96ed7a97593/tcpip/header/tcp.go#L497-L520 | train |
google/netstack | tcpip/header/tcp.go | AddTCPOptionPadding | func AddTCPOptionPadding(options []byte, offset int) int {
paddingToAdd := -offset & 3
// Now add any padding bytes that might be required to quad align the
// options.
for i := offset; i < offset+paddingToAdd; i++ {
options[i] = TCPOptionNOP
}
return paddingToAdd
} | go | func AddTCPOptionPadding(options []byte, offset int) int {
paddingToAdd := -offset & 3
// Now add any padding bytes that might be required to quad align the
// options.
for i := offset; i < offset+paddingToAdd; i++ {
options[i] = TCPOptionNOP
}
return paddingToAdd
} | [
"func",
"AddTCPOptionPadding",
"(",
"options",
"[",
"]",
"byte",
",",
"offset",
"int",
")",
"int",
"{",
"paddingToAdd",
":=",
"-",
"offset",
"&",
"3",
"\n",
"// Now add any padding bytes that might be required to quad align the",
"// options.",
"for",
"i",
":=",
"offset",
";",
"i",
"<",
"offset",
"+",
"paddingToAdd",
";",
"i",
"++",
"{",
"options",
"[",
"i",
"]",
"=",
"TCPOptionNOP",
"\n",
"}",
"\n",
"return",
"paddingToAdd",
"\n",
"}"
] | // AddTCPOptionPadding adds the required number of TCPOptionNOP to quad align
// the option buffer. It adds padding bytes after the offset specified and
// returns the number of padding bytes added. The passed in options slice
// must have space for the padding bytes. | [
"AddTCPOptionPadding",
"adds",
"the",
"required",
"number",
"of",
"TCPOptionNOP",
"to",
"quad",
"align",
"the",
"option",
"buffer",
".",
"It",
"adds",
"padding",
"bytes",
"after",
"the",
"offset",
"specified",
"and",
"returns",
"the",
"number",
"of",
"padding",
"bytes",
"added",
".",
"The",
"passed",
"in",
"options",
"slice",
"must",
"have",
"space",
"for",
"the",
"padding",
"bytes",
"."
] | 70ebca9c30730cf3887cdef3b85bb96ed7a97593 | https://github.com/google/netstack/blob/70ebca9c30730cf3887cdef3b85bb96ed7a97593/tcpip/header/tcp.go#L535-L543 | train |
google/netstack | tcpip/stack/transport_demuxer.go | registerEndpoint | func (d *transportDemuxer) registerEndpoint(netProtos []tcpip.NetworkProtocolNumber, protocol tcpip.TransportProtocolNumber, id TransportEndpointID, ep TransportEndpoint, reusePort bool) *tcpip.Error {
for i, n := range netProtos {
if err := d.singleRegisterEndpoint(n, protocol, id, ep, reusePort); err != nil {
d.unregisterEndpoint(netProtos[:i], protocol, id, ep)
return err
}
}
return nil
} | go | func (d *transportDemuxer) registerEndpoint(netProtos []tcpip.NetworkProtocolNumber, protocol tcpip.TransportProtocolNumber, id TransportEndpointID, ep TransportEndpoint, reusePort bool) *tcpip.Error {
for i, n := range netProtos {
if err := d.singleRegisterEndpoint(n, protocol, id, ep, reusePort); err != nil {
d.unregisterEndpoint(netProtos[:i], protocol, id, ep)
return err
}
}
return nil
} | [
"func",
"(",
"d",
"*",
"transportDemuxer",
")",
"registerEndpoint",
"(",
"netProtos",
"[",
"]",
"tcpip",
".",
"NetworkProtocolNumber",
",",
"protocol",
"tcpip",
".",
"TransportProtocolNumber",
",",
"id",
"TransportEndpointID",
",",
"ep",
"TransportEndpoint",
",",
"reusePort",
"bool",
")",
"*",
"tcpip",
".",
"Error",
"{",
"for",
"i",
",",
"n",
":=",
"range",
"netProtos",
"{",
"if",
"err",
":=",
"d",
".",
"singleRegisterEndpoint",
"(",
"n",
",",
"protocol",
",",
"id",
",",
"ep",
",",
"reusePort",
")",
";",
"err",
"!=",
"nil",
"{",
"d",
".",
"unregisterEndpoint",
"(",
"netProtos",
"[",
":",
"i",
"]",
",",
"protocol",
",",
"id",
",",
"ep",
")",
"\n",
"return",
"err",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] | // registerEndpoint registers the given endpoint with the dispatcher such that
// packets that match the endpoint ID are delivered to it. | [
"registerEndpoint",
"registers",
"the",
"given",
"endpoint",
"with",
"the",
"dispatcher",
"such",
"that",
"packets",
"that",
"match",
"the",
"endpoint",
"ID",
"are",
"delivered",
"to",
"it",
"."
] | 70ebca9c30730cf3887cdef3b85bb96ed7a97593 | https://github.com/google/netstack/blob/70ebca9c30730cf3887cdef3b85bb96ed7a97593/tcpip/stack/transport_demuxer.go#L88-L97 | train |
google/netstack | tcpip/stack/transport_demuxer.go | selectEndpoint | func (ep *multiPortEndpoint) selectEndpoint(id TransportEndpointID) TransportEndpoint {
ep.mu.RLock()
defer ep.mu.RUnlock()
payload := []byte{
byte(id.LocalPort),
byte(id.LocalPort >> 8),
byte(id.RemotePort),
byte(id.RemotePort >> 8),
}
h := jenkins.Sum32(ep.seed)
h.Write(payload)
h.Write([]byte(id.LocalAddress))
h.Write([]byte(id.RemoteAddress))
hash := h.Sum32()
idx := reciprocalScale(hash, uint32(len(ep.endpointsArr)))
return ep.endpointsArr[idx]
} | go | func (ep *multiPortEndpoint) selectEndpoint(id TransportEndpointID) TransportEndpoint {
ep.mu.RLock()
defer ep.mu.RUnlock()
payload := []byte{
byte(id.LocalPort),
byte(id.LocalPort >> 8),
byte(id.RemotePort),
byte(id.RemotePort >> 8),
}
h := jenkins.Sum32(ep.seed)
h.Write(payload)
h.Write([]byte(id.LocalAddress))
h.Write([]byte(id.RemoteAddress))
hash := h.Sum32()
idx := reciprocalScale(hash, uint32(len(ep.endpointsArr)))
return ep.endpointsArr[idx]
} | [
"func",
"(",
"ep",
"*",
"multiPortEndpoint",
")",
"selectEndpoint",
"(",
"id",
"TransportEndpointID",
")",
"TransportEndpoint",
"{",
"ep",
".",
"mu",
".",
"RLock",
"(",
")",
"\n",
"defer",
"ep",
".",
"mu",
".",
"RUnlock",
"(",
")",
"\n\n",
"payload",
":=",
"[",
"]",
"byte",
"{",
"byte",
"(",
"id",
".",
"LocalPort",
")",
",",
"byte",
"(",
"id",
".",
"LocalPort",
">>",
"8",
")",
",",
"byte",
"(",
"id",
".",
"RemotePort",
")",
",",
"byte",
"(",
"id",
".",
"RemotePort",
">>",
"8",
")",
",",
"}",
"\n\n",
"h",
":=",
"jenkins",
".",
"Sum32",
"(",
"ep",
".",
"seed",
")",
"\n",
"h",
".",
"Write",
"(",
"payload",
")",
"\n",
"h",
".",
"Write",
"(",
"[",
"]",
"byte",
"(",
"id",
".",
"LocalAddress",
")",
")",
"\n",
"h",
".",
"Write",
"(",
"[",
"]",
"byte",
"(",
"id",
".",
"RemoteAddress",
")",
")",
"\n",
"hash",
":=",
"h",
".",
"Sum32",
"(",
")",
"\n\n",
"idx",
":=",
"reciprocalScale",
"(",
"hash",
",",
"uint32",
"(",
"len",
"(",
"ep",
".",
"endpointsArr",
")",
")",
")",
"\n",
"return",
"ep",
".",
"endpointsArr",
"[",
"idx",
"]",
"\n",
"}"
] | // selectEndpoint calculates a hash of destination and source addresses and
// ports then uses it to select a socket. In this case, all packets from one
// address will be sent to same endpoint. | [
"selectEndpoint",
"calculates",
"a",
"hash",
"of",
"destination",
"and",
"source",
"addresses",
"and",
"ports",
"then",
"uses",
"it",
"to",
"select",
"a",
"socket",
".",
"In",
"this",
"case",
"all",
"packets",
"from",
"one",
"address",
"will",
"be",
"sent",
"to",
"same",
"endpoint",
"."
] | 70ebca9c30730cf3887cdef3b85bb96ed7a97593 | https://github.com/google/netstack/blob/70ebca9c30730cf3887cdef3b85bb96ed7a97593/tcpip/stack/transport_demuxer.go#L120-L139 | train |
google/netstack | tcpip/stack/transport_demuxer.go | unregisterEndpoint | func (ep *multiPortEndpoint) unregisterEndpoint(t TransportEndpoint) bool {
ep.mu.Lock()
defer ep.mu.Unlock()
idx, ok := ep.endpointsMap[t]
if !ok {
return false
}
delete(ep.endpointsMap, t)
l := len(ep.endpointsArr)
if l > 1 {
// The last endpoint in endpointsArr is moved instead of the deleted one.
lastEp := ep.endpointsArr[l-1]
ep.endpointsArr[idx] = lastEp
ep.endpointsMap[lastEp] = idx
ep.endpointsArr = ep.endpointsArr[0 : l-1]
return false
}
return true
} | go | func (ep *multiPortEndpoint) unregisterEndpoint(t TransportEndpoint) bool {
ep.mu.Lock()
defer ep.mu.Unlock()
idx, ok := ep.endpointsMap[t]
if !ok {
return false
}
delete(ep.endpointsMap, t)
l := len(ep.endpointsArr)
if l > 1 {
// The last endpoint in endpointsArr is moved instead of the deleted one.
lastEp := ep.endpointsArr[l-1]
ep.endpointsArr[idx] = lastEp
ep.endpointsMap[lastEp] = idx
ep.endpointsArr = ep.endpointsArr[0 : l-1]
return false
}
return true
} | [
"func",
"(",
"ep",
"*",
"multiPortEndpoint",
")",
"unregisterEndpoint",
"(",
"t",
"TransportEndpoint",
")",
"bool",
"{",
"ep",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"ep",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n\n",
"idx",
",",
"ok",
":=",
"ep",
".",
"endpointsMap",
"[",
"t",
"]",
"\n",
"if",
"!",
"ok",
"{",
"return",
"false",
"\n",
"}",
"\n",
"delete",
"(",
"ep",
".",
"endpointsMap",
",",
"t",
")",
"\n",
"l",
":=",
"len",
"(",
"ep",
".",
"endpointsArr",
")",
"\n",
"if",
"l",
">",
"1",
"{",
"// The last endpoint in endpointsArr is moved instead of the deleted one.",
"lastEp",
":=",
"ep",
".",
"endpointsArr",
"[",
"l",
"-",
"1",
"]",
"\n",
"ep",
".",
"endpointsArr",
"[",
"idx",
"]",
"=",
"lastEp",
"\n",
"ep",
".",
"endpointsMap",
"[",
"lastEp",
"]",
"=",
"idx",
"\n",
"ep",
".",
"endpointsArr",
"=",
"ep",
".",
"endpointsArr",
"[",
"0",
":",
"l",
"-",
"1",
"]",
"\n",
"return",
"false",
"\n",
"}",
"\n",
"return",
"true",
"\n",
"}"
] | // unregisterEndpoint returns true if multiPortEndpoint has to be unregistered. | [
"unregisterEndpoint",
"returns",
"true",
"if",
"multiPortEndpoint",
"has",
"to",
"be",
"unregistered",
"."
] | 70ebca9c30730cf3887cdef3b85bb96ed7a97593 | https://github.com/google/netstack/blob/70ebca9c30730cf3887cdef3b85bb96ed7a97593/tcpip/stack/transport_demuxer.go#L179-L198 | train |
google/netstack | tcpip/stack/transport_demuxer.go | deliverPacket | func (d *transportDemuxer) deliverPacket(r *Route, protocol tcpip.TransportProtocolNumber, netHeader buffer.View, vv buffer.VectorisedView, id TransportEndpointID) bool {
eps, ok := d.protocol[protocolIDs{r.NetProto, protocol}]
if !ok {
return false
}
// If a sender bound to the Loopback interface sends a broadcast,
// that broadcast must not be delivered to the sender.
if loopbackSubnet.Contains(r.RemoteAddress) && r.LocalAddress == header.IPv4Broadcast && id.LocalPort == id.RemotePort {
return false
}
// If the packet is a broadcast, then find all matching transport endpoints.
// Otherwise, try to find a single matching transport endpoint.
destEps := make([]TransportEndpoint, 0, 1)
eps.mu.RLock()
if protocol == header.UDPProtocolNumber && id.LocalAddress == header.IPv4Broadcast {
for epID, endpoint := range eps.endpoints {
if epID.LocalPort == id.LocalPort {
destEps = append(destEps, endpoint)
}
}
} else if ep := d.findEndpointLocked(eps, vv, id); ep != nil {
destEps = append(destEps, ep)
}
// As in net/ipv4/ip_input.c:ip_local_deliver, attempt to deliver via
// raw endpoint first. If there are multipe raw endpoints, they all
// receive the packet.
foundRaw := false
for _, rawEP := range eps.rawEndpoints {
// Each endpoint gets its own copy of the packet for the sake
// of save/restore.
rawEP.HandlePacket(r, buffer.NewViewFromBytes(netHeader), vv.ToView().ToVectorisedView())
foundRaw = true
}
eps.mu.RUnlock()
// Fail if we didn't find at least one matching transport endpoint.
if len(destEps) == 0 && !foundRaw {
// UDP packet could not be delivered to an unknown destination port.
if protocol == header.UDPProtocolNumber {
r.Stats().UDP.UnknownPortErrors.Increment()
}
return false
}
// Deliver the packet.
for _, ep := range destEps {
ep.HandlePacket(r, id, vv)
}
return true
} | go | func (d *transportDemuxer) deliverPacket(r *Route, protocol tcpip.TransportProtocolNumber, netHeader buffer.View, vv buffer.VectorisedView, id TransportEndpointID) bool {
eps, ok := d.protocol[protocolIDs{r.NetProto, protocol}]
if !ok {
return false
}
// If a sender bound to the Loopback interface sends a broadcast,
// that broadcast must not be delivered to the sender.
if loopbackSubnet.Contains(r.RemoteAddress) && r.LocalAddress == header.IPv4Broadcast && id.LocalPort == id.RemotePort {
return false
}
// If the packet is a broadcast, then find all matching transport endpoints.
// Otherwise, try to find a single matching transport endpoint.
destEps := make([]TransportEndpoint, 0, 1)
eps.mu.RLock()
if protocol == header.UDPProtocolNumber && id.LocalAddress == header.IPv4Broadcast {
for epID, endpoint := range eps.endpoints {
if epID.LocalPort == id.LocalPort {
destEps = append(destEps, endpoint)
}
}
} else if ep := d.findEndpointLocked(eps, vv, id); ep != nil {
destEps = append(destEps, ep)
}
// As in net/ipv4/ip_input.c:ip_local_deliver, attempt to deliver via
// raw endpoint first. If there are multipe raw endpoints, they all
// receive the packet.
foundRaw := false
for _, rawEP := range eps.rawEndpoints {
// Each endpoint gets its own copy of the packet for the sake
// of save/restore.
rawEP.HandlePacket(r, buffer.NewViewFromBytes(netHeader), vv.ToView().ToVectorisedView())
foundRaw = true
}
eps.mu.RUnlock()
// Fail if we didn't find at least one matching transport endpoint.
if len(destEps) == 0 && !foundRaw {
// UDP packet could not be delivered to an unknown destination port.
if protocol == header.UDPProtocolNumber {
r.Stats().UDP.UnknownPortErrors.Increment()
}
return false
}
// Deliver the packet.
for _, ep := range destEps {
ep.HandlePacket(r, id, vv)
}
return true
} | [
"func",
"(",
"d",
"*",
"transportDemuxer",
")",
"deliverPacket",
"(",
"r",
"*",
"Route",
",",
"protocol",
"tcpip",
".",
"TransportProtocolNumber",
",",
"netHeader",
"buffer",
".",
"View",
",",
"vv",
"buffer",
".",
"VectorisedView",
",",
"id",
"TransportEndpointID",
")",
"bool",
"{",
"eps",
",",
"ok",
":=",
"d",
".",
"protocol",
"[",
"protocolIDs",
"{",
"r",
".",
"NetProto",
",",
"protocol",
"}",
"]",
"\n",
"if",
"!",
"ok",
"{",
"return",
"false",
"\n",
"}",
"\n\n",
"// If a sender bound to the Loopback interface sends a broadcast,",
"// that broadcast must not be delivered to the sender.",
"if",
"loopbackSubnet",
".",
"Contains",
"(",
"r",
".",
"RemoteAddress",
")",
"&&",
"r",
".",
"LocalAddress",
"==",
"header",
".",
"IPv4Broadcast",
"&&",
"id",
".",
"LocalPort",
"==",
"id",
".",
"RemotePort",
"{",
"return",
"false",
"\n",
"}",
"\n\n",
"// If the packet is a broadcast, then find all matching transport endpoints.",
"// Otherwise, try to find a single matching transport endpoint.",
"destEps",
":=",
"make",
"(",
"[",
"]",
"TransportEndpoint",
",",
"0",
",",
"1",
")",
"\n",
"eps",
".",
"mu",
".",
"RLock",
"(",
")",
"\n\n",
"if",
"protocol",
"==",
"header",
".",
"UDPProtocolNumber",
"&&",
"id",
".",
"LocalAddress",
"==",
"header",
".",
"IPv4Broadcast",
"{",
"for",
"epID",
",",
"endpoint",
":=",
"range",
"eps",
".",
"endpoints",
"{",
"if",
"epID",
".",
"LocalPort",
"==",
"id",
".",
"LocalPort",
"{",
"destEps",
"=",
"append",
"(",
"destEps",
",",
"endpoint",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"else",
"if",
"ep",
":=",
"d",
".",
"findEndpointLocked",
"(",
"eps",
",",
"vv",
",",
"id",
")",
";",
"ep",
"!=",
"nil",
"{",
"destEps",
"=",
"append",
"(",
"destEps",
",",
"ep",
")",
"\n",
"}",
"\n\n",
"// As in net/ipv4/ip_input.c:ip_local_deliver, attempt to deliver via",
"// raw endpoint first. If there are multipe raw endpoints, they all",
"// receive the packet.",
"foundRaw",
":=",
"false",
"\n",
"for",
"_",
",",
"rawEP",
":=",
"range",
"eps",
".",
"rawEndpoints",
"{",
"// Each endpoint gets its own copy of the packet for the sake",
"// of save/restore.",
"rawEP",
".",
"HandlePacket",
"(",
"r",
",",
"buffer",
".",
"NewViewFromBytes",
"(",
"netHeader",
")",
",",
"vv",
".",
"ToView",
"(",
")",
".",
"ToVectorisedView",
"(",
")",
")",
"\n",
"foundRaw",
"=",
"true",
"\n",
"}",
"\n",
"eps",
".",
"mu",
".",
"RUnlock",
"(",
")",
"\n\n",
"// Fail if we didn't find at least one matching transport endpoint.",
"if",
"len",
"(",
"destEps",
")",
"==",
"0",
"&&",
"!",
"foundRaw",
"{",
"// UDP packet could not be delivered to an unknown destination port.",
"if",
"protocol",
"==",
"header",
".",
"UDPProtocolNumber",
"{",
"r",
".",
"Stats",
"(",
")",
".",
"UDP",
".",
"UnknownPortErrors",
".",
"Increment",
"(",
")",
"\n",
"}",
"\n",
"return",
"false",
"\n",
"}",
"\n\n",
"// Deliver the packet.",
"for",
"_",
",",
"ep",
":=",
"range",
"destEps",
"{",
"ep",
".",
"HandlePacket",
"(",
"r",
",",
"id",
",",
"vv",
")",
"\n",
"}",
"\n\n",
"return",
"true",
"\n",
"}"
] | // deliverPacket attempts to find one or more matching transport endpoints, and
// then, if matches are found, delivers the packet to them. Returns true if it
// found one or more endpoints, false otherwise. | [
"deliverPacket",
"attempts",
"to",
"find",
"one",
"or",
"more",
"matching",
"transport",
"endpoints",
"and",
"then",
"if",
"matches",
"are",
"found",
"delivers",
"the",
"packet",
"to",
"them",
".",
"Returns",
"true",
"if",
"it",
"found",
"one",
"or",
"more",
"endpoints",
"false",
"otherwise",
"."
] | 70ebca9c30730cf3887cdef3b85bb96ed7a97593 | https://github.com/google/netstack/blob/70ebca9c30730cf3887cdef3b85bb96ed7a97593/tcpip/stack/transport_demuxer.go#L262-L316 | train |
google/netstack | tcpip/stack/transport_demuxer.go | deliverControlPacket | func (d *transportDemuxer) deliverControlPacket(net tcpip.NetworkProtocolNumber, trans tcpip.TransportProtocolNumber, typ ControlType, extra uint32, vv buffer.VectorisedView, id TransportEndpointID) bool {
eps, ok := d.protocol[protocolIDs{net, trans}]
if !ok {
return false
}
// Try to find the endpoint.
eps.mu.RLock()
ep := d.findEndpointLocked(eps, vv, id)
eps.mu.RUnlock()
// Fail if we didn't find one.
if ep == nil {
return false
}
// Deliver the packet.
ep.HandleControlPacket(id, typ, extra, vv)
return true
} | go | func (d *transportDemuxer) deliverControlPacket(net tcpip.NetworkProtocolNumber, trans tcpip.TransportProtocolNumber, typ ControlType, extra uint32, vv buffer.VectorisedView, id TransportEndpointID) bool {
eps, ok := d.protocol[protocolIDs{net, trans}]
if !ok {
return false
}
// Try to find the endpoint.
eps.mu.RLock()
ep := d.findEndpointLocked(eps, vv, id)
eps.mu.RUnlock()
// Fail if we didn't find one.
if ep == nil {
return false
}
// Deliver the packet.
ep.HandleControlPacket(id, typ, extra, vv)
return true
} | [
"func",
"(",
"d",
"*",
"transportDemuxer",
")",
"deliverControlPacket",
"(",
"net",
"tcpip",
".",
"NetworkProtocolNumber",
",",
"trans",
"tcpip",
".",
"TransportProtocolNumber",
",",
"typ",
"ControlType",
",",
"extra",
"uint32",
",",
"vv",
"buffer",
".",
"VectorisedView",
",",
"id",
"TransportEndpointID",
")",
"bool",
"{",
"eps",
",",
"ok",
":=",
"d",
".",
"protocol",
"[",
"protocolIDs",
"{",
"net",
",",
"trans",
"}",
"]",
"\n",
"if",
"!",
"ok",
"{",
"return",
"false",
"\n",
"}",
"\n\n",
"// Try to find the endpoint.",
"eps",
".",
"mu",
".",
"RLock",
"(",
")",
"\n",
"ep",
":=",
"d",
".",
"findEndpointLocked",
"(",
"eps",
",",
"vv",
",",
"id",
")",
"\n",
"eps",
".",
"mu",
".",
"RUnlock",
"(",
")",
"\n\n",
"// Fail if we didn't find one.",
"if",
"ep",
"==",
"nil",
"{",
"return",
"false",
"\n",
"}",
"\n\n",
"// Deliver the packet.",
"ep",
".",
"HandleControlPacket",
"(",
"id",
",",
"typ",
",",
"extra",
",",
"vv",
")",
"\n\n",
"return",
"true",
"\n",
"}"
] | // deliverControlPacket attempts to deliver the given control packet. Returns
// true if it found an endpoint, false otherwise. | [
"deliverControlPacket",
"attempts",
"to",
"deliver",
"the",
"given",
"control",
"packet",
".",
"Returns",
"true",
"if",
"it",
"found",
"an",
"endpoint",
"false",
"otherwise",
"."
] | 70ebca9c30730cf3887cdef3b85bb96ed7a97593 | https://github.com/google/netstack/blob/70ebca9c30730cf3887cdef3b85bb96ed7a97593/tcpip/stack/transport_demuxer.go#L320-L340 | train |
google/netstack | tcpip/stack/transport_demuxer.go | registerRawEndpoint | func (d *transportDemuxer) registerRawEndpoint(netProto tcpip.NetworkProtocolNumber, transProto tcpip.TransportProtocolNumber, ep RawTransportEndpoint) *tcpip.Error {
eps, ok := d.protocol[protocolIDs{netProto, transProto}]
if !ok {
return nil
}
eps.mu.Lock()
defer eps.mu.Unlock()
eps.rawEndpoints = append(eps.rawEndpoints, ep)
return nil
} | go | func (d *transportDemuxer) registerRawEndpoint(netProto tcpip.NetworkProtocolNumber, transProto tcpip.TransportProtocolNumber, ep RawTransportEndpoint) *tcpip.Error {
eps, ok := d.protocol[protocolIDs{netProto, transProto}]
if !ok {
return nil
}
eps.mu.Lock()
defer eps.mu.Unlock()
eps.rawEndpoints = append(eps.rawEndpoints, ep)
return nil
} | [
"func",
"(",
"d",
"*",
"transportDemuxer",
")",
"registerRawEndpoint",
"(",
"netProto",
"tcpip",
".",
"NetworkProtocolNumber",
",",
"transProto",
"tcpip",
".",
"TransportProtocolNumber",
",",
"ep",
"RawTransportEndpoint",
")",
"*",
"tcpip",
".",
"Error",
"{",
"eps",
",",
"ok",
":=",
"d",
".",
"protocol",
"[",
"protocolIDs",
"{",
"netProto",
",",
"transProto",
"}",
"]",
"\n",
"if",
"!",
"ok",
"{",
"return",
"nil",
"\n",
"}",
"\n\n",
"eps",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"eps",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n",
"eps",
".",
"rawEndpoints",
"=",
"append",
"(",
"eps",
".",
"rawEndpoints",
",",
"ep",
")",
"\n\n",
"return",
"nil",
"\n",
"}"
] | // registerRawEndpoint registers the given endpoint with the dispatcher such
// that packets of the appropriate protocol are delivered to it. A single
// packet can be sent to one or more raw endpoints along with a non-raw
// endpoint. | [
"registerRawEndpoint",
"registers",
"the",
"given",
"endpoint",
"with",
"the",
"dispatcher",
"such",
"that",
"packets",
"of",
"the",
"appropriate",
"protocol",
"are",
"delivered",
"to",
"it",
".",
"A",
"single",
"packet",
"can",
"be",
"sent",
"to",
"one",
"or",
"more",
"raw",
"endpoints",
"along",
"with",
"a",
"non",
"-",
"raw",
"endpoint",
"."
] | 70ebca9c30730cf3887cdef3b85bb96ed7a97593 | https://github.com/google/netstack/blob/70ebca9c30730cf3887cdef3b85bb96ed7a97593/tcpip/stack/transport_demuxer.go#L377-L388 | train |
google/netstack | tcpip/stack/transport_demuxer.go | unregisterRawEndpoint | func (d *transportDemuxer) unregisterRawEndpoint(netProto tcpip.NetworkProtocolNumber, transProto tcpip.TransportProtocolNumber, ep RawTransportEndpoint) {
eps, ok := d.protocol[protocolIDs{netProto, transProto}]
if !ok {
panic(fmt.Errorf("tried to unregister endpoint with unsupported network and transport protocol pair: %d, %d", netProto, transProto))
}
eps.mu.Lock()
defer eps.mu.Unlock()
for i, rawEP := range eps.rawEndpoints {
if rawEP == ep {
eps.rawEndpoints = append(eps.rawEndpoints[:i], eps.rawEndpoints[i+1:]...)
return
}
}
} | go | func (d *transportDemuxer) unregisterRawEndpoint(netProto tcpip.NetworkProtocolNumber, transProto tcpip.TransportProtocolNumber, ep RawTransportEndpoint) {
eps, ok := d.protocol[protocolIDs{netProto, transProto}]
if !ok {
panic(fmt.Errorf("tried to unregister endpoint with unsupported network and transport protocol pair: %d, %d", netProto, transProto))
}
eps.mu.Lock()
defer eps.mu.Unlock()
for i, rawEP := range eps.rawEndpoints {
if rawEP == ep {
eps.rawEndpoints = append(eps.rawEndpoints[:i], eps.rawEndpoints[i+1:]...)
return
}
}
} | [
"func",
"(",
"d",
"*",
"transportDemuxer",
")",
"unregisterRawEndpoint",
"(",
"netProto",
"tcpip",
".",
"NetworkProtocolNumber",
",",
"transProto",
"tcpip",
".",
"TransportProtocolNumber",
",",
"ep",
"RawTransportEndpoint",
")",
"{",
"eps",
",",
"ok",
":=",
"d",
".",
"protocol",
"[",
"protocolIDs",
"{",
"netProto",
",",
"transProto",
"}",
"]",
"\n",
"if",
"!",
"ok",
"{",
"panic",
"(",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"netProto",
",",
"transProto",
")",
")",
"\n",
"}",
"\n\n",
"eps",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"eps",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n",
"for",
"i",
",",
"rawEP",
":=",
"range",
"eps",
".",
"rawEndpoints",
"{",
"if",
"rawEP",
"==",
"ep",
"{",
"eps",
".",
"rawEndpoints",
"=",
"append",
"(",
"eps",
".",
"rawEndpoints",
"[",
":",
"i",
"]",
",",
"eps",
".",
"rawEndpoints",
"[",
"i",
"+",
"1",
":",
"]",
"...",
")",
"\n",
"return",
"\n",
"}",
"\n",
"}",
"\n",
"}"
] | // unregisterRawEndpoint unregisters the raw endpoint for the given transport
// protocol such that it won't receive any more packets. | [
"unregisterRawEndpoint",
"unregisters",
"the",
"raw",
"endpoint",
"for",
"the",
"given",
"transport",
"protocol",
"such",
"that",
"it",
"won",
"t",
"receive",
"any",
"more",
"packets",
"."
] | 70ebca9c30730cf3887cdef3b85bb96ed7a97593 | https://github.com/google/netstack/blob/70ebca9c30730cf3887cdef3b85bb96ed7a97593/tcpip/stack/transport_demuxer.go#L392-L406 | train |
google/netstack | tcpip/link/sharedmem/queue/tx.go | Init | func (t *Tx) Init(tx, rx []byte) {
t.tx.Init(tx)
t.rx.Init(rx)
} | go | func (t *Tx) Init(tx, rx []byte) {
t.tx.Init(tx)
t.rx.Init(rx)
} | [
"func",
"(",
"t",
"*",
"Tx",
")",
"Init",
"(",
"tx",
",",
"rx",
"[",
"]",
"byte",
")",
"{",
"t",
".",
"tx",
".",
"Init",
"(",
"tx",
")",
"\n",
"t",
".",
"rx",
".",
"Init",
"(",
"rx",
")",
"\n",
"}"
] | // Init initializes the transmit queue with the given pipes. | [
"Init",
"initializes",
"the",
"transmit",
"queue",
"with",
"the",
"given",
"pipes",
"."
] | 70ebca9c30730cf3887cdef3b85bb96ed7a97593 | https://github.com/google/netstack/blob/70ebca9c30730cf3887cdef3b85bb96ed7a97593/tcpip/link/sharedmem/queue/tx.go#L57-L60 | train |
Subsets and Splits
No saved queries yet
Save your SQL queries to embed, download, and access them later. Queries will appear here once saved.