]> git.proxmox.com Git - ceph.git/blame - ceph/src/seastar/src/net/arp.cc
update source to Ceph Pacific 16.2.2
[ceph.git] / ceph / src / seastar / src / net / arp.cc
CommitLineData
11fdf7f2
TL
1/*
2 * This file is open source software, licensed to you under the terms
3 * of the Apache License, Version 2.0 (the "License"). See the NOTICE file
4 * distributed with this work for additional information regarding copyright
5 * ownership. You may not use this file except in compliance with the License.
6 *
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing,
12 * software distributed under the License is distributed on an
13 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 * KIND, either express or implied. See the License for the
15 * specific language governing permissions and limitations
16 * under the License.
17 */
18/*
19 * Copyright (C) 2014 Cloudius Systems, Ltd.
20 */
21
22#include <seastar/net/arp.hh>
23
24namespace seastar {
25
26namespace net {
27
28arp_for_protocol::arp_for_protocol(arp& a, uint16_t proto_num)
29 : _arp(a), _proto_num(proto_num) {
30 _arp.add(proto_num, this);
31}
32
33arp_for_protocol::~arp_for_protocol() {
34 _arp.del(_proto_num);
35}
36
37arp::arp(interface* netif) : _netif(netif), _proto(netif, eth_protocol_num::arp, [this] { return get_packet(); })
9f95a23c
TL
38{
39 // FIXME: ignored future
40 (void)_proto.receive(
41 [this](packet p, ethernet_address ea) {
42 return process_packet(std::move(p), ea);
43 },
44 [this](forward_hash& out_hash_data, packet& p, size_t off) {
45 return forward(out_hash_data, p, off);
46 });
11fdf7f2
TL
47}
48
f67539c2
TL
49std::optional<l3_protocol::l3packet> arp::get_packet() {
50 std::optional<l3_protocol::l3packet> p;
11fdf7f2
TL
51 if (!_packetq.empty()) {
52 p = std::move(_packetq.front());
53 _packetq.pop_front();
54 }
55 return p;
56}
57
58bool arp::forward(forward_hash& out_hash_data, packet& p, size_t off) {
59 auto ah = p.get_header<arp_hdr>(off);
60 auto i = _arp_for_protocol.find(ntoh(ah->ptype));
61 if (i != _arp_for_protocol.end()) {
62 return i->second->forward(out_hash_data, p, off);
63 }
64 return false;
65}
66
67void arp::add(uint16_t proto_num, arp_for_protocol* afp) {
68 _arp_for_protocol[proto_num] = afp;
69}
70
71void arp::del(uint16_t proto_num) {
72 _arp_for_protocol.erase(proto_num);
73}
74
75future<>
76arp::process_packet(packet p, ethernet_address from) {
77 auto h = p.get_header(0, arp_hdr::size());
78 if (!h) {
79 return make_ready_future<>();
80 }
81 auto ah = arp_hdr::read(h);
82 auto i = _arp_for_protocol.find(ah.ptype);
83 if (i != _arp_for_protocol.end()) {
9f95a23c 84 return i->second->received(std::move(p));
11fdf7f2
TL
85 }
86 return make_ready_future<>();
87}
88
89}
90
91}