Somali President Mohamed Siad Barre said here last night that the delivery of Soviet arms to neighboring Ethiopia is a "danger" to which his government could not remain indifferent and that it could eventually affect Somalia's relations with the Soviet Union.

It was the first time that President Siad Barre has ever hinted at the possibility of an upset in Soviet-Somali relations or spoken of them in such troubled terms.

Only a few weeks ago he was reaffirming that the Soviets were Somalia's "best friend" and debunking press reports of a rift in Soviet-Somali relations. His warning yesterday may mark the beginning of an important change in those relations.

The Somali leader indicated that he had not officially protested to Moscow over the Soviet decision to replace the United States as Ethiopia's main armssupplier, but he said that he had informed "our Russian friends" of Somalia's concern and feelings about this new development.

Somalia has been the Soviet Union's principal ally in this East African region for the past eight years, and the two countries are formally linked by treaty of friendship and cooperation - the first ever signed between Moscow and a black African country. In addition, the Soviets provide virtually all of Somalia's arms and have built its military into one of the strongest in black Africa.

The arrival of Soviet arms in Ethiopia, including tanks, appears to signal a shift in Soviet policy toward both countries however. This has become a source of major concern here, particularly because Ethiopia is regarded as this country's No. 1 enemy.

On other key issues, Siad Barre told foreign correspondents in his first press conference with them in two years:

That he had met secretly in March with the military strongman of the Ethiopian regime, Lt. Col. Mengistu Haile Mariam, in South Yemen's capital, Aden. It was the first confirmation of the meeting, which Siad Barre said was arranged by Cuban leader Fidel Castro, who was attempting to find a peaceful compromise to the Ethiopian-Somali dispute over Ethiopia's Ogaden region, which Somali claims, and over the tiny French Territory of the Afars and Issas (Djibouti), sandwiched between them and scheduled to become independent June 27. Castro sought some kind of federation between the two Marxist states.

"Unfortunately, we could not agree," Siad Barre said. He praised Castro's diplomatic efforts, however, saying, "He did his best." He blamed the failure of Castro's mediation effort on the Ethiopians, who, he said, were "rigid in their colonial mentality.

That the possibility of a federation between Somalia and a new independent Republic of Djibouti is something to be decided by the people of Djibouti, although he described them as mostly Somali in language, tradition and birth.

"If they want to come to Somalia, welcome. If they want to remain [independent], it's up to them . . . If they want to go to Ethiopia, we will not make war for that . . . They must decide," he said.

Siad Barre said Somalia would not try to take Djibouti by force, as Ethiopia was claiming, but he later warned that Somalia would come to the aid of Djibouti if it sought help in repelling an Ethiopian invasion. He also made it clear that Somalia would oppose any French attempt to keep a military base in Djibouti.

On the whole, the Somali president seemed to want to play down the importance of the apparent Soviet policy shift toward this region, known as the Horn of Africa. He avoided answering when asked whether the Soviet Union could simultaneously be "the best friends" of both Somalia and Ethiopia. He was also somewhat vague in his reply to another question about the possibility that the delivery of Soviet arms to Ethiopia might seriously affect this country's relations with Moscow.

"Well, it may, really, but it may well not," he said. He later added that "It is a danger to Somalia and Somalia should not be indifferent."

He also took sharp issue with the Soviet Union's apparent judgment that Ethiopia now has a true Marxist government similar to the one here and thus is worthy of Soviet support.

"We do not believe that bloodshed, torture and killing is socialism," he said. "What's happening in Ethiopia, we don't believe that is socialism"

"It's a question of power, power and hunger of power," he added. At one point he even called Ethiopia's military leaders "mad."

Regarding Somali-American relations, President Siad Barre said he had not yet seen any significant shift in American policy toward Somalia, despite some speculation in the Western press.

Nor did he seem to attach much importance to reports of a major initiative by Saudi Arabia to counter Soviet influence here. He said there had been to much "sensational talk" about recent diplomatic maneuverings among the countries in the Red Sea region, adding that the recent visit of the Saudi foreign minister hard on the heels of a visit by Soviet President Nikolai Podgorny was "normal" given the longstanding close ties between the two countries.

President Siad Barre even attacked the Saudis for their alleged policy of trying to turn the Red Sea into an Arab lake, saying no power has the right to monopolize the waterway.

Regarding persistent reports in the Western press over the past few years that Somalia has been providing the Soviets with naval and air bases, the Somali leader said that the visit of American congressmen to Berbera, Somalia's Indian Ocean port, in July 1975 had proved the "inexistence" of any Soviet military base in his country.

He confirmed however, that Soviet ships did use Somali facilities and said that Somalia would give similar treatment to any country that "comes as a friend" and asks for them through channels. French and Italian warships had also been given facilities in Somali ports, he said.