]>
git.proxmox.com Git - ceph.git/blob - ceph/src/seastar/src/net/arp.cc
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.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
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
19 * Copyright (C) 2014 Cloudius Systems, Ltd.
22 #include <seastar/net/arp.hh>
28 arp_for_protocol::arp_for_protocol(arp
& a
, uint16_t proto_num
)
29 : _arp(a
), _proto_num(proto_num
) {
30 _arp
.add(proto_num
, this);
33 arp_for_protocol::~arp_for_protocol() {
37 arp::arp(interface
* netif
) : _netif(netif
), _proto(netif
, eth_protocol_num::arp
, [this] { return get_packet(); })
39 // FIXME: ignored future
41 [this](packet p
, ethernet_address ea
) {
42 return process_packet(std::move(p
), ea
);
44 [this](forward_hash
& out_hash_data
, packet
& p
, size_t off
) {
45 return forward(out_hash_data
, p
, off
);
49 std::optional
<l3_protocol::l3packet
> arp::get_packet() {
50 std::optional
<l3_protocol::l3packet
> p
;
51 if (!_packetq
.empty()) {
52 p
= std::move(_packetq
.front());
58 bool 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
);
67 void arp::add(uint16_t proto_num
, arp_for_protocol
* afp
) {
68 _arp_for_protocol
[proto_num
] = afp
;
71 void arp::del(uint16_t proto_num
) {
72 _arp_for_protocol
.erase(proto_num
);
76 arp::process_packet(packet p
, ethernet_address from
) {
77 auto h
= p
.get_header(0, arp_hdr::size());
79 return make_ready_future
<>();
81 auto ah
= arp_hdr::read(h
);
82 auto i
= _arp_for_protocol
.find(ah
.ptype
);
83 if (i
!= _arp_for_protocol
.end()) {
84 return i
->second
->received(std::move(p
));
86 return make_ready_future
<>();